{"record":{"id":"6f599aeb4369f71c","repo":"oxc-project/oxc","slug":"do-not-call-jest-settimeout-multiple-times","errorCode":null,"errorMessage":"Do not call `jest.setTimeout` multiple times","messagePattern":"Do not call `jest\\.setTimeout` multiple times","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs","lineNumber":20,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::{AstNode, NodeId, ReferenceId};\nuse oxc_span::Span;\nuse rustc_hash::{FxHashMap, FxHashSet};\n\nuse crate::{\n    context::LintContext,\n    rule::Rule,\n    utils::{PossibleJestNode, collect_possible_jest_call_node, parse_jest_fn_call},\n};\n\nfn non_global_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`jest.setTimeout` should only be called in a global scope\")\n        .with_label(span)\n}\n\nfn no_multiple_set_timeouts_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not call `jest.setTimeout` multiple times\")\n        .with_help(\"Only the last call to `jest.setTimeout` will have an effect.\")\n        .with_label(span)\n}\n\nfn no_unorder_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`jest.setTimeout` should be placed before any other jest methods.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoConfusingSetTimeout;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow confusing usages of `jest.setTimeout`.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs#L2-L38","documentation":"This is the 'called multiple times' branch of oxlint's 'jest/no-confusing-set-timeout' rule. It reports a jest.setTimeout call when an earlier jest.setTimeout call already appeared in the file. Because only the last call takes effect, earlier calls are dead configuration that silently misleads readers about the active timeout.","triggerScenarios":"Enable the rule and lint a file containing two or more jest.setTimeout(...) calls at any scope; every call except the first (as tracked via a NodeId set during traversal) gets this diagnostic, with help text 'Only the last call ... will have an effect.'","commonSituations":"Copy-pasted test files merge setup blocks, or a shared setup file and a local file both set timeouts. During migration to testTimeout in jest.config.js teams often leave the old setTimeout calls behind, producing duplicates.","solutions":["Delete all but one jest.setTimeout call, keeping the single intended value at module scope.","Prefer config: set testTimeout in jest.config.js (or jest.config.ts) and remove all per-file setTimeout calls.","If different files need different timeouts, keep exactly one top-level call per file with the right value.","Suppress intentional duplicates with an inline oxlint-disable-next-line comment."],"exampleFix":"// before\njest.setTimeout(5000);\njest.setTimeout(30000);\n\n// after\njest.setTimeout(30000);\n\n// or in jest.config.js\nmodule.exports = { testTimeout: 30000 };","handlingStrategy":"validation","validationCode":"// count jest.setTimeout occurrences per file; >1 will be flagged\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -c 'jest\\\\.setTimeout' tests/ | awk -F: '$2 > 1'\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one jest.setTimeout per file, at the top.","After merging test files or setup blocks, re-grep for duplicate setTimeout calls.","Migrate timeouts to jest.config.js testTimeout to make duplication impossible."],"tags":["lint","jest","testing","timers","duplicate-code","oxlint"],"backgroundTag":"jest-settimeout-misuse","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"}