{"record":{"id":"1086bfc9003c4542","repo":"oxc-project/oxc","slug":"expect-takes-at-most-argument","errorCode":null,"errorMessage":"Expect takes at most {} argument{} ","messagePattern":"Expect takes at most (.+?) argument(.+?) ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs","lineNumber":23,"sourceCode":"use oxc_semantic::ScopeId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\nuse schemars::JsonSchema;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    utils::{\n        ExpectError, PossibleJestNode, collect_possible_jest_call_node, parse_expect_jest_fn_call,\n    },\n};\n\nfn valid_expect_diagnostic<S: Into<Cow<'static, str>>>(\n    x1: S,\n    x2: &'static str,\n    span3: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nChecks that `expect()` is called correctly.\n\n### Why is this bad?\n\n`expect()` is a function that is used to assert values in tests.\nIt should be called with a single argument, which is the value to be tested.\nIf you call `expect()` with no arguments, or with more than one argument, it will not work as expected.\n\n### Examples\n\nExamples of **incorrect** code for this rule:\n```javascript\nexpect();\nexpect('something');","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs#L5-L41","documentation":"Diagnostic from the shared jest/vitest `valid-expect` rule: the `expect()` call itself was passed more arguments than `maxArgs` allows (default 1, per ValidExpectConfig). Extra arguments are silently ignored by Jest/Vitest, so a custom-message second argument does nothing and signals a mistake.","triggerScenarios":"`(call_expr.arguments.len() as u32) > self.max_args && !allow_message_arg` fires the formatted 'Expect takes at most N argument(s)' message. Concretely: `expect(a, b)`, `expect(a, 'custom message')` when the string-message escape hatch is off, or `maxArgs` lowered in `.oxlintrc.json` while code still passes two values.","commonSituations":"Developers porting chai/QUnit habits (message as second argument), or configuring `minArgs`/`maxArgs` for a wrapped expect without updating call sites.","solutions":["Reduce the call to the allowed argument count: `expect(actual)`.","Move the intended custom message into the matcher (`toBe(expected, 'message')` in vitest) or an explicit `ctx.assert`/error message.","If two arguments are intentional, raise `maxArgs` in the rule's config: `{ \"rules\": { \"valid-expect\": [\"error\", { \"maxArgs\": 2 }] } }`."],"exampleFix":"// before\nexpect(result, 'result should be truthy');\n\n// after\nexpect(result).toBeDefined();","handlingStrategy":"validation","validationCode":"// reject multi-argument expect() calls before commit\nconst multi = /\\bexpect\\s*\\([^(),]+\\s*,/; // crude: expect(x, ...)\nif (multi.test(src)) { console.error('expect() called with more than one argument'); process.exitCode = 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember jest/vitest `expect` takes exactly one value; custom messages go on the matcher, not expect.","If you wrap expect, document the intended arity and align `minArgs`/`maxArgs` config with it.","Code-review any `expect(a, b)` shape on sight — it is almost always a chai habit leak."],"tags":["jest","vitest","oxlint","testing","arguments","valid-expect"],"backgroundTag":"expect-argument-count","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"}