dart-code-checker/dart-code-metrics

[BUG] - Error to run flutter pub run dart_code_metrics:metrics analyze lib

vitoramaral10 opened this issue · 2 comments

  • DCM version: 5.5.0
  • Dart sdk version: 2.19.0

Please show your full configuration:

Configuration
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml


analyzer:
  plugins:
    - dart_code_metrics
 

linter:
  # The lint rules applied to this project can be customized in the
  # section below to disable rules from the `package:flutter_lints/flutter.yaml`
  # included above or to enable additional rules. A list of all available lints
  # and their documentation is published at
  # https://dart-lang.github.io/linter/lints/index.html.
  #
  # Instead of disabling a lint rule for the entire project in the
  # section below, it can also be suppressed for a single line of code
  # or a specific dart file by using the `// ignore: name_of_lint` and
  # `// ignore_for_file: name_of_lint` syntax on the line or in the file
  # producing the lint.
  rules:
    # avoid_print: false  # Uncomment to disable the `avoid_print` rule
    # prefer_single_quotes: true  # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
dart_code_metrics:
  anti-patterns:
    - long-method
    - long-parameter-list
  ignored-types: 
    - TabController
  metrics:
    cyclomatic-complexity: 20
    maximum-nesting-level: 5
    number-of-parameters: 4
    source-lines-of-code: 50
    lines-of-executable-code: 50
  metrics-exclude:
    - test/**
  rules-exclude:
    - lib/generated_plugin_registrant.dart
  rules:
    #Common code
    - arguments-ordering:
        child-last: true
    - avoid-banned-imports
    - avoid-border-all
    - avoid-cascade-after-if-null
    - avoid-collection-methods-with-unrelated-types
    - avoid-double-slash-imports
    - avoid-duplicate-exports
    - avoid-dynamic
    - avoid-global-state
    - avoid-late-keyword:
       
    - avoid-missing-enum-constant-in-map
    - avoid-nested-conditional-expressions:
      acceptable-level: 2
    - avoid-non-ascii-symbols
    - avoid-redundant-async 
    - avoid-returning-widgets
    - avoid-throw-in-catch-block
    - avoid-unnecessary-conditionals
    - avoid-unnecessary-type-assertions
    - avoid-unnecessary-type-casts
    - avoid-unrelated-type-assertions
    - avoid-unused-parameters
    - binary-expression-operand-order
    - check-for-equals-in-render-object-setters
    - consistent-update-render-object
    - double-literal-format
    - format-comment
    - list-all-equatable-fields
    - member-ordering:
      alphabetize: true
    - member-ordering
    - newline-before-return
    - no-boolean-literal-compare
    - no-empty-block
    - no-equal-then-else
    - no-object-declaration
    - prefer-async-await
    - prefer-commenting-analyzer-ignores
    - prefer-conditional-expressions
    - prefer-correct-edge-insets-constructor
    - prefer-correct-identifier-length:
      exceptions: [ 'z' ]
      max-identifier-length: 30
      min-identifier-length: 4
    - prefer-correct-test-file-name
    - prefer-correct-type-name
    - prefer-enums-by-name
    - prefer-first
    - prefer-immediate-return
    - prefer-iterable-of
    - prefer-last
    - prefer-match-file-name
    - prefer-moving-to-variable
    - prefer-static-class
    - prefer-trailing-comma
    #Flutter specific
    - always-remove-listener
    - avoid-border-all
    - avoid-returning-widgets
    - avoid-unnecessary-setstate
    - avoid-wrapping-in-padding
    - avoid-expanded-as-spacer
    - prefer-const-border-radius
    - prefer-correct-edge-insets-constructor
    - prefer-provide-intl-description
    - prefer-single-widget-per-file
    - prefer-using-list-view
    - no-magic-number
    - use-setstate-synchronously

What did you do? Please include the source code example causing the issue.

flutter pub run dart_code_metrics:metrics analyze lib

What did you expect to happen?

✔ Analysis is completed. Preparing the results: 18.1s

What actually happened?

⠙ Analyzing...Unhandled exception:
Bad state: No element
#0 Iterable.first (dart:core/iterable.dart:624:7)
#1 AnalysisOptions.readMapOfMap. (package:dart_code_metrics/src/config_builder/models/analysis_options.dart:97:42)
#2 ListMixin.fold (dart:collection/list.dart:237:22)
#3 AnalysisOptions.readMapOfMap (package:dart_code_metrics/src/config_builder/models/analysis_options.dart:90:14)
#4 new LintConfig.fromAnalysisOptions (package:dart_code_metrics/src/analyzers/lint_analyzer/lint_config.dart:34:24)
#5 ConfigBuilder.getLintConfigFromOptions (package:dart_code_metrics/src/config_builder/config_builder.dart:24:18)
#6 LintAnalyzer._getAnalysisConfig (package:dart_code_metrics/src/analyzers/lint_analyzer/lint_analyzer.dart:191:23)
#7 LintAnalyzer.runCliAnalysis (package:dart_code_metrics/src/analyzers/lint_analyzer/lint_analyzer.dart:87:11)
#8 AnalyzeCommand.runCommand (package:dart_code_metrics/src/cli/commands/analyze_command.dart:53:48)
#9 BaseCommand._verifyThenRunCommand (package:dart_code_metrics/src/cli/commands/base_command.dart:168:12)
#10 BaseCommand.run (package:dart_code_metrics/src/cli/commands/base_command.dart:30:25)
#11 CommandRunner.runCommand (package:args/command_runner.dart:212:27)
#12 CommandRunner.run. (package:args/command_runner.dart:122:25)
#13 new Future.sync (dart:async/future.dart:302:31)
#14 CommandRunner.run (package:args/command_runner.dart:122:14)
#15 CliRunner.run (package:dart_code_metrics/src/cli/cli_runner.dart:56:19)
#16 main (file:///C:/Users/vitor.melo/AppData/Local/Pub/Cache/hosted/pub.dev/dart_code_metrics-5.5.0/bin/metrics.dart:4:21)
#17 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:295:33)
#18 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
pub finished with exit code 255

Are you willing to submit a pull request to fix this bug?

@vitoramaral10 please check your configuration. YAML is indent-sensitive, so things like these:

- avoid-late-keyword:
       
- avoid-missing-enum-constant-in-map

...

- avoid-nested-conditional-expressions:
  acceptable-level: 2

are not allowed.

This works for me, thanks!