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
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
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
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!