From 6bbe0a457f3e25db680a0e06d0c0924152c61925 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 16:41:04 +0700 Subject: [PATCH 01/11] [github action] update lint rue and replace the lint action with reviewdog --- .github/workflows/lint.yaml | 19 ++++-- analysis_options.yaml | 131 ++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 9bc4e71c9c..8e4752ee08 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -62,11 +62,22 @@ jobs: - name: Submoudles update run: git -c submodule.auto-test.update=none submodule update --init --recursive - run: flutter pub get - - name: Analyze Dart - uses: invertase/github-action-dart-analyzer@v1 + - uses: reviewdog/action-setup@v1 with: - annotate: true - working-directory: ./ + reviewdog_version: lates + - name: Run reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-check + - name: dart fixes + run: | + dart format . + dart fix --apply + - name: suggester / dart fixes + uses: reviewdog/action-suggester@v1 + with: + tool_name: dart fix gitleaks: runs-on: ubuntu-latest diff --git a/analysis_options.yaml b/analysis_options.yaml index f109fef0c8..936e0ff02a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -23,19 +23,138 @@ linter: # producing the lint. rules: # style rules - constant_identifier_names: false - camel_case_types: true - library_names: true - avoid_catching_errors: true - avoid_empty_else: true - unnecessary_brace_in_string_interps: true + always_declare_return_types: true + always_put_control_body_on_new_line: true + always_put_required_named_parameters_first: true + always_specify_types: true + annotate_overrides: true + annotate_redeclares: true + avoid_annotating_with_dynamic: true + avoid_escaping_inner_quotes: true + avoid_function_literals_in_foreach_calls: true + avoid_init_to_null: true + avoid_multiple_declarations_per_line: true + avoid_null_checks_in_equality_operators: true + avoid_private_typedef_functions: true avoid_redundant_argument_values: true + avoid_renaming_method_parameters: true + avoid_return_types_on_setters: true + avoid_returning_null_for_void: true + avoid_single_cascade_in_expression_statements: true + avoid_types_on_closure_parameters: true + avoid_unnecessary_containers: true + avoid_unused_constructor_parameters: true + avoid_void_async: true + await_only_futures: true + cascade_invocations: true + cast_nullable_to_non_nullable: true + combinators_ordering: true + constant_identifier_names: true + curly_braces_in_flow_control_structures: true + dangling_library_doc_comments: true + directives_ordering: true + empty_catches: true + empty_constructor_bodies: true + eol_at_end_of_file: true + exhaustive_cases: true + implicit_call_tearoffs: true leading_newlines_in_multiline_strings: true + library_annotations: true + no_leading_underscores_for_library_prefixes: true + no_leading_underscores_for_local_identifiers: true + no_literal_bool_comparisons: true + non_constant_identifier_names: true + noop_primitive_operations: true + null_check_on_nullable_type_parameter: true + null_closures: true + omit_local_variable_types: true + prefer_adjacent_string_concatenation: true + prefer_collection_literals: true + prefer_conditional_assignment: true + prefer_const_constructors: true + prefer_const_constructors_in_immutables: true + prefer_const_declarations: true + prefer_const_literals_to_create_immutables: true + prefer_contains: true + prefer_double_quotes: true + prefer_expression_function_bodies: true + prefer_final_fields: true + prefer_final_in_for_each: true + prefer_final_locals: true + prefer_final_parameters: true + prefer_for_elements_to_map_fromIterable: true + prefer_function_declarations_over_variables: true + prefer_generic_function_type_aliases: true + prefer_if_elements_to_conditional_expressions: true + prefer_if_null_operators: true + prefer_initializing_formals: true + prefer_inlined_adds: true + prefer_int_literals: true + prefer_interpolation_to_compose_strings: true + prefer_is_empty: true + prefer_is_not_empty: true + prefer_is_not_operator: true + prefer_iterable_whereType: true + prefer_null_aware_operators: true + prefer_single_quotes: true + prefer_spread_collections: true + prefer_typing_uninitialized_variables: true + require_trailing_commas: true + sized_box_for_whitespace: true + slash_for_doc_comments: true + sort_child_properties_last: true + sort_constructors_first: true + sort_unnamed_constructors_first: true + type_annotate_public_apis: true + type_init_formals: true + type_literal_in_constant_pattern: true + unawaited_futures: true + unnecessary_brace_in_string_interps: true + unnecessary_breaks: true + unnecessary_const: true + unnecessary_constructor_name: true + unnecessary_final: true + unnecessary_getters_setters: true + unnecessary_lambdas: true + unnecessary_late: true + unnecessary_library_directive: true + unnecessary_new: true + unnecessary_null_aware_assignments: true + unnecessary_null_checks: true + unnecessary_null_in_if_null_operators: true + unnecessary_nullable_for_final_variable_declarations: true + unnecessary_overrides: true + unnecessary_parenthesis: true + unnecessary_raw_strings: true + unnecessary_string_escapes: true + unnecessary_string_interpolations: true + unnecessary_this: true + unnecessary_to_list_in_spreads: true + unreachable_from_main: true + use_decorated_box: true + use_enums: true + use_full_hex_values_for_flutter_colors: true + use_function_type_syntax_for_parameters: true + use_raw_strings: true + use_rethrow_when_possible: true + use_string_in_part_of_directives: true + use_super_parameters: true # formatting: true # lines_longer_than_80_chars: true curly_braces_in_flow_control_structures: true # doc comments slash_for_doc_comments: true + # has a quick fix + avoid_print: true + diagnostic_describe_all_properties: true + discarded_futures: true + empty_statements: true + hash_and_equals: true + implicit_reopen: true + invalid_case_patterns: true + prefer_relative_imports: true + prefer_void_to_null: true + use_key_in_widget_constructors: true analyzer: exclude: From 110f0de7b2cb13bee5a23bffa5da732b112b8ccf Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 16:44:36 +0700 Subject: [PATCH 02/11] fix a typo --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 8e4752ee08..054d8bf1da 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -64,7 +64,7 @@ jobs: - run: flutter pub get - uses: reviewdog/action-setup@v1 with: - reviewdog_version: lates + reviewdog_version: latest - name: Run reviewdog env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 7eb6301d6123e63d8b38af3ef02874920743b81d Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 16:58:10 +0700 Subject: [PATCH 03/11] optimize linting flow --- .github/workflows/lint.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 054d8bf1da..7a497f3204 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -69,7 +69,7 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-check + flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-reviewgithub-pr-review - name: dart fixes run: | dart format . @@ -78,6 +78,7 @@ jobs: uses: reviewdog/action-suggester@v1 with: tool_name: dart fix + cleanup: true gitleaks: runs-on: ubuntu-latest From 1523642affe765b65af01085ba62e034b02398fd Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 16:58:28 +0700 Subject: [PATCH 04/11] fix problem on linting file --- analysis_options.yaml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 936e0ff02a..b828ba66ce 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -26,9 +26,7 @@ linter: always_declare_return_types: true always_put_control_body_on_new_line: true always_put_required_named_parameters_first: true - always_specify_types: true annotate_overrides: true - annotate_redeclares: true avoid_annotating_with_dynamic: true avoid_escaping_inner_quotes: true avoid_function_literals_in_foreach_calls: true @@ -41,7 +39,6 @@ linter: avoid_return_types_on_setters: true avoid_returning_null_for_void: true avoid_single_cascade_in_expression_statements: true - avoid_types_on_closure_parameters: true avoid_unnecessary_containers: true avoid_unused_constructor_parameters: true avoid_void_async: true @@ -76,7 +73,6 @@ linter: prefer_const_declarations: true prefer_const_literals_to_create_immutables: true prefer_contains: true - prefer_double_quotes: true prefer_expression_function_bodies: true prefer_final_fields: true prefer_final_in_for_each: true @@ -113,7 +109,6 @@ linter: unnecessary_breaks: true unnecessary_const: true unnecessary_constructor_name: true - unnecessary_final: true unnecessary_getters_setters: true unnecessary_lambdas: true unnecessary_late: true @@ -140,10 +135,7 @@ linter: use_string_in_part_of_directives: true use_super_parameters: true # formatting: true - # lines_longer_than_80_chars: true - curly_braces_in_flow_control_structures: true - # doc comments - slash_for_doc_comments: true + lines_longer_than_80_chars: true # has a quick fix avoid_print: true diagnostic_describe_all_properties: true @@ -159,5 +151,5 @@ linter: analyzer: exclude: - '**/*.g.dart' - - 'auto-test/*' - - 'test/*' \ No newline at end of file + - 'auto-test/**' + - 'test/**' \ No newline at end of file From 3c2bfccda9cbf755552ff17e4139a605e654d5cc Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:04:41 +0700 Subject: [PATCH 05/11] fix typo --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 7a497f3204..eb89fc454b 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -69,7 +69,7 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-reviewgithub-pr-review + flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-review - name: dart fixes run: | dart format . From 431e66135f8f5790f0bde66944ab687c01e66f8a Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:15:42 +0700 Subject: [PATCH 06/11] run codespell auto-fix with suggestion --- .github/workflows/lint.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index eb89fc454b..e99af5d755 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -70,8 +70,15 @@ jobs: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | flutter analyze --no-preamble | reviewdog -efm="%p%t%r • %m • %f:%l:%c • %s" -reporter=github-pr-review - - name: dart fixes + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: 'pip' + - name: Install codespell + run: pip install codespell + - name: Fix the code run: | + codespell -w dart format . dart fix --apply - name: suggester / dart fixes @@ -114,12 +121,4 @@ jobs: pattern: | *.dart *.swift - *.kt - - uses: codespell-project/codespell-problem-matcher@v1 - - name: codespell - uses: codespell-project/actions-codespell@v2 - with: - check_filenames: true - ignore_words_file: .codespellignore - only_warn: 1 - exclude_file: pubspec.yaml \ No newline at end of file + *.kt \ No newline at end of file From 6325900ee6987762d0651df5a3301c9cefbd90c0 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:22:04 +0700 Subject: [PATCH 07/11] remove pip caching --- .github/workflows/lint.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index e99af5d755..6861982486 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -73,12 +73,11 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - cache: 'pip' - name: Install codespell run: pip install codespell - name: Fix the code run: | - codespell -w + codespell -w -I .codespellignore dart format . dart fix --apply - name: suggester / dart fixes From 3c9c4fa08572eb0049ce79978732029d997eeb94 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:31:14 +0700 Subject: [PATCH 08/11] skip files --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 6861982486..fe91950ae4 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -77,7 +77,7 @@ jobs: run: pip install codespell - name: Fix the code run: | - codespell -w -I .codespellignore + codespell -w -I .codespellignore --skip "**/*.g.dart,*.svg" dart format . dart fix --apply - name: suggester / dart fixes From 4f0891b3aa69e8ee4b81d4d22f30e4aec345b5fc Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:35:06 +0700 Subject: [PATCH 09/11] run codespell with interactive level 3 --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index fe91950ae4..3b2dea90f2 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -77,7 +77,7 @@ jobs: run: pip install codespell - name: Fix the code run: | - codespell -w -I .codespellignore --skip "**/*.g.dart,*.svg" + codespell -i 3 -w -I .codespellignore --skip "**/*.g.dart,*.svg" dart format . dart fix --apply - name: suggester / dart fixes From 71113c5a744381b578a31c8d4227bc1f83794f32 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:39:32 +0700 Subject: [PATCH 10/11] change the code order to make sure it's compilable --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 3b2dea90f2..39e7df53c2 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -77,9 +77,9 @@ jobs: run: pip install codespell - name: Fix the code run: | - codespell -i 3 -w -I .codespellignore --skip "**/*.g.dart,*.svg" dart format . dart fix --apply + codespell -i 3 -w -I .codespellignore --skip "**/*.g.dart,*.svg" - name: suggester / dart fixes uses: reviewdog/action-suggester@v1 with: From 92d555de2d0f7d7b6e803d5ebbb4030ca01fbba4 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Fri, 3 Nov 2023 17:59:40 +0700 Subject: [PATCH 11/11] update the rule --- analysis_options.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index b828ba66ce..2ab77dbe67 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -92,7 +92,7 @@ linter: prefer_is_not_operator: true prefer_iterable_whereType: true prefer_null_aware_operators: true - prefer_single_quotes: true + prefer_double_quotes: true prefer_spread_collections: true prefer_typing_uninitialized_variables: true require_trailing_commas: true @@ -137,16 +137,25 @@ linter: # formatting: true lines_longer_than_80_chars: true # has a quick fix + always_use_package_imports: true + avoid_empty_else: true avoid_print: true + avoid_relative_lib_imports: true + avoid_types_as_parameter_names: true diagnostic_describe_all_properties: true discarded_futures: true empty_statements: true hash_and_equals: true implicit_reopen: true invalid_case_patterns: true - prefer_relative_imports: true + no_duplicate_case_values: true prefer_void_to_null: true use_key_in_widget_constructors: true + # recommended by don't have quick fix + unrelated_type_equality_checks: true + valid_regexps: true + control_flow_in_finally: true + collection_methods_unrelated_type: true analyzer: exclude: