js-code-metric
Visualize JavaScript source complexity with js-code-metric.
Based on the older es5 plato, this is a port to es6
and eslint
Start in 3 steps.
-
Install.
npm install --save-dev js-code-metric
-
Add.
"scripts" : {
"js-code-metric": "./node_modules/.bin/jschecker -r -d ./report src",
}
- Run.
npm run js-code-metric
Installation
Install the module with: npm install --save-dev js-code-metric
Usage
From scripts
//be sure and set your src, output, and any options.let src = "./scripts/**/*.js";let outputDir = "./artifacts/jschecker"; let jscheckerArgs = title: "example" eslint: {}; //you can use the reports in the callback. { let overview = jschecker; let total average = overviewsummary; let output = `total ---------------------- eslint: sloc: maintainability: average ---------------------- eslint: sloc: maintainability: `; console;} //usage is jschecker.inspectjschecker;
Example Gulpfile
let gulp = ;let jschecker = ; let src = "./scripts/**/*.js";let outputDir = "./artifacts/jschecker"; let lintRules = rules: indent: 2 "tab" quotes: 2 "single" semi: 2 "always" "no-console": 1 curly: "error" "no-dupe-keys": 2 "func-names": 1 "always" env: es6: true globals: "require" parserOptions: sourceType: "module" ecmaFeatures: jsx: true modules: true ; let complexityRules = {}; let jscheckerArgs = title: "example" eslint: lintRules complexity: complexityRules; { return jschecker;} gulp;
From the commandline
Usage : js-code-metric [options] -d <output_dir> <input files> -h, --help Display this help text. -q, --quiet Reduce output to errors only -v, --version Print the version. -x, --exclude : String File exclusion regex -d, --dir : String *required* The output directory -r, --recurse Recursively search directories -l, --jshint : String Specify a jshintrc file
Example
js-code-metric -r -d report src
Data sources
- Complexity from typhonjs-escomplex
- Lint data from eslint
Contributors
- [Rajaprabhu]
Release History
version | update |
---|---|
1.0.0-alpha | Project works with es6 and eslint |
About
This is currently a reimplementation of the older plato, and started as a fork from https://github.com/deedubs/js-code-metric, but has since been heavily modified. After seeing it was unpublished on npm and also wanting to add more features, This project uses eslint, not jshint for default linting.
I have switched to the typhon-js module since it properly parses classes.
License
Copyright (c) 2019 Rajaprabhu Licensed under the MIT license.