{"record":{"id":"e255758a1eb1604a","repo":"oxc-project/oxc","slug":"deprecated-has-been-deprecated-in-favor-of-ne","errorCode":null,"errorMessage":"{deprecated:?} has been deprecated in favor of {new:?}","messagePattern":"(.+?) has been deprecated in favor of (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs","lineNumber":11,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn deprecated_function(deprecated: &str, new: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"{deprecated:?} has been deprecated in favor of {new:?}\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, Deserialize, JsonSchema)]\n#[serde(default, deny_unknown_fields)]\npub struct JestConfig {\n    /// The version of Jest being used.\n    version: usize,\n}\n\nimpl Default for JestConfig {\n    fn default() -> Self {\n        Self { version: 29 }\n    }\n}\n\n#[derive(Debug, Deserialize, JsonSchema)]\n#[serde(default, deny_unknown_fields)]","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs#L1-L29","documentation":"This is oxlint's 'jest/no-deprecated-functions' diagnostic. It maps statically-known member accesses onto a deprecation table (jest.resetModuleRegistry→jest.resetModules since Jest 15, jest.addMatchers→expect.extend since 17, require.requireMock/requireActual→jest.* since 21, jest.runTimersToTime→jest.advanceTimersByTime since 22, jest.genMockFromModule→jest.createMockFromModule since 26) and reports usages when your configured Jest version is at or above the deprecation version. The rule carries an autofix that rewrites the member expression to its replacement. Version comes from settings.jest.version or the rule's jest.version option, defaulting to 29.","triggerScenarios":"Enable the rule (default Jest version 29) and lint code containing a static or computed member expression on the identifiers jest or require whose property matches the deprecation map, e.g. jest.genMockFromModule('./x'). Because 29 >= 26, the diagnostic fires and the fixer replaces the span with the new name.","commonSituations":"Codebases upgraded across Jest majors keep old API calls that still work but are slated for removal (genMockFromModule is removed in Jest 30). A wrong jest version setting — e.g. settings.jest.version left at an old value — either hides real deprecations or, when defaulted to 29, flags calls that were fine on the project's actual old Jest.","solutions":["Apply the provided autofix (oxlint --fix) or manually replace the deprecated call, e.g. jest.genMockFromModule(m) → jest.createMockFromModule(m).","Set your real Jest major in .oxlintrc.json under settings.jest.version (e.g. \"settings\": { \"jest\": { \"version\": \"27\" } }) so only genuinely deprecated APIs for your version are flagged.","If you must keep a deprecated call temporarily, suppress it with // oxlint-disable-next-line jest/no-deprecated-functions.","After Jest upgrades, re-run the rule to catch newly deprecated functions."],"exampleFix":"// before\nconst mock = jest.genMockFromModule('./db');\nconst actual = require.requireActual('./db');\n\n// after\nconst mock = jest.createMockFromModule('./db');\nconst actual = jest.requireActual('./db');","handlingStrategy":"validation","validationCode":"// detect deprecated Jest APIs before linting\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -n 'jest\\\\.(resetModuleRegistry|addMatchers|runTimersToTime|genMockFromModule)|require\\\\.(requireMock|requireActual)' tests/\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set settings.jest.version in .oxlintrc.json to the project's actual Jest major.","Run oxlint --fix after each Jest upgrade to rewrite newly deprecated calls.","Check Jest release notes for removals (genMockFromModule is removed in Jest 30) before upgrading."],"tags":["lint","jest","deprecated-api","testing","oxlint","autofix"],"backgroundTag":"deprecated-jest-api","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"}