{"id":14978211,"url":"https://github.com/vitalets/eslint-plugin-visual-complexity","last_synced_at":"2025-10-28T08:31:57.060Z","repository":{"id":255678348,"uuid":"853403183","full_name":"vitalets/eslint-plugin-visual-complexity","owner":"vitalets","description":"Enforce a visual complexity of the code","archived":false,"fork":false,"pushed_at":"2024-09-07T07:31:29.000Z","size":174,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-04T09:09:39.762Z","etag":null,"topics":["complexity","eslint","eslint-plugin"],"latest_commit_sha":null,"homepage":"","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/vitalets.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},"funding":{"github":["vitalets"]}},"created_at":"2024-09-06T15:30:36.000Z","updated_at":"2024-09-17T13:20:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b4ed82f-9334-4d2c-98a3-909640ee4a2a","html_url":"https://github.com/vitalets/eslint-plugin-visual-complexity","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"3edf904928539a22445af4ce2a45356a9bf4cbe9"},"previous_names":["vitalets/eslint-plugin-visual-complexity"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Feslint-plugin-visual-complexity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Feslint-plugin-visual-complexity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Feslint-plugin-visual-complexity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Feslint-plugin-visual-complexity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalets","download_url":"https://codeload.github.com/vitalets/eslint-plugin-visual-complexity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859903,"owners_count":16556031,"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","eslint-plugin"],"created_at":"2024-09-24T13:57:04.537Z","updated_at":"2025-10-28T08:31:51.702Z","avatar_url":"https://github.com/vitalets.png","language":"JavaScript","funding_links":["https://github.com/sponsors/vitalets"],"categories":[],"sub_categories":[],"readme":"# eslint-plugin-visual-complexity\n\n[![lint](https://github.com/vitalets/eslint-plugin-visual-complexity/actions/workflows/lint.yaml/badge.svg)](https://github.com/vitalets/eslint-plugin-visual-complexity/actions/workflows/lint.yaml)\n[![test](https://github.com/vitalets/eslint-plugin-visual-complexity/actions/workflows/test.yaml/badge.svg)](https://github.com/vitalets/eslint-plugin-visual-complexity/actions/workflows/test.yaml)\n[![npm version](https://img.shields.io/npm/v/eslint-plugin-visual-complexity)](https://www.npmjs.com/package/eslint-plugin-visual-complexity)\n[![license](https://img.shields.io/npm/l/eslint-plugin-visual-complexity)](https://github.com/vitalets/eslint-plugin-visual-complexity/blob/main/LICENSE)\n\nA custom eslint rule to check code [complexity](https://eslint.org/docs/latest/rules/complexity) without optional chaining.\n\n## Motivation\nStarting from v9, eslint [changed](https://github.com/eslint/eslint/issues/18060) the algorithm of calculating cyclomatic complexity of the code. Now it additionally counts [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining). While it matches the complexity formula, these expressions don't actually increase the _visual complexity_.\n\nFor example, the following function has a complexity **4** by the core eslint rule:\n\n```js\nfunction f(a) {\n  return a?.b?.c?.d;\n}\n```\n\nIt means the function is equivalent to:\n```js\nfunction f(a) {\n  if (condition) {\n    if (condition) {\n        return a;\n      } else if (condition) {\n        return b;\n     } else {\n       return c;\n     }\n  } else {\n    return d;\n  }\n}\n```\nBut visually they are quite different. \n\nThis plugin extends eslint `complexity` rule and \nkicks out optional chaining during calculation. It outputs **1** for the first function and **4** for the second one.\n\n\u003e There was a request to provide a built-in option to disable optional chaining counting, but it was [discarded](https://github.com/eslint/eslint/issues/18432).\n\n## Usage\n\n1. Install the package:\n    ```\n    npm install -D eslint-plugin-visual-complexity\n    ```\n\n2. Import and use the plugin in `eslint.config.js`:\n    ```js\n    import visualComplexity from \"eslint-plugin-visual-complexity\";\n\n    export default [\n      {\n        plugins: {\n          visual: visualComplexity,\n        },\n        rules: {\n          \"visual/complexity\": [\"error\", { max: 6 }],\n          complexity: 0, // \u003c- disable core complexity rule\n        }\n      }\n      // ...\n    ]\n    ```\n\n## License\n[MIT](https://github.com/vitalets/eslint-plugin-visual-complexity/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Feslint-plugin-visual-complexity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalets%2Feslint-plugin-visual-complexity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Feslint-plugin-visual-complexity/lists"}