diff --git a/lib/analysis_options.yaml b/lib/analysis_options.yaml index 74e16568..f5af7669 100644 --- a/lib/analysis_options.yaml +++ b/lib/analysis_options.yaml @@ -32,55 +32,77 @@ analyzer: missing_return: error parameter_assignments: error -dart_code_metrics: - metrics: +custom_lint: + rules: + - avoid_global_state + + - avoid_late_keyword: + allow_initialized: true + ignored_types: + - AnimationController + + - avoid_non_null_assertion + - avoid_returning_widgets + - avoid_unnecessary_setstate + - avoid_unnecessary_type_assertions + - avoid_unnecessary_type_casts + - avoid_unrelated_type_assertions + - avoid_unused_parameters + # NIST 500-235 item 2.5 - cyclomatic-complexity: 10 + - cyclomatic_complexity: + max_complexity: 10 - # McConnell, S. (2004), Chapter 7.5: High-Quality Routines: How To Use Routine Parameters. Code Complete, Second Edition, Redmond, WA, USA: Microsoft Press. 174-180 - number-of-parameters: 7 + - double_literal_format # McConnell, S. (2004), Chapter 7.4: High-Quality Routines: How Long Can a Routine Be?. Code Complete, Second Edition, Redmond, WA, USA: Microsoft Press. 173-174 - source-lines-of-code: 200 + - function_lines_of_code: + max_lines: 200 - # We use source-lines-of-code instead of this as we don't want to count comment or blank lines. - # lines-of-code: 50 - rules: - - avoid-global-state - - avoid-late-keyword - - avoid-non-null-assertion - - avoid-returning-widgets - - avoid-unnecessary-setstate - - avoid-unnecessary-type-assertions - - avoid-unnecessary-type-casts - - avoid-unrelated-type-assertions - - avoid-unused-parameters - - double-literal-format - - member-ordering: - order: - - fields - - getters-setters - - constructors - - methods - widgets-order: - - init-state-method - - build-method - - did-change-dependencies-method - - did-update-widget-method - - deactivate-method - - dispose-method - - newline-before-return - - no-empty-block - - no-equal-then-else - - no-magic-number - - prefer-conditional-expressions - - prefer-first - - prefer-last - # This improves navigation by matching file content and file name. - - prefer-match-file-name - anti-patterns: - - long-method - - long-parameter-list + - member_ordering: + alphabetize: true + order: + - public_fields + - private_fields + - getters + - setters + - constructors + - public_methods + - private_methods + - close_method + widgets_order: + - const_fields + - static_fields + - static_methods + - public_fields + - private_fields + - constructors + - public_methods + - private_methods + - init_state_method + - build_method + - did_change_dependencies_method + - did_update_widget_method + - dispose_method + + - newline_before_return + - no_empty_block + - no_equal_then_else + + - no_magic_number: + allowed_in_widget_params: true + + # McConnell, S. (2004), Chapter 7.5: High-Quality Routines: How To Use Routine Parameters. Code Complete, Second Edition, Redmond, WA, USA: Microsoft Press. 174-180 + - number_of_parameters: + max_parameters: 7 + + - prefer_conditional_expressions: + ignore_nested: true + + - prefer_first + - prefer_last + - prefer_match_file_name + - proper_super_calls linter: rules: diff --git a/lib/analysis_options_test.yaml b/lib/analysis_options_test.yaml index 7cc80664..0acf73b8 100644 --- a/lib/analysis_options_test.yaml +++ b/lib/analysis_options_test.yaml @@ -1,24 +1,20 @@ include: package:solid_lints/analysis_options.yaml -dart_code_metrics: - metrics: - +custom_lint: + rules: # Tests usually organized in one large main() function making this rule not applicable. # Given the quite large threshold configured for this metric we considered extracting # test body into separate function, but that means that we'll have to either pass # Test Context that contains all defined variables in main to every function call # or moving them to the Global State. # Both options didn't look right, so we decided that tests are ok to be long. - source-lines-of-code: false - + - function_lines_of_code: false # Since we're not using the source-lines-of-code rule, `main()` function in test can # have high cyclomatic complexity. # For rationale against splitting up `main()` in tests, see `source-lines-of-code` comments. -# Also there is a bug in metric calculation: https://github.com/dart-code-checker/dart-code-metrics/issues/663 - cyclomatic-complexity: false +# Also, there is a bug in metric calculation: https://github.com/dart-code-checker/dart-code-metrics/issues/663 + - cyclomatic_complexity: false - rules: - # Late keyword is allowed in tests in order to enable the use of custom mocks and # fakes. @@ -36,7 +32,7 @@ dart_code_metrics: # 1. Making the mocks `final` and non-nullable, and adding a `reset()` method # to them, which would return the mock/fake to its initial state. # - Works well with generated code from testing libraries like `mockito`. -# - It's less practical with hand-written mocks, where it's possible to add a +# - It's less practical with handwritten mocks, where it's possible to add a # piece of state and forget to reset it, which might lead to hard-to-trace # errors. Usually re-instantiating a test mock simplifies its code and # prevents such errors altogether, but that requires making the field @@ -52,10 +48,7 @@ dart_code_metrics: # 4. Making the mocks nullable and using the "bang" operator (`!`): # - In terms of behavior similar to `late`, but requires using the operator in # many places inside the test code, adding uninformative visual noise. -# - The use of this operator is also discouraged by the main ruleset. - avoid-late-keyword: false +# - The use of this operator is also discouraged by the main rule set. + - avoid_late_keyword: false # It's acceptable to include stubs or other helper classes into the test file. - prefer-match-file-name: false - anti-patterns: -# Same as for `source-lines-of-code` - long-method: false + - prefer_match_file_name: false