{"record":{"id":"a387ddcb39297d14","repo":"oxc-project/oxc","slug":"enforces-a-maximum-depth-to-nested-describe-calls","errorCode":null,"errorMessage":"Enforces a maximum depth to nested describe calls.","messagePattern":"Enforces a maximum depth to nested describe calls\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/max_nested_describe.rs","lineNumber":16,"sourceCode":"use schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, collect_possible_jest_call_node, is_type_of_jest_fn_call,\n    },\n};\n\nfn exceeded_max_depth(current: u32, max: u32, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Enforces a maximum depth to nested describe calls.\")\n        .with_help(format!(\"Too many nested describe calls ({current}) - maximum allowed is {max}\"))\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r#\"### What it does\n\nThis rule enforces a maximum depth to nested `describe()` calls.\n\n### Why is this bad?\n\nNesting `describe()` blocks too deeply can make the test suite hard to read and understand.\n\n### Examples\n\nThe following patterns are considered warnings (with the default option of\n`{ \"max\": 5 } `):\n\nExamples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/max_nested_describe.rs#L1-L34","documentation":"Diagnostic from the oxlint rule `jest/max-nested-describe` (shared with `vitest/max-nested-describe`) in crates/oxc_linter/src/rules/shared/jest_vitest/max_nested_describe.rs:16. It fires when `describe()` blocks are nested deeper than the configured `maxDepth` (default 5). Deeply nested suites hurt readability, so the linter labels the offending `describe` span and reports the current depth versus the maximum in the help text.","triggerScenarios":"A test file nests more than maxDepth (default 5) `describe()` calls, e.g. describe inside describe six levels deep. The rule tracks describe depth while walking possible jest call nodes (collect_possible_jest_call_node) and emits exceeded_max_depth(current, max, span) on the describe call that crosses the limit.","commonSituations":"Suites that mirror a deep folder structure; teams migrating from Mocha where heavy nesting was conventional; generated tests; CI newly enabling the jest/vitest plugin categories in oxlint so the rule starts reporting on legacy files.","solutions":["Flatten the suite: extract the deepest describe blocks into separate files, or merge levels that add no value","Raise the limit explicitly if deeper nesting is intentional: { \"jest/max-nested-describe\": [\"error\", { \"maxDepth\": 8 }] } in .oxlintrc.json","Suppress for one file with an oxlint-disable jest/max-nested-describe comment (or turn the rule off) when nesting is deliberate"],"exampleFix":"// before (6 levels)\ndescribe('a', () => { describe('b', () => { describe('c', () => { describe('d', () => { describe('e', () => { describe('f', () => { it('works', fn); }); }); }); }); }); });\n\n// after: split into files, keep depth <= 5\n// file: a.b.c.d.spec.ts\ndescribe('a b c d', () => { describe('e', () => { it('works', fn); }); });","handlingStrategy":"validation","validationCode":"npx oxlint -c .oxlintrc.json 'tests/**/*.spec.ts' # jest/max-nested-describe reports depth violations before CI","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run oxlint in a pre-commit hook so nesting violations surface locally, not in CI","Keep suites shallow by design: one or two describe levels, flat lists of cases","Set an explicit maxDepth in .oxlintrc.json so the team limit is documented, not implicit"],"tags":["jest","vitest","oxlint","testing","nesting","describe"],"backgroundTag":"test-nesting-depth","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}