Code Monkey home page Code Monkey logo

dart-code-metrics's Introduction

Build Status Coverage Status Pub Version Dart SDK Version License Pub popularity GitHub popularity

Dart Code Metrics

Note: you can find the full documentation on the website

Configuration | Rules | Metrics | Anti-patterns

Dart Code Metrics logo

Dart Code Metrics is a static analysis tool that helps you analyse and improve your code quality.

Links

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.3.3

    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
  • GitHub
  • 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.
    --halstead-volume=<150>                       Halstead Volume 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.
    --maintainability-index=<50>                  Maintainability Index 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]
    --[no-]fatal-style                            Treat style level issues as fatal.
    --[no-]fatal-performance                      Treat performance level issues as fatal.
    --[no-]fatal-warnings                         Treat warning level issues as fatal.

Troubleshooting

Please read the following guide if the plugin is not working as you'd expect it to work.

Contributing

If you are interested in contributing, please check out the contribution guidelines. Feedback and contributions are welcome!

How to reach us

Please feel free to ask any questions about this tool. Join our community chat on Telegram. We speak both English and Russian.

LICENCE

MIT

dart-code-metrics's People

Contributors

dkrutskikh avatar incendial avatar anrock avatar sinegovsky-ivan avatar andrewst avatar roman-petrov avatar creativecreatorormaybenot avatar bigdaddys avatar furaiev avatar csepanda avatar dependabot[bot] avatar aprokofevwrike avatar danilagogolev avatar ookami-kb avatar vlkonoshenko avatar xsahil03x avatar zmeggyesi avatar grafovdenis avatar aschyolokov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.