{"record":{"id":"25b5034a054e6563","repo":"oxc-project/oxc","slug":"duplicate-hook-name-in-describe-block","errorCode":null,"errorMessage":"Duplicate {hook_name:?} in describe block.","messagePattern":"Duplicate (.+?) in describe block\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_duplicate_hooks.rs","lineNumber":16,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_semantic::NodeId;\nuse oxc_span::Span;\nuse rustc_hash::FxHashMap;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, PossibleJestNode,\n        collect_possible_jest_call_node, parse_jest_fn_call,\n    },\n};\n\nfn no_duplicate_hooks_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Duplicate {hook_name:?} in describe block.\"))\n        .with_help(\"Describe blocks can only have one of each hook. Consider consolidating the duplicate hooks into a single call.\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nDisallows duplicate hooks in describe blocks.\n\n### Why is this bad?\n\nHaving duplicate hooks in a describe block can lead to confusion and unexpected behavior.\nWhen multiple hooks of the same type exist, they all execute in order, which can make it\ndifficult to understand the test setup flow and may result in redundant or conflicting\noperations. This makes tests harder to maintain and debug.\n\n### Examples\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/no_duplicate_hooks.rs#L1-L34","documentation":"Diagnostic from oxlint rule `jest/no-duplicate-hooks` (shared with vitest) in crates/oxc_linter/src/rules/shared/jest_vitest/no_duplicate_hooks.rs:16. Inside one describe block each lifecycle hook type (beforeAll, beforeEach, afterAll, afterEach) may appear only once; the rule reports the second and later occurrence of the same hook_name. Duplicate hooks all execute in order, which is confusing and error-prone.","triggerScenarios":"Two or more calls to the same hook kind inside the same describe scope, e.g. two beforeEach blocks; the rule parses jest fn calls via parse_jest_fn_call and keeps an FxHashMap of seen hooks per describe node, reporting the duplicate's span.","commonSituations":"Copy-pasting setup into a second beforeEach instead of merging; merging branches that each added their own beforeAll; refactoring a describe and accidentally leaving the old hook; partial cleanup after moving hooks around.","solutions":["Merge the duplicate hooks into a single call, preserving the original execution order of their bodies","If the hooks belong to different concerns, move one to a nested describe so each scope keeps one hook of each type","Delete the stale hook when its logic was already inlined into the surviving one"],"exampleFix":"// before\ndescribe('cart', () => {\n  beforeEach(() => { seedCart(); });\n  beforeEach(() => { login(); });\n});\n\n// after\ndescribe('cart', () => {\n  beforeEach(() => { seedCart(); login(); });\n});","handlingStrategy":"validation","validationCode":"npx oxlint -c .oxlintrc.json tests/ # jest/no-duplicate-hooks reports the second same-type hook per describe","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When merging hooks from copied describes, check the target scope for an existing hook of that type","Keep one beforeEach per describe; push scoped setup into nested describes","Review hook diffs carefully during branch merges, where duplicates usually enter"],"tags":["jest","vitest","oxlint","testing","hooks","duplicates"],"backgroundTag":"duplicate-setup-hook","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"}