{"record":{"id":"e189647dc15b902f","repo":"oxc-project/oxc","slug":"jest-settimeout-should-be-placed-before-any-othe","errorCode":null,"errorMessage":"`jest.setTimeout` should be placed before any other jest methods.","messagePattern":"`jest\\.setTimeout` should be placed before any other jest methods\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs","lineNumber":26,"sourceCode":"use 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?\n    ///\n    /// - being called anywhere other than in global scope\n    /// - being called multiple times\n    /// - being called after other Jest functions like hooks, `describe`, `test`, or `it`\n    ///\n    ///","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs#L8-L44","documentation":"This is the ordering branch of oxlint's 'jest/no-confusing-set-timeout' rule. It reports a jest.setTimeout call that appears after other jest method calls in the module. Placement matters because Jest reads timeout configuration while evaluating the module, so a late setTimeout may run after some tests or mocks were already registered, making its effect unpredictable.","triggerScenarios":"Enable the rule and lint a file where a jest.setTimeout call node's NodeId is greater than the NodeId of a previously seen different jest.* method call (tracked in an FxHashMap during the run). The diagnostic 'should be placed before any other jest methods' is emitted on the late call.","commonSituations":"Developers append jest.setTimeout at the bottom of a growing setup section, after jest.mock(...) or jest.useFakeTimers() lines. Merging setup files commonly lands the timeout call mid-file. Reviewers rarely notice, but the rule's ordering check does.","solutions":["Move jest.setTimeout(ms) to the very top of the file, above all jest.mock/jest.spyOn/other jest calls.","Better: remove it entirely and set testTimeout in jest.config.js so ordering never matters.","If the call must stay where it is for a deliberate reason, add // oxlint-disable-next-line jest/no-confusing-set-timeout."],"exampleFix":"// before\njest.mock('./db');\njest.setTimeout(30000);\n\n// after\njest.setTimeout(30000);\njest.mock('./db');","handlingStrategy":"validation","validationCode":"// flag files where jest.setTimeout appears after another jest.* call line\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -n 'jest\\\\.' tests/ | awk -F: '$0 !~ /setTimeout/ {seen[FILENAME]=1} seen[FILENAME] && /setTimeout/'\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place jest.setTimeout as the first statement of the test file, above jest.mock calls.","Use jest.config.js for timeout settings so ordering constraints disappear.","When adding new jest.* setup calls, insert them below an existing top-of-file setTimeout."],"tags":["lint","jest","testing","timers","ordering","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"}