{"record":{"id":"6cde6f7855170181","repo":"oxc-project/oxc","slug":"use-of-chain-call-is-disallowed","errorCode":null,"errorMessage":"Use of `{chain_call}` is disallowed","messagePattern":"Use of `(.+?)` is disallowed","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_matchers.rs","lineNumber":21,"sourceCode":"use 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::{\n    context::LintContext,\n    rule::DefaultRuleConfig,\n    utils::{\n        JestFnKind, KnownMemberExpressionProperty, PossibleJestNode, is_type_of_jest_fn_call,\n        object_with_nullable_string_schema, parse_expect_jest_fn_call,\n    },\n};\n\nfn restricted_chain(chain_call: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use of `{chain_call}` is disallowed\")).with_label(span)\n}\n\nfn restricted_chain_with_message(chain_call: &str, message: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use of `{chain_call}` is disallowed\"))\n        .with_help(message.to_string())\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r#\"### What it does\n\nBan specific matchers & modifiers from being used, and can suggest alternatives.\n\n### Why is this bad?\n\nSome matchers or modifiers might be discouraged in your codebase for various reasons:\nthey might be deprecated, cause confusion, have performance implications, or there\nmight be better alternatives available. This rule allows you to enforce consistent\ntesting patterns by restricting certain Jest matchers and providing guidance on","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_matchers.rs#L3-L39","documentation":"Diagnostic from oxlint rule `jest/no-restricted-matchers` (shared with vitest), the restricted_chain constructor at crates/oxc_linter/src/rules/shared/jest_vitest/no_restricted_matchers.rs:21. Matchers and modifiers can be deny-listed by chain pattern (e.g. 'not', 'resolves', 'toBeTruthy'); this variant fires for a configured pattern that carries no custom message, reporting `Use of \\`chain\\` is disallowed` on the matcher span.","triggerScenarios":"A configured chain pattern (keys of the rule's map, including modifiers like `not` and full chains like `not.toBe`) is matched against the members of an expect() call parsed via parse_expect_jest_fn_call. When the entry has no message (e.g. { \"toBeTruthy\": null }), restricted_chain reports the joined chain text.","commonSituations":"Teams banning vague matchers like toBeTruthy/toBeFalsy in favor of toBe(true); banning `not` negations for readability; restricting toBeNull vs toBeUndefined confusion; enabling the rule on code that predates the convention.","solutions":["Replace the banned matcher with the specific alternative your team prefers, e.g. expect(x).toBe(true) instead of toBeTruthy()","Rewrite negations: expect(x).toBe(false) instead of expect(x).not.toBeTruthy()","Adjust the deny-list in .oxlintrc.json if the pattern is too broad for your codebase"],"exampleFix":"// before (config: { \"toBeTruthy\": null })\nexpect(user.isActive()).toBeTruthy();\n\n// after\nexpect(user.isActive()).toBe(true);","handlingStrategy":"validation","validationCode":"npx oxlint -c .oxlintrc.json tests/ # no-restricted-matchers applies the configured matcher deny-list","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to precise matchers (toBe(true), toHaveLength) so vague ones never enter the code","Scope deny-list patterns narrowly (full chains like 'not.toBe') to avoid over-blocking","Document each restricted pattern next to the config entry"],"tags":["jest","vitest","oxlint","testing","matchers","config","restricted-api"],"backgroundTag":"restricted-matcher-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"}