Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

dart code metrics

dart code metrics is a static analysis tool that helps you analyse and improve your code quality.

quick start

analyzer plugin

a plugin for the dart analyzer package providing additional rules from dart code metrics. all issues produced by rules or anti-patterns will be highlighted in ide.

  1. install package as a dev dependency
    $ dart pub add --dev dart_code_metrics
    
    # or for a flutter package
    $ flutter pub add --dev dart_code_metrics
    

    or

    add it manually to pubspec.yaml

    dev_dependencies:
      dart_code_metrics: ^4.2.0-dev.1
    

    and then run

    $ dart pub get
    
    # or for a flutter package
    $ flutter pub get
    
  2. add configuration to analysis_options.yaml
    analyzer:
      plugins:
        - dart_code_metrics
    
    dart_code_metrics:
      anti-patterns:
        - long-method
        - long-parameter-list
      metrics:
        cyclomatic-complexity: 20
        maximum-nesting-level: 5
        number-of-parameters: 4
        source-lines-of-code: 50
      metrics-exclude:
        - test/**
      rules:
        - newline-before-return
        - no-boolean-literal-compare
        - no-empty-block
        - prefer-trailing-comma
        - prefer-conditional-expressions
        - no-equal-then-else
    
  3. reload ide to allow the analyzer to discover the plugin

cli

the package can be used as a command-line tool.
it will produce a result in one of the supported formats:

  • console
  • <li/li>

  • codeclimate
  • html
  • json

usage

install the package as listed in the analyzer plugin usage example.

if you want the command-line tool to check rules, you should configure rules entry in the analysis_options.yaml first.

dart pub run dart_code_metrics:metrics lib

# or for a flutter package
flutter pub run dart_code_metrics:metrics lib

multi-package repositories usage

if you use melos, you can add custom command to melos.yaml.

metrics:
  run: |
    melos exec -c 1 --ignore="*example*" -- 
      flutter pub run dart_code_metrics:metrics lib
  description: |
    run `dart_code_metrics` in all packages.
     - note: you can also rely on your ides dart analysis / issues window.

options

usage: metrics [arguments...] <directories>

-h, --help                                        print this usage information.


-r, --reporter=<console>                          the format of the output of the analysis
                                                  [console (default), console-verbose, codeclimate, github, gitlab, html, json]
-o, --output-directory=<output>                   write html output to output
                                                  (defaults to "metrics")


    --cyclomatic-complexity=<20>                  cyclomatic complexity threshold
    --lines-of-code=<100>                         lines of code threshold
    --maximum-nesting-level=<5>                   maximum nesting level threshold
    --number-of-methods=<10>                      number of methods threshold
    --number-of-parameters=<4>                    number of parameters threshold
    --source-lines-of-code=<50>                   source lines of code threshold
    --weight-of-class=<0.33>                      weight of a class threshold


    --root-folder=<./>                            root folder
                                                  (defaults to current directory)
    --exclude=<{/**.g.dart,/**.template.dart}>    file paths in glob syntax to be exclude
                                                  (defaults to "{/**.g.dart,/**.template.dart}")


    --set-exit-on-violation-level=<warning>       set exit code 2 if code violations same or higher level than selected are detected
                                                  [noted, warning, alarm]

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.