{"id":27180194,"url":"https://github.com/eslintcc/eslintcc","last_synced_at":"2025-04-09T14:25:53.847Z","repository":{"id":55086619,"uuid":"153572129","full_name":"eslintcc/eslintcc","owner":"eslintcc","description":"Complexity of Code - JavaScript/TypeScript","archived":false,"fork":false,"pushed_at":"2024-09-24T01:42:37.000Z","size":213,"stargazers_count":37,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T15:02:58.078Z","etag":null,"topics":["complexity","eslint","javascript","linter","static-code-analysis","typescript"],"latest_commit_sha":null,"homepage":"https://eslintcc.github.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eslintcc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-18T06:10:38.000Z","updated_at":"2025-02-28T00:30:34.000Z","dependencies_parsed_at":"2024-06-19T01:55:11.506Z","dependency_job_id":null,"html_url":"https://github.com/eslintcc/eslintcc","commit_stats":{"total_commits":232,"total_committers":4,"mean_commits":58.0,"dds":0.5517241379310345,"last_synced_commit":"de164693784f6a94a7c5e674192de1e3d5e9d555"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eslintcc%2Feslintcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eslintcc%2Feslintcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eslintcc%2Feslintcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eslintcc%2Feslintcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eslintcc","download_url":"https://codeload.github.com/eslintcc/eslintcc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247352834,"owners_count":20925313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["complexity","eslint","javascript","linter","static-code-analysis","typescript"],"created_at":"2025-04-09T14:25:53.037Z","updated_at":"2025-04-09T14:25:53.831Z","avatar_url":"https://github.com/eslintcc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESLint Complexity of Code [![npm][npm_img]][npm_url] [![Checks ➜ Tests ➜ Publish][build_img]][build_url]\n\n[ESLintCC][npm_url] is a ECMAScript/JavaScript/TypeScript tool\nthat computes complexity of code by using [ESLint][eslint_npm]\n\n\u003e ESLint calculates complexity of code,\n\u003e while this tool only collects a report based on his [complexity rule messages][eslint_rule]\n\n## Installation and Usage\n\n\u003e Requirements, principles of local and global installation and usage\n\u003e are the same as [ESLint Installation and Usage][eslint_usage]\n\nGlobally:\n\n    $ npm install -g eslintcc\n    $ eslintcc yourfile.js\n\nLocally:\n\n    $ npm install eslintcc\n    $ ./node_modules/.bin/eslintcc yourfile.js\n\nNPX (you can do it without installing):\n\n    $ npx eslintcc yourfile.js\n\nIntegration in JavaScript application ([see more...](#nodejs-api)):\n\n```js\nconst { Complexity } = require('eslintcc');\n\nconst complexity = new Complexity();\nconst report = await complexity.lintFiles(['yourfile.js']);\n\nconsole.log(JSON.stringify(report, null, '\\t'));\n```\n\n**Note:** ESLintCC ignores all rules, specified in configuration files,\nand uses to generate a report only [complexity rules][eslint_rule].\n\n## Configuration\n\nESLintCC uses ESLint along with [Its configuration system][eslint_config].\nYou can use configuration comments and files, as described in the configuration for ESLint.\n\n**Difference:** ESLintCC uses its own settings for complexity rules,\nso they cannot be overridden through a configuration file.\nHowever, you can disable them locally in the file.\n\n**Features:**\n\n1.  You can configurate [parserOptions][eslint_parser_options]\n    or [parser][eslint_parser] for specify the JavaScript language support. `.eslintrc.json`:\n\n```json\n{\n  \"parserOptions\": {\n    \"ecmaVersion\": 2021,\n    \"sourceType\": \"module\"\n  }\n}\n```\n\n```json\n{\n  \"parser\": \"@typescript-eslint/parser\"\n}\n```\n\n2.  You can disable checks for a specific complexity rule for a file or part of file\n    [using a comment][eslint_disabling_comments]:\n\n```js\n// For a file\n/* eslint max-params: off, max-depth: off */\n\nfunction myFunc(a, b, c, d, e) {\n  //...\n}\n```\n\n```js\n// For a block\n/* eslint-disable max-params */\nfunction myFunc(a, b, c, d, e) {\n  //...\n}\n/* eslint-enable max-params */\nfunction myFunc2(a, b) {\n  //...\n}\n```\n\n```js\n// For a line\n/* eslint-disable-next-line max-params */\nfunction myFunc(a, b, c, d, e) {\n  //...\n}\n```\n\n## Customize parser\n\nExamples of [ESLint Parser][eslint_parser] configuration\n\n### Babel parser\n\nUsing Babel you can support experimental syntax.\nFor example private fields and methods for classes.\n\n\u003e See package [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)\n\npackage.json\n\n```json\n{\n  \"devDependencies\": {\n    \"@babel/eslint-parser\": \"latest\",\n    \"@babel/plugin-transform-class-properties\": \"latest\",\n    \"@babel/plugin-transform-private-methods\": \"latest\"\n  }\n}\n```\n\n.eslintrc.json\n\n```json\n{\n  \"parser\": \"@babel/eslint-parser\",\n  \"parserOptions\": {\n    \"sourceType\": \"module\",\n    \"babelOptions\": {\n      \"configFile\": \"./babel.config.json\"\n    }\n  }\n}\n```\n\n.babel.config.json\n\n```json\n{\n  \"plugins\": [\n    \"@babel/plugin-transform-class-properties\",\n    \"@babel/plugin-transform-private-methods\"\n  ]\n}\n```\n\n### TypeScript parser\n\n\u003e See package [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser)\n\nThis parser is used you can add a code complexity score to your TypeScript project.\nIn this case, the same standard ESLint rules are used for calculating complexity,\n[described in \"Complexity ranks\" section](#complexity-ranks).\n\npackage.json\n\n```json\n{\n  \"devDependencies\": {\n    \"typescript\": \"latest\",\n    \"@typescript-eslint/parser\": \"latest\",\n    \"@typescript-eslint/eslint-plugin\": \"latest\"\n  }\n}\n```\n\n.eslintrc.json\n\n```json\n{\n  \"overrides\": [\n    {\n      \"files\": [\n        \"*.ts\"\n      ],\n      \"parser\": \"@typescript-eslint/parser\",\n      \"plugins\": [\n        \"@typescript-eslint\"\n      ],\n      \"extends\": [\n        \"eslint:recommended\",\n        \"plugin:@typescript-eslint/recommended\"\n      ]\n    }\n  ]\n}\n```\n\n## Complexity ranks\n\nEvery function and block will be ranked from A (best complexity score) to F (worst one).\nThis ranks is based on the ranks of complexity of the [Python Radon][radon_cc_rank].\n\n**Rank\tRisk**\n\n*   **A**\tlow - simple block\n*   **B**\tlow - well structured and stable block\n*   **C**\tmoderate - slightly complex block\n*   **D**\tmore than moderate - more complex block\n*   **E**\thigh - complex block, alarming\n*   **F**\tvery high - error-prone, unstable block\n\nRanks corresponds to rule complexity scores as follows:\n\n| Rules                                                       | A      | B        | C         | D         | E         | F     |\n| ----------------------------------------------------------- | ------ | -------- | --------- | --------- | --------- | ----- |\n| Logic:                                                      |        |          |           |           |           |       |\n| [**complexity**][eslint_rule]                               | 1 - 5  | 6 - 10   | 11 - 20   | 21 - 30   | 31 - 40   | 41 +  |\n| [**max-depth**][eslint_max_depth]                           | 1 - 2  | 3        | 4 - 5     | 6 - 7     | 8         | 9 +   |\n| [**max-nested-callbacks**][eslint_max_nested_callbacks]     | 1 - 3  | 4 - 5    | 6 - 10    | 11 - 15   | 16 - 20   | 21 +  |\n| [**max-params**][eslint_max_params]                         | 1      | 2        | 3 - 4     | 5         | 6         | 7 +   |\n| Raw:                                                        |        |          |           |           |           |       |\n| [**max-lines**][eslint_max_lines]                           | 1 - 75 | 76 - 150 | 151 - 300 | 301 - 450 | 451 - 600 | 601 + |\n| [**max-lines-per-function**][eslint_max_lines_per_function] | 1 - 13 | 14 - 25  | 26 - 50   | 51 - 75   | 76 - 100  | 101 + |\n| [**max-statements**][eslint_max_statements]                 | 1 - 3  | 4 - 5    | 6 - 10    | 11 - 15   | 16 - 20   | 21 +  |\n\n\u003e **Note:** For rank \"C\", the maximum score, using from the standard score of ESLint rules.\n\u003e See [complexity rules][eslint_rule].\n\u003e Other rules are calculated relative to the values of the \"complexity\" rule.\n\u003e\n\u003e Example formula:\n\u003e `[5, 10, 20, 30, 40].map(score =\u003e Math.round((score / 20) * defaultRuleScoreLimit))`\n\n## Command line options\n\nCommand line format:\n\n    $ eslintcc [options] file.js [file.js] [dir]\n\n| Option                                         | Type             | Description                                                              |\n| ---------------------------------------------- | ---------------- | ------------------------------------------------------------------------ |\n| --rules \\\u003crules\u003e, -r=\\\u003crules\u003e              | Array of String  | Rule, or group: all, logic, raw. Default: logic                          |\n| --format \\\u003cformat\u003e, -f=\\\u003cformat\u003e           | String           | Use a specific output format, text or json. Default: text                |\n| --average, -a                                  | Flag             | Show the average complexity at the end of output, if used text format    |\n| --show-rules, -sr                              | Flag             | Show rule name and value, if used text format                            |\n| --greater-than \\\u003cvalue\u003e, -gt=\\\u003cvalue\u003e      | String or Number | Will show rules more than rank a, b, c, d, e, or rank value              |\n| --less-than \\\u003cvalue\u003e, -lt=\\\u003cvalue\u003e         | String or Number | Will show rules less than rank b, c, d, e, f, or rank value              |\n| --no-inline-config, -nlc                       | Flag             | Disable the use of configuration comments (such as `/*eslint-disable*/`) |\n| --max-rank \\\u003cvalue\u003e, -mr=\\\u003cvalue\u003e          | String or Number | Maximum allowed complexity rank for a single message. Default: C         |\n| --max-average-rank \\\u003cvalue\u003e, -mar=\\\u003cvalue\u003e | String or Number | Maximum allowed complexity rank for average value. Default: B            |\n\n\u003e If the rank value for one message or the average value is higher than the allowed value, the program terminates with error code 1\n\n### Command examples\n\nOutput as JSON and show rules more than rank **E**:\n\n    $ npx eslintcc -f=json -gt=e file.js\n\nUse only 2 rules and show rule name:\n\n    $ npx eslintcc --rules complexity --rules max-depth --show-rules file.js\n\n### Output examples\n\n\u003e Based on the test files from the directory:\n\u003e [./test/src/](https://github.com/eslintcc/eslintcc/blob/master/test/src)\n\n      $ npx eslintcc --show-rules ./test/src/complexity__max_rank.js\n      B test/src/complexity__max_rank.js\n        D  3:0 function MyFunc (max-params = 4)\n        A  9:0 function MyFunc1 (max-params = 1)\n        A 15:0 function MyFunc2 (max-params = 1)\n        A 21:0 function MyFunc3 (max-params = 1)\n        B 27:0 function myFunc4 (max-params = 2)\n        A 28:2 function myFunc4, IfStatement (28:2-32:3) (max-depth = 1)\n        A 29:7 function myFunc4, arrow function (29:7-31:5) (max-nested-callbacks = 1)\n      Error: Complexity of code above maximum allowable rank C (3), messages - 1\n\n\n      $ npx eslintcc --format json ./test/src/complexity__max_average_rank.js\n      {\"files\":[{\"file\":\"/development/github/eslintcc/test/src/complexity__max_average_rank.js\",\"messages\":[{\"loc\":{\"start\":{\"line\":3,\"column\":0},\"end\":{\"line\":5,\"column\":1}},\"type\":\"function\",\"name\":\"function MyFunc\",\"rules\":{\"max-params\":{\"value\":3,\"rank\":3,\"label\":\"C\"},\"complexity\":{\"value\":1,\"rank\":0.2,\"label\":\"A\"}},\"maxRule\":\"max-params\"}],\"average\":{\"rank\":3,\"label\":\"C\"}}],\"average\":{\"rank\":3,\"label\":\"C\"},\"ranks\":{\"A\":0,\"B\":0,\"C\":1,\"D\":0,\"E\":0,\"F\":0},\"errors\":{\"maxRank\":0,\"maxAverageRank\":true}}\n\n\n      $ npx eslintcc --show-rules ./test/src/custom_parser/typescript-eslint-parser.ts\n      A test/src/custom_parser/typescript-eslint-parser.ts\n        A 6:7 function test (max-params = 1)\n        A 7:4 function test, IfStatement (7:4-11:5) (max-depth = 1)\n\n## Node.js API\n\nWhile ESLintСС is designed to be run on the command line,\nit's possible to use ESLintСС programmatically through the Node.js API.\nThe purpose of the Node.js API is to allow plugin and tool authors to use the ESLintСС functionality directly,\nwithout going through the command line interface.\n\n### Complexity class\n\nIs a main class for use in Node.js applications.\n\n#### Example\n\n```js\nconst { Complexity } = require('eslintcc');\n\nconst complexity = new Complexity({\n  rules: 'logic',\n  eslintOptions: {\n    useEslintrc: false,\n    overrideConfig: {\n      parser: '@typescript-eslint/parser',\n      plugins: ['@typescript-eslint'],\n      extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended']\n    }\n  }\n});\nconst report = await complexity.lintFiles(['yourfile.ts']);\n\nconsole.log(JSON.stringify(report, null, '\\t'));\n```\n\n#### new Complexity(options)\n\nClass options equivalent to the command line (see [Command line options](#command-line-options)):\n\n*   **options.rules**, *Default: 'logic'*\n*   **options.greaterThan**, *Default: undefined*\n*   **options.lessThan**, *Default: undefined*\n*   **options.noInlineConfig**, *Default: false*\n*   **options.maxRank**, *Default: 'C'*\n*   **options.maxAverageRank**, *Default: 'B'*\n\nAdditional options available in API mode:\n\n*   **options.ranks**, *Default: null* -\n    Allows you to set an arbitrary comparison of ranks and max counters of indicators of the corresponding rules.\n\nExample:\n\n```js\nconst complexity = new Complexity({\n  ranks: {\n    'complexity': { A: 5, B: 10, C: 20, D: 30, E: 40, F: Infinity }\n    'max-depth': { A: 2, B: 3, C: 4, D: 6, E: 8, F: Infinity}\n  }\n})\n```\n\n*   **options.eslintOptions**, *Default: {}* -\n    This option allows you to configure the internal `ESLint class`.\n    It's allows you to set additional options described in the documentation:\n    [ESLint: Node.js API](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions)\n\n#### complexity.lintFiles(patterns)\n\nThis method lints the files that match the glob patterns and then returns the results.\n\n**Parameters**\n\n*   patterns *(string | string\\[])* -\n    The lint target files. This can contain any of file paths, directory paths, and glob patterns.\n\n**Return Value**\n\n*Promise\\\u003cComplexityResult\u003e* -\nThe promise that will be fulfilled with an ComplexityResult object.\n\nExample:\n\n```js\n{\n  'average': { 'rank': 0.2, 'label': 'A' },\n  'errors': {\n    'maxAverageRank': false,\n    'maxRank': 0\n  },\n  'ranks': {\n    'A': 1,\n    'B': 0,\n    'C': 0,\n    'D': 0,\n    'E': 0,\n    'F': 0\n  },\n  'files': [{\n    'average': { 'rank': 0.2, 'label': 'A' },\n    'file': ...absolute path to file...,\n    'messages': [{\n      'type': 'function',\n      'loc': { 'start': { 'line': 3, 'column': 0 }, 'end': { 'line': 5, 'column': 1 } },\n      'name': 'function myFunc',\n      'rules': { 'complexity': { 'value': 1, 'rank': 0.2, 'label': 'A' } },\n      'maxRule': 'complexity'\n    }]\n  }]\n}\n```\n\n[npm_img]: https://img.shields.io/npm/v/eslintcc.svg\n\n[npm_url]: https://www.npmjs.com/package/eslintcc\n\n[build_img]: https://github.com/eslintcc/eslintcc/actions/workflows/main.yml/badge.svg?branch=main\n\n[build_url]: https://github.com/eslintcc/eslintcc/actions/workflows/main.yml?query=branch:main\n\n[eslint_npm]: https://www.npmjs.com/package/eslint\n\n[eslint_rule]: https://eslint.org/docs/rules/complexity\n\n[eslint_max_depth]: https://eslint.org/docs/rules/max-depth\n\n[eslint_max_lines]: https://eslint.org/docs/rules/max-lines\n\n[eslint_max_lines_per_function]: https://eslint.org/docs/rules/max-lines-per-function\n\n[eslint_max_nested_callbacks]: https://eslint.org/docs/rules/max-nested-callbacks\n\n[eslint_max_params]: https://eslint.org/docs/rules/max-params\n\n[eslint_max_statements]: https://eslint.org/docs/rules/max-statements\n\n[eslint_usage]: https://github.com/eslint/eslint#installation-and-usage\n\n[eslint_config]: https://eslint.org/docs/user-guide/configuring/\n\n[eslint_parser_options]: https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options\n\n[eslint_parser]: https://eslint.org/docs/user-guide/configuring/plugins#specifying-parser\n\n[eslint_disabling_comments]: https://eslint.org/docs/user-guide/configuring/rules#disabling-rules\n\n[radon_cc_rank]: https://radon.readthedocs.io/en/latest/api.html#radon.complexity.cc_rank\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feslintcc%2Feslintcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feslintcc%2Feslintcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feslintcc%2Feslintcc/lists"}