Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslintcc

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslintcc

ESLintCC is a ECMAScript/JavaScript tool that computes complexity of code by using ESLint

  • 0.3.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-11.78%
Maintainers
1
Weekly downloads
 
Created
Source

ESLint Complexity of Code npm Build Status Coverage Status

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

Installation and Usage

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.

Configuration

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:

  1. You can configurate parserOptions and parser for specify the JavaScript language support. .eslintrc.json:
{
  "parserOptions": {
    "ecmaVersion": 2017
  }
}
  1. You can disable checks for a specific complexity rule for a file or part of file using a comment:
// 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) {
  //...
}

Complexity ranks

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

  • A low - simple block
  • B low - well structured and stable block
  • C moderate - slightly complex block
  • D more than moderate - more complex block
  • E high - complex block, alarming
  • F very high - error-prone, unstable block

Ranks corresponds to rule complexity scores as follows:

RulesABCDEF
Logic:
complexity1 - 56 - 1011 - 2021 - 3031 - 4041 +
max-depth1 - 234 - 56 - 789 +
max-nested-callbacks1 - 34 - 56 - 1011 - 1516 - 2021 +
max-params123 - 4567 +
Raw:
max-lines1 - 7576 - 150151 - 300301 - 450451 - 600601 +
max-lines-per-function1 - 1314 - 2526 - 5051 - 7576 - 100101 +
max-statements1 - 34 - 56 - 1011 - 1516 - 2021 +

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 options

Command line format:

$ eslintcc [options] file.js [file.js] [dir]
OptionTypeDescription
--rules <rules>, -r=<rules>Array of StringRule, or group: all, logic, raw. Default: logic
--format <format>, -f=<format>StringUse a specific output format, text or json. Default: text
--average, -aFlagShow the average complexity at the end of output, if used text format
--show-rules, -srFlagShow rule name and value, if used text format
--greater-than <value>, -gt=<value>String or NumberWill show rules more than rank a, b, c, d, e, or rank value
--less-than <value>, -lt=<value>String or NumberWill show rules less than rank b, c, d, e, f, or rank value
--no-inline-config, -nlcFlagDisable the use of configuration comments (such as /*eslint-disable*/)
--max-rank <value>, -mr=<value>String or NumberMaximum allowed complexity rank for a single message. Default: C
--max-average-rank <value>, -mar=<value>String or NumberMaximum 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

Command examples

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

Keywords

FAQs

Package last updated on 27 Nov 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc