Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ESLintCC is a ECMAScript/JavaScript tool that computes complexity of code by using ESLint
ESLintCC is a ECMAScript/JavaScript tool that computes complexity of code by using ESLint
ESLint calculates complexity of code, while this tool only collects a report based on his complexity rule messages
Requirements, principles of local and global installation and usage are the same as ESLint Installation and Usage
Globally:
$ npm install -g eslintcc
$ eslintcc yourfile.js
Locally:
$ npm install eslintcc
$ ./node_modules/.bin/eslintcc yourfile.js
Integration in JavaScript application:
const { Complexity } = require('eslintcc');
const complexity = new Complexity();
const report = complexity.executeOnFiles(['yourfile.js']);
console.log(JSON.stringify(report, null, '\t'));
Note: ESLintCC ignores all rules, specified in configuration files, and uses to generate a report only complexity rules.
ESLintCC uses ESLint along with Its configuration system. You can use configuration comments and files, as described in the configuration for ESLint.
Difference: ESLintCC uses its own settings for complexity rules, so they cannot be overridden through a configuration file. However, you can disable them locally in the file.
Features:
.eslintrc.json
:{
"parserOptions": {
"ecmaVersion": 2017
}
}
// For a file
/* eslint max-params: off, max-depth: off */
function myFunc(a, b, c, d, e) {
//...
}
// For a block
/* eslint-disable max-params */
function myFunc(a, b, c, d, e) {
//...
}
/* eslint-enable max-params */
function myFunc2(a, b) {
//...
}
// For a line
/* eslint-disable-next-line max-params */
function myFunc(a, b, c, d, e) {
//...
}
Every function and block will be ranked from A (best complexity score) to F (worst one). This ranks is based on the ranks of complexity of the Python Radon.
Rank Risk
Ranks corresponds to rule complexity scores as follows:
Rules | A | B | C | D | E | F |
---|---|---|---|---|---|---|
Logic: | ||||||
complexity | 1 - 5 | 6 - 10 | 11 - 20 | 21 - 30 | 31 - 40 | 41 + |
max-depth | 1 - 2 | 3 | 4 - 5 | 6 - 7 | 8 | 9 + |
max-nested-callbacks | 1 - 3 | 4 - 5 | 6 - 10 | 11 - 15 | 16 - 20 | 21 + |
max-params | 1 | 2 | 3 - 4 | 5 | 6 | 7 + |
Raw: | ||||||
max-lines | 1 - 75 | 76 - 150 | 151 - 300 | 301 - 450 | 451 - 600 | 601 + |
max-lines-per-function | 1 - 13 | 14 - 25 | 26 - 50 | 51 - 75 | 76 - 100 | 101 + |
max-statements | 1 - 3 | 4 - 5 | 6 - 10 | 11 - 15 | 16 - 20 | 21 + |
Note: For rank "C", the maximum score, using from the standard score of ESLint rules. See complexity rules. Other rules are calculated relative to the values of the "complexity" rule.
Example formula:
[5, 10, 20, 30, 40].map(score => Math.round((score / 20) * defaultRuleScoreLimit))
Command line format:
$ eslintcc [options] file.js [file.js] [dir]
Option | Type | Description |
---|---|---|
--rules <rules>, -r=<rules> | Array of String | Rule, or group: all, logic, raw. Default: logic |
--format <format>, -f=<format> | String | Use a specific output format, text or json. Default: text |
--average, -a | Flag | Show the average complexity at the end of output, if used text format |
--show-rules, -sr | Flag | Show rule name and value, if used text format |
--greater-than <value>, -gt=<value> | String or Number | Will show rules more than rank a, b, c, d, e, or rank value |
--less-than <value>, -lt=<value> | String or Number | Will show rules less than rank b, c, d, e, f, or rank value |
--no-inline-config, -nlc | Flag | Disable the use of configuration comments (such as /*eslint-disable*/ ) |
--max-rank <value>, -mr=<value> | String or Number | Maximum allowed complexity rank for a single message. Default: C |
--max-average-rank <value>, -mar=<value> | String or Number | Maximum allowed complexity rank for average value. Default: B |
If the rank value for one message or the average value is higher than the allowed value, the program terminates with error code 1
Output as JSON and show rules more than rank E:
$ eslintcc -f=json -gt=e file.js
Use only 2 rules and show rule name:
$ eslintcc --rules complexity --rules max-depth --show-rules file.js
FAQs
ESLintCC is a ECMAScript/JavaScript tool that computes complexity of code by using ESLint
We found that eslintcc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.