{"record":{"id":"90dfdfe51d0ecc75","repo":"oxc-project/oxc","slug":"name-has-a-complexity-of-complexity-maximum-a","errorCode":null,"errorMessage":"{name} has a complexity of {complexity}. Maximum allowed is {max}.","messagePattern":"(.+?) has a complexity of (.+?)\\. Maximum allowed is (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/complexity.rs","lineNumber":21,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::ScopeFlags;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::AssignmentOperator;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse serde_json::Value;\nuse std::ops::Deref;\n\nuse crate::{\n    AstNode,\n    ast_util::get_function_name_with_kind,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn complexity_diagnostic(span: Span, name: &str, complexity: u32, max: u32) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"{name} has a complexity of {complexity}. Maximum allowed is {max}.\"\n    ))\n    .with_label(span)\n}\n\nconst THRESHOLD_DEFAULT: u32 = 20;\n\n#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct ComplexityConfig {\n    /// Maximum amount of cyclomatic complexity\n    #[serde(alias = \"maximum\")]\n    max: u32,\n    /// The cyclomatic complexity variant to use\n    variant: Variant,\n}\n\nimpl Default for ComplexityConfig {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/complexity.rs#L3-L39","documentation":"Oxlint's port of the ESLint rule complexity. It counts the independent branch points of a function (if/else-if, loops, case clauses, catch, short-circuit operators, ternaries) and reports the function when the total exceeds the configured maximum. The message interpolates the function description from get_function_name_with_kind, the measured complexity, and the limit. The default threshold is 20 (THRESHOLD_DEFAULT at crates/oxc_linter/src/rules/eslint/complexity.rs:27) and the config field `max` also accepts the ESLint-style alias `maximum`.","triggerScenarios":"Linting any function whose counted decision points exceed `max` (default 20), e.g. a function with 15 if/else-if branches plus 6 `&&`/`||` operators reports complexity 22 against max 20. Lowering `max` in .oxlintrc.json immediately reports more functions.","commonSituations":"Enabling complexity on a brownfield codebase with long dispatch or validation functions; migrating an ESLint config that used the `maximum` key; CI failures after a team tightens the limit without refactoring first.","solutions":["Refactor the function: split responsibilities, use early returns, or replace long branch chains with a lookup table or map dispatch.","Raise the limit if it is unrealistic for the codebase: { \"complexity\": [\"warn\", { \"max\": 30 }] }.","Suppress the single occurrence with `// oxlint-disable-line complexity` while scheduling the refactor.","Extract nested conditionals into named predicate functions so each unit stays under the limit."],"exampleFix":"// before (complexity 22)\nfunction route(req) {\n  if (req.t === 'a') { return fa(req); }\n  else if (req.t === 'b') { return fb(req); }\n  /* 20 more branches */\n}\n\n// after\nconst routes = { a: fa, b: fb };\nfunction route(req) {\n  return (routes[req.t] ?? unknown)(req);\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — pick a threshold the codebase actually passes\n{\n  \"rules\": {\n    \"complexity\": [\"warn\", { \"max\": 30 }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the rule at \"warn\" first and gate to \"error\" once the backlog is cleared.","Extract predicates and handlers when a function approaches ~10 branches.","Remember the count includes && , || , ternaries, case clauses, and catch blocks, not just if statements."],"tags":["eslint","oxlint","complexity","maintainability"],"backgroundTag":"cyclomatic-complexity-exceeded","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}