Purpose

Does oxlint support cyclomatic/cognitive complexity checks or max line length rules?

Key Findings

  • max-len (line length): Built into oxlint core — enabled via config
  • max-lines and max-lines-per-function: Built into oxlint core
  • Cyclomatic/Cognitive complexity: NOT in oxlint core — use the community plugin oxlint-plugin-complexity

Built-in Rules (Oxlint Core)

eslint/max-len — Max Line Length

Enforces a maximum line length. Added to oxlint in April 2024.

Config (oxlintrc.json):

{
"rules": {
"max-len": ["error", {
"code": 100,
"ignoreUrls": true,
"ignoreStrings": false,
"ignoreTemplateLiterals": false,
"ignoreRegExpLiterals": false,
"ignoreComments": false,
"ignoreTrailingComments": false,
"ignorePattern": ""
}]
}
}

Note: JSX comment handling has limitations in the current AST.

Docs: https://oxc.rs/docs/guide/usage/linter/rules/eslint/max-len


eslint/max-lines — Max Lines Per File

Enforces a maximum number of lines per file.


eslint/max-lines-per-function — Max Lines Per Function

Enforces a maximum number of lines within a function (default: 50).

Config:

{
"rules": {
"max-lines-per-function": ["error", {
"max": 50,
"skipBlankLines": false,
"skipComments": false,
"IIFEs": false
}]
}
}

Docs: https://oxc.rs/docs/guide/usage/linter/rules/eslint/max-lines-per-function


Community Plugin: oxlint-plugin-complexity

For cyclomatic and cognitive complexity, use the third-party plugin:

Install:

Terminal window
npm install oxlint-plugin-complexity --save-dev

Config (oxlintrc.json):

{
"jsPlugins": ["oxlint-plugin-complexity"],
"rules": {
"complexity/complexity": ["error", {
"cyclomatic": 20,
"cognitive": 15,
"minLines": 10,
"enableExtraction": true,
"nestingTipThreshold": 3,
"elseIfChainThreshold": 4,
"logicalOperatorThreshold": 3
}]
}
}

Cyclomatic Complexity

Counts decision points (+1 for each): if, for, for...in, for...of, while, do...while, case, catch, ? :, &&, ||, ??

Cognitive Complexity

Penalizes nesting depth to measure understandability. Excludes React components and default value patterns like a || [].

Plugin Options

OptionDefaultPurpose
cyclomatic20Max cyclomatic threshold
cognitive15Max cognitive threshold
minLines10Skip functions shorter than N lines
enableExtractiontrueSuggest extractable blocks
nestingTipThreshold3Nesting depth to trigger tip
elseIfChainThreshold4else-if chain length to trigger tip
logicalOperatorThreshold3Logical operator count to trigger tip

Supports: .js, .mjs, .cjs, .ts, .tsx, .jsx, .vue (extracts <script> blocks)

Plugin repo: https://github.com/itaymendel/oxlint-plugin-complexity


Summary Table

RuleBuilt-in?Notes
max-len✅ YesLine length limit
max-lines✅ YesLines per file limit
max-lines-per-function✅ YesLines per function limit
Cyclomatic complexity❌ Plugin onlyoxlint-plugin-complexity
Cognitive complexity❌ Plugin onlyoxlint-plugin-complexity

Sources

  1. oxlint rules: eslint/max-len
  2. oxlint rules: eslint/max-lines-per-function
  3. oxlint rules: eslint/max-lines
  4. oxlint-plugin-complexity GitHub
  5. PR : feat(linter): eslint/max-len