{"record":{"id":"b805f1ae8dd2e4fd","repo":"oxc-project/oxc","slug":"unexpected-alias-name","errorCode":null,"errorMessage":"Unexpected alias {name:?}","messagePattern":"Unexpected alias (.+?)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_alias_methods.rs","lineNumber":11,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn no_alias_methods_diagnostic(name: &str, canonical_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected alias {name:?}\"))\n        .with_help(format!(\"Replace {name:?} with its canonical name of {canonical_name:?}\"))\n        .with_label(span)\n}\n\npub fn run_on_jest_node<'a, 'c>(jest_node: &PossibleJestNode<'a, 'c>, ctx: &'c LintContext<'a>) {\n    let node = jest_node.node;\n    let AstKind::CallExpression(call_expr) = node.kind() else {\n        return;\n    };\n    let Some(jest_fn_call) = parse_expect_jest_fn_call(call_expr, jest_node, ctx) else {\n        return;\n    };\n    let Some(matcher) = jest_fn_call.matcher() else {\n        return;\n    };\n    let Some(alias) = matcher.name() else {\n        return;\n    };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_alias_methods.rs#L1-L29","documentation":"Diagnostic from the oxlint rule `jest/no-alias-methods` (shared with vitest) in crates/oxc_linter/src/rules/shared/jest_vitest/no_alias_methods.rs:11. Jest matchers have legacy alias spellings (toBeCalled, lastCalledWith, toThrowError, ...) and canonical spellings (toHaveBeenCalled, toHaveBeenLastCalledWith, toThrow). The rule flags the alias on any expect() matcher chain and offers an automatic fix that replaces the alias with its canonical name.","triggerScenarios":"Any expect(...) chain ending in one of the eleven aliases enumerated in BadAliasMethodName: toBeCalled, toBeCalledTimes, toBeCalledWith, lastCalledWith, nthCalledWith, toReturn, toReturnTimes, toReturnWith, lastReturnedWith, nthReturnedWith, toThrowError (including quoted matchers like expect(x)['toBeCalled'](), where only the name inside the quotes is replaced).","commonSituations":"Codebases mixing old Jest docs/examples with new ones; copy-paste from older tutorials; style divergence across a team where half use aliases; enabling the jest plugin in oxlint on an existing repo for the first time.","solutions":["Apply the built-in autofix: run `npx oxlint --fix` and every alias matcher is replaced with its canonical name","Manually rename using the mapping in the help text, e.g. toBeCalledWith -> toHaveBeenCalledWith, lastCalledWith -> toHaveBeenLastCalledWith, toThrowError -> toThrow","Standardize on canonical matchers in review checklists / editor snippets so aliases stop entering the codebase"],"exampleFix":"// before\nexpect(fn).toBeCalled();\nexpect(fn).lastCalledWith(1, 2);\nexpect(fn).toThrowError('boom');\n\n// after\nexpect(fn).toHaveBeenCalled();\nexpect(fn).toHaveBeenLastCalledWith(1, 2);\nexpect(fn).toThrow('boom');","handlingStrategy":"validation","validationCode":"rg -n \"\\.(toBeCalled|toBeCalledTimes|toBeCalledWith|lastCalledWith|nthCalledWith|toReturn|toReturnTimes|toReturnWith|lastReturnedWith|nthReturnedWith|toThrowError)\\(\" tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `npx oxlint --fix` in CI or pre-commit; the rule ships an automatic rename fix","Configure editor snippets to insert canonical matchers only","Code-review ban on alias matchers so both spellings never coexist"],"tags":["jest","vitest","oxlint","testing","matchers","alias","autofix"],"backgroundTag":"deprecated-alias-method","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"}