{"record":{"id":"26f58b2fd6c3061f","repo":"oxc-project/oxc","slug":"use-of-method-name-is-not-allowed","errorCode":null,"errorMessage":"Use of `{method_name}` is not allowed","messagePattern":"Use of `(.+?)` is not allowed","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_jest_methods.rs","lineNumber":19,"sourceCode":"use crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, PossibleJestNode, is_type_of_jest_fn_call,\n        object_with_nullable_string_schema,\n    },\n};\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\nuse rustc_hash::FxHashMap;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::rule::DefaultRuleConfig;\n\nfn restricted_jest_method(method_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use of `{method_name}` is not allowed\")).with_label(span)\n}\n\nfn restricted_jest_method_with_message(message: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message.to_string()).with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nRestrict the use of specific `jest` and `vi` methods.\n\n### Why is this bad?\n\nCertain Jest or Vitest methods may be deprecated, discouraged in specific\ncontexts, or incompatible with your testing environment. Restricting\nthem helps maintain consistent and reliable test practices.\n\nBy default, no methods are restricted by this rule.\nYou must configure the rule for it to disable anything.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_jest_methods.rs#L1-L37","documentation":"Diagnostic from oxlint rule `jest/no-restricted-jest-methods` (shared with vitest), the restricted_jest_method constructor at crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_jest_methods.rs:19. It lets a team configure a deny-list of `jest.*` / `vi.*` methods; when a restricted method with no custom message is called, the rule reports `Use of \\`method\\` is not allowed` on the call span.","triggerScenarios":"The rule's config maps object names (jest, vi) to restricted method names (optionally with a custom message, handled by restricted_jest_method_with_message). Calling any configured method without a custom message, e.g. jest.setTimeout or vi.useFakeTimers when listed, produces this exact diagnostic.","commonSituations":"Teams banning jest.mock in favor of dependency injection; banning vi.useFakeTimers because of flaky timers; deprecated or dangerous methods (jest.resetModules) disabled repo-wide; new team members unaware of the local convention.","solutions":["Stop using the restricted method and apply the team's sanctioned alternative (e.g. DI instead of jest.spyOn)","If the restriction does not apply to this call site, ask the owners to remove or scope the entry in .oxlintrc.json","If a legitimate exception exists, disable the rule inline with an oxlint-disable comment including a justification"],"exampleFix":"// before (config restricts vi.useFakeTimers)\nvi.useFakeTimers();\n\n// after\nvi.advanceTimersByTime(0); // or use real timers per team convention","handlingStrategy":"validation","validationCode":"npx oxlint -c .oxlintrc.json tests/ # no-restricted-jest-methods applies the configured jest/vi deny-list","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the deny-list in .oxlintrc.json reviewed each quarter; prune entries whose rationale expired","Add a custom message to each entry so diagnostics teach the alternative","Introduce restrictions gradually with warnings first, then promote to errors"],"tags":["jest","vitest","oxlint","testing","config","restricted-api","lint"],"backgroundTag":"restricted-method-usage","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"}