{"record":{"id":"bc70040098308361","repo":"oxc-project/oxc","slug":"jest-settimeout-should-only-be-called-in-a-globa","errorCode":null,"errorMessage":"`jest.setTimeout` should only be called in a global scope","messagePattern":"`jest\\.setTimeout` should only be called in a global scope","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs","lineNumber":15,"sourceCode":"use oxc_ast::AstKind;\nuse 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!(","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs#L1-L33","documentation":"This is oxlint's 'jest/no-confusing-set-timeout' diagnostic for scope violations. It fires when jest.setTimeout(...) is called anywhere other than the top level of the test file (inside describe, test, beforeAll, hooks, or callbacks). Only the module scope is global; a setTimeout buried in a block looks like it scopes to that block but actually affects the whole file, which misleads readers.","triggerScenarios":"Enable the rule and lint a file where a parsed jest.setTimeout() call node's enclosing function scope is not the program (module) scope — e.g. describe(() => { jest.setTimeout(5000); }). The diagnostic is emitted on the call span.","commonSituations":"Developers try to give one slow describe block a longer timeout by calling jest.setTimeout inside it, not realizing the call is file-global and order-dependent. It also appears when moving setup code into beforeAll hooks or shared setup files.","solutions":["Move the jest.setTimeout(ms) call to the top level of the test file, before any tests.","If only one test needs more time, pass the timeout as the third/fifth argument to it/test instead: test('name', fn, 10000).","If the whole suite needs it, set testTimeout in jest.config.js and remove the per-file call entirely.","Suppress a deliberate case with // oxlint-disable-next-line jest/no-confusing-set-timeout."],"exampleFix":"// before\ndescribe('integration', () => {\n  jest.setTimeout(30000);\n  it('is slow', () => { /* ... */ });\n});\n\n// after\njest.setTimeout(30000);\ndescribe('integration', () => {\n  it('is slow', () => { /* ... */ });\n});","handlingStrategy":"validation","validationCode":"// flag jest.setTimeout calls that are indented (inside blocks)\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -n '^\\\\s+jest\\\\.setTimeout' tests/\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep jest.setTimeout only at column 0 of test files.","Prefer per-test timeout arguments (test('name', fn, 10000)) for localized slowness.","Centralize timeout configuration in jest.config.js testTimeout instead of per-file calls."],"tags":["lint","jest","testing","timers","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-14T05:17:10.506Z"}