{"id":19964047,"url":"https://github.com/pilotpirxie/cyclomatic-complexity","last_synced_at":"2025-05-03T23:30:26.486Z","repository":{"id":194705693,"uuid":"691648412","full_name":"pilotpirxie/cyclomatic-complexity","owner":"pilotpirxie","description":"🐌 Detect cyclomatic complexity of your JavaScript and TypeScript code","archived":false,"fork":false,"pushed_at":"2024-10-05T12:34:26.000Z","size":214,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-03T14:42:21.070Z","etag":null,"topics":["cc","complexity","cyclomatic","cyclomatic-complexity","esprima","javascript","jsx","tsx","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cyclomatic-complexity","language":"TypeScript","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/pilotpirxie.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}},"created_at":"2023-09-14T15:41:44.000Z","updated_at":"2025-05-01T17:55:58.000Z","dependencies_parsed_at":"2024-03-10T20:51:32.738Z","dependency_job_id":null,"html_url":"https://github.com/pilotpirxie/cyclomatic-complexity","commit_stats":null,"previous_names":["pilotpirxie/cyclomatic-complexity"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotpirxie%2Fcyclomatic-complexity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotpirxie%2Fcyclomatic-complexity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotpirxie%2Fcyclomatic-complexity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotpirxie%2Fcyclomatic-complexity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilotpirxie","download_url":"https://codeload.github.com/pilotpirxie/cyclomatic-complexity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252269026,"owners_count":21721239,"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":["cc","complexity","cyclomatic","cyclomatic-complexity","esprima","javascript","jsx","tsx","typescript"],"created_at":"2024-11-13T02:18:58.621Z","updated_at":"2025-05-03T23:30:26.088Z","avatar_url":"https://github.com/pilotpirxie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cyclomatic-complexity\n\nDetect cyclomatic complexity of your JavaScript and TypeScript code. You can use it as a CLI tool or as a programmatic library.\n\nCyclomatic complexity is a software metric used to indicate the complexity of a program. It measures the number of linearly independent paths through a program's source code, providing insights into code maintainability and testability.\n\nIn simple words, it's a measure of how many different paths a piece of code can take. The higher the cyclomatic complexity, the more difficult it is to understand and maintain the code.\n\n## Basic Usage\n\nRun with npx and pass a glob pattern to your source files:\n\n```sh\nnpx cyclomatic-complexity './**/*'\n```\n\nExample output:\n```sh\nsrc/utils/useLocalStorage.ts: 15 (OK)\n  [line: 13] handler: 5 (OK)\n  [line: 7] anonymous: useEffect: 4 (OK)\n  [line: 24] anonymous: setValueWrap: 4 (OK)\n  [line: 5] useLocalStorage: 1 (OK)\n  [line: 20] anonymous: handler: 1 (OK)\n  [line: 0] global: 0 (OK)\n\nsrc/vite-env.d.ts: 0 (OK)\n  [line: 0] global: 0 (OK)\n```\n\nOr install it globally and run it:\n\n```sh\n# npm\nnpm install -g cyclomatic-complexity\n\n# yarn\nyarn global add cyclomatic-complexity\n\n# pnpm\npnpm install -g cyclomatic-complexity\n```\n\n## Advanced Usage\n\nTo check cyclomatic complexity of typescript files in `./src` folder and set warnings to 10 and errors to 20. Output as JSON:\n\n```sh\nnpx cyclomatic-complexity './src/**/*.ts' --threshold-warnings 10 --threshold-errors 20 --json\n```\n\nExample output:\n```json\n[\n  {\n    \"file\": \"src/vite-env.d.ts\",\n    \"functionComplexities\": [\n      {\n        \"name\": \"global\",\n        \"complexity\": 0,\n        \"line\": 0\n      }\n    ],\n    \"complexityLevel\": \"ok\",\n    \"complexitySum\": 0\n  },\n  {\n    \"file\": \"src/utils/useLocalStorage.ts\",\n    \"functionComplexities\": [\n      {\n        \"name\": \"handler\",\n        \"complexity\": 5,\n        \"line\": 13\n      },\n      {\n        \"name\": \"anonymous: useEffect\",\n        \"complexity\": 4,\n        \"line\": 7\n      },\n      {\n        \"name\": \"anonymous: setValueWrap\",\n        \"complexity\": 4,\n        \"line\": 24\n      },\n      {\n        \"name\": \"useLocalStorage\",\n        \"complexity\": 1,\n        \"line\": 5\n      },\n      {\n        \"name\": \"anonymous: handler\",\n        \"complexity\": 1,\n        \"line\": 20\n      },\n      {\n        \"name\": \"global\",\n        \"complexity\": 0,\n        \"line\": 0\n      }\n    ],\n    \"complexityLevel\": \"ok\",\n    \"complexitySum\": 15\n  }\n]\n\n```\n\n## Requirements\n* Node \u003e= 18\n\n## Options\n\n```shell\nUsage: code-complexity [options] \u003cpattern\u003e\n\nCalculates code complexity of given files\n\nArguments:\n  pattern                             Glob pattern for files to check\n\nOptions:\n  -tw, --threshold-warnings \u003cnumber\u003e  Threshold for warnings (default: \"10\")\n  -te, --threshold-errors \u003cnumber\u003e    Threshold for errors (default: \"20\")\n  -j, --json                          Output as JSON (default: false)\n  -e, --exclude \u003cpattern\u003e             Exclude pattern (default: \"**/node_modules/**\")\n  -h, --help                          display help for command\n```\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilotpirxie%2Fcyclomatic-complexity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilotpirxie%2Fcyclomatic-complexity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilotpirxie%2Fcyclomatic-complexity/lists"}