Skip to content

Codemetrics for Dart is a simple command line utility that provides some insight into the "quality" of code.

License

Notifications You must be signed in to change notification settings

CristianDRM/codemetrics

 
 

Repository files navigation

Codemetrics

Codemetrics for Dart is a simple command line utility that provides some insight into the "quality" of code.

It uses static analysis of the code to determine:

and provides different reporting serialization formats:

  • json
  • html

How to use

For now, there is no pub package for this project, so you have to clone it

git clone https://github.com/daniel-v/codemetrics.git
cd codemetrics
pub get
cd bin; dart codemetrics.dart --analysis-root=/path/to/your/package

Internally, Codemetrics for Dart uses glob package to find dart files within the --analysis-root folder with the **.dart glob. It will exclude all dart files in:

  • packages
  • .pub

directories.

You can also install it as a global package:

pub global activate --source git https://github.com/daniel-v/codemetrics.git

Executable name is dart-codemetrics

dart-codemetrics --begin-warning-complexity-number=2 --begin-error-complexity-number=4

print:

./bin\codemetrics.dart
    main - 10 - ERROR

./lib\analyzer\src\cyclomatic_impl.dart
    _getQualifiedName - 3 - WARNING
    CyclomaticAnalysisRecorder.startRecordGroup - 3 - WARNING
    CyclomaticAnalysisRecorder.record - 3 - WARNING
    CyclomaticAnalyzer.runAnalysis - 2 - WARNING
    CyclomaticAnalyzer.runComplexityAnalysisFor - 2 - WARNING
    CyclomaticAnalysisRunner.run - 2 - WARNING

./lib\cyclomatic\src\control_flow_ast_visitor.dart
    ControlFlowVisitor.increaseComplexity - 2 - WARNING
    ControlFlowVisitor.visitBlockFunctionBody - 3 - WARNING

./lib\reporter\src\printf_reporter.dart
    PrintFReporter._isErrorMustBePrint - 2 - WARNING
    PrintFReporter._isWarningMustBePrint - 3 - WARNING
    PrintFReporter.getReport - 11 - ERROR

or use print-all for see more:

dart-codemetrics --print-all=true --begin-warning-complexity-number=2 --begin-error-complexity-number=4 

Reporting options

For html output use the --report-format=html and for JSON use --report-format=json. A full command could look like this:

dart bin/codemetrics.dart --analysis-root=/path/to/your/package --report-format=html > /tmp/test.html

Looking for contributors

There are number of areas you can contribute to this project:

  • code reviews: I always welcome criticism to my code, esp. when it comes to the analysis package
  • documentation: the code is mostly undocumented
  • tests: there are little if any tests written for this package
  • funtionality: if you feel contributing with some functionality, let me know!

About

Codemetrics for Dart is a simple command line utility that provides some insight into the "quality" of code.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Dart 90.6%
  • HTML 9.4%