oxc-project/oxc · warning · OxcDiagnostic
Use of `{method_name}` is not allowed
Error message
Use of `{method_name}` is not allowed What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_jest_methods.rs:19
use crate::{
context::LintContext,
utils::{
JestFnKind, JestGeneralFnKind, PossibleJestNode, is_type_of_jest_fn_call,
object_with_nullable_string_schema,
},
};
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::Span;
use oxc_str::CompactStr;
use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::rule::DefaultRuleConfig;
fn restricted_jest_method(method_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Use of `{method_name}` is not allowed")).with_label(span)
}
fn restricted_jest_method_with_message(message: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(message.to_string()).with_label(span)
}
pub const DOCUMENTATION: &str = r"### What it does
Restrict the use of specific `jest` and `vi` methods.
### Why is this bad?
Certain Jest or Vitest methods may be deprecated, discouraged in specific
contexts, or incompatible with your testing environment. Restricting
them helps maintain consistent and reliable test practices.
By default, no methods are restricted by this rule.
You must configure the rule for it to disable anything.View on GitHub (pinned to e1e7af627c)
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
Example fix
// before (config restricts vi.useFakeTimers) vi.useFakeTimers(); // after vi.advanceTimersByTime(0); // or use real timers per team convention
Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -c .oxlintrc.json tests/ # no-restricted-jest-methods applies the configured jest/vi deny-list
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Use of `{chain_call}` is disallowed
- Require a message for {matcher_name:?}.
- Snapshot is too long.
- {word} is not allowed in test title
- {un_prefixed_name} should match {raw_pattern}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/26f58b2fd6c3061f.
Report an issue: GitHub.