{"id":37427323,"url":"https://github.com/itaymendel/oxlint-plugin-complexity","last_synced_at":"2026-02-18T00:29:55.847Z","repository":{"id":330560555,"uuid":"1122725701","full_name":"itaymendel/oxlint-plugin-complexity","owner":"itaymendel","description":"Cyclomatic and cognitive complexity rules for oxlint with actionable error messages. Also available as a standalone library for programmatic complexity analysis.","archived":false,"fork":false,"pushed_at":"2026-01-10T13:21:06.000Z","size":105,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-11T03:13:25.920Z","etag":null,"topics":["complexity-analysis","linter","plugin"],"latest_commit_sha":null,"homepage":"","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/itaymendel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-25T11:20:23.000Z","updated_at":"2026-01-10T10:03:32.000Z","dependencies_parsed_at":"2025-12-27T22:00:56.449Z","dependency_job_id":null,"html_url":"https://github.com/itaymendel/oxlint-plugin-complexity","commit_stats":null,"previous_names":["itaymendel/oxlint-plugin-complexity"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/itaymendel/oxlint-plugin-complexity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itaymendel%2Foxlint-plugin-complexity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itaymendel%2Foxlint-plugin-complexity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itaymendel%2Foxlint-plugin-complexity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itaymendel%2Foxlint-plugin-complexity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itaymendel","download_url":"https://codeload.github.com/itaymendel/oxlint-plugin-complexity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itaymendel%2Foxlint-plugin-complexity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-analysis","linter","plugin"],"created_at":"2026-01-16T06:22:53.920Z","updated_at":"2026-02-18T00:29:55.839Z","avatar_url":"https://github.com/itaymendel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oxlint-plugin-complexity\n\nCyclomatic and cognitive complexity rules for [oxlint](https://oxc.rs/docs/guide/usage/linter.html) with **actionable error messages**. Also available as a standalone library for programmatic complexity analysis.\n\n**Features:**\n\n- Cyclomatic and cognitive complexity analysis.\n- Actionable error messages with complexity breakdown.\n- [Programmatic API](./src/index.ts) for custom tooling\n- **Framework support:** React, Vue, Angular, Svelte, Astro, Solid, Qwik\n- **File types:** `.js` `.mjs` `.cjs` `.ts` `.tsx` `.jsx` `.vue` `.svelte` `.astro`\n\n\u003e **Note:** Refactoring tips require cognitive complexity (only it tracks nesting depth).\n\n## Quick Start\n\n```bash\nnpm install oxlint-plugin-complexity --save-dev\n```\n\n```json\n// .oxlintrc.json\n{\n  \"jsPlugins\": [\"oxlint-plugin-complexity\"],\n  \"rules\": {\n    \"complexity/complexity\": [\n      \"error\",\n      {\n        \"cyclomatic\": 20,\n        \"cognitive\": 15\n      }\n    ]\n  }\n}\n```\n\n## Actionable Error Messages\n\nError messages show a summary, line-by-line breakdown, and refactoring tips for deep nesting:\n\n```\ncomplexity(complexity): Function 'processData' has Cognitive Complexity of 15.\nMaximum allowed is 10. [if: +14, for: +1]\n\nBreakdown:\n   Line 2: +1 for 'for'\n   Line 3: +2 for 'if' (incl. +1 nesting)\n   Line 4: +3 for 'if' (incl. +2 nesting)\n   Line 5: +4 for 'if' (incl. +3 nesting)\n\u003e\u003e\u003e Line 6: +5 for 'if' (incl. +4 nesting) [top offender]\n    ↳ Tip: Extract inner loops into helper functions - each extraction removes one nesting level\n```\n\n```javascript\nfunction processData(items, mode, config) {\n  for (const item of items) {\n    // Line 2: +1\n    if (item.active) {\n      // Line 3: +2 (nesting=1)\n      if (mode === 'strict') {\n        // Line 4: +3 (nesting=2)\n        if (config.validate) {\n          // Line 5: +4 (nesting=3)\n          if (item.required) {\n            // Line 6: +5 (nesting=4) \u003c- top offender\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n## Rule Configuration\n\n```jsonc\n{\n  \"complexity/complexity\": [\n    \"error\",\n    {\n      // Complexity thresholds\n      \"cyclomatic\": 20, // Default: 20\n      \"cognitive\": 15, // Default: 15\n\n      // Performance optimization (optional)\n      \"minLines\": 10, // Default: 10 (skip functions \u003c10 lines like getters; 0 = analyze all; counts comments/blanks)\n\n      // Extraction suggestions (optional)\n      \"enableExtraction\": true, // Default: true\n      \"extractionMultiplier\": 1.5, // Default: 1.5 (triggers at 1.5× cognitive threshold)\n      \"minExtractionPercentage\": 30, // Default: 30 (min % of total complexity to suggest)\n\n      // Refactoring tip thresholds (optional, set to 0 to disable)\n      \"nestingTipThreshold\": 3, // Default: 3\n      \"elseIfChainThreshold\": 4, // Default: 4\n      \"logicalOperatorThreshold\": 3, // Default: 3\n    },\n  ],\n}\n```\n\n### Cyclomatic Complexity\n\nCounts decision points in code. [Learn more](https://en.wikipedia.org/wiki/Cyclomatic_complexity)\n\n**+1 for:** `if`, `for`, `for...in`, `for...of`, `while`, `do...while`, `case`, `catch`, `? :`, `\u0026\u0026`, `||`, `??`\n\n### Cognitive Complexity\n\nMeasures how difficult code is to understand by penalizing nesting. [Learn more](https://www.sonarsource.com/resources/cognitive-complexity/)\n\n- **+1 for:** `if`/`for`/`while`/`switch`/`catch`/`? :` (+nesting), `else`, logical sequence changes, nested functions, recursion\n- **Excluded:** React components (PascalCase + returns JSX), default value patterns (`a || []`)\n\n### Refactoring Tips\n\nDetects common complexity patterns and provides actionable tips:\n\n- **Deep nesting** (`nestingTipThreshold`): Suggests extracting inner loops/conditions\n- **Long else-if chains** (`elseIfChainThreshold`): Recommends lookup tables or strategy pattern\n- **Logical operator sequences** (`logicalOperatorThreshold`): Suggests extracting boolean expressions\n\n### Extraction Suggestions\n\nAnalyzes variable flow to identify extractable code blocks (enabled by default, disable with `enableExtraction: false`):\n\n**Example output:**\n\n```\nSmart extraction suggestions:\n\n  Lines 9-22: Extractable with some refactoring\n    Complexity: +11 (55% of total)\n    Inputs: order, config, processedItems\n    Suggested: processOrder(order, config, processedItems): void\n\n  Lines 25-33: Requires significant refactoring\n    Complexity: +6 (30% of total)\n    Inputs: config, totalCount, processedItems\n    Issue: Mutates external variable 'totalCount' (line 27)\n    Suggestion: Consider returning 'totalCount' instead of mutating it\n```\n\n**TypeScript support:** Preserves type annotations in suggested signatures:\n\n```\nInputs: config: Config, results: number[]\nSuggested: processBlock(config: Config, results: number[]): void\n```\n\n#### Known Limitations\n\nExtraction suggestions use static analysis heuristics and may miss:\n\n- **Globals/module variables** (not tracked by variable flow analysis)\n- **Complex flows** (closures, dynamic properties, indirect mutations)\n\nAlways review suggestions before applying, even when marked \"high confidence\".\n\n---\n\n## Migration from v0.x\n\nReplace the removed `max-cyclomatic` / `max-cognitive` rules with the combined `complexity` rule:\n\n```diff\n// .oxlintrc.json\n{\n  \"jsPlugins\": [\"oxlint-plugin-complexity\"],\n  \"rules\": {\n-   \"complexity/max-cyclomatic\": [\"error\", { \"max\": 20 }],\n-   \"complexity/max-cognitive\": [\"error\", { \"max\": 15 }]\n+   \"complexity/complexity\": [\"error\", {\n+     \"cyclomatic\": 20,\n+     \"cognitive\": 15\n+   }]\n  }\n}\n```\n\n---\n\n## Attribution\n\nThe cognitive complexity metric is based on [G. Ann Campbell's specification](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) (SonarSource, 2016).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitaymendel%2Foxlint-plugin-complexity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitaymendel%2Foxlint-plugin-complexity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitaymendel%2Foxlint-plugin-complexity/lists"}