{"record":{"id":"ed81c95bbb240018","repo":"oxc-project/oxc","slug":"enforce-test-and-it-usage-conventions","errorCode":null,"errorMessage":"Enforce `test` and `it` usage conventions","messagePattern":"Enforce `test` and `it` usage conventions","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/consistent_test_it.rs","lineNumber":19,"sourceCode":"use std::borrow::Cow;\n\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, PossibleJestNode,\n        collect_possible_jest_call_node, parse_jest_fn_call,\n    },\n};\n\nfn consistent_method(preferred_method: &str, other_method: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Enforce `test` and `it` usage conventions\")\n        .with_help(format!(\"Prefer using {preferred_method:?} instead of {other_method:?}\"))\n        .with_label(span)\n}\n\nfn consistent_method_within_describe(\n    preferred_method: &str,\n    other_method: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Enforce `test` and `it` usage conventions\")\n        .with_help(format!(\n            \"Prefer using {preferred_method:?} instead of {other_method:?} within describe\"\n        ))\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, JsonSchema, Serialize)]\n#[serde(rename_all = \"lowercase\")]","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/consistent_test_it.rs#L1-L37","documentation":"Diagnostic from oxlint's shared jest/vitest consistent-test-it rule (port of jest/consistent-test-it). It enforces one keyword for test cases: by default `fn` is `test` at the top level and `withinDescribe` is `it` inside describe blocks. The check is string-based: a reported call's parsed jest name must end with the preferred keyword, otherwise this diagnostic (with a 'Prefer using X instead of Y' help) fires and an autofix rewrites the callee.","triggerScenarios":"`parse_jest_fn_call` resolves the call as a General jest test call, then: top-level `it('x')` / `it.only('x')` with default fn=test reports 'Prefer using \"test\" instead of \"it\"'; `test('x')` inside `describe(...)` with default withinDescribe=it reports the within-describe variant. Config `{ \"fn\": \"it\" }` flips it, and if withinDescribe is omitted it inherits fn. The fixer also maps `fit` → `test.only` and x-/f-prefixed names accordingly.","commonSituations":"Mixed-style suites after merging teams or copy-pasting examples; enforcing `it` inside describe (BDD style) while keeping `test` at the top; CI lint failures after enabling the jest plugin category where the rule is on by default.","solutions":["Apply the provided autofix (rewrites `it(` → `test(` or `test(` → `it(` per scope).","Standardize the suite with a codemod or search-replace, then let the rule keep it consistent.","If your team prefers the other keyword, configure it: `\"jest/consistent-test-it\": [\"error\", { \"fn\": \"it\", \"withinDescribe\": \"it\" }]`.","Disable the rule if mixed usage is acceptable in your repo."],"exampleFix":"// before (defaults: fn=test, withinDescribe=it)\nit('works at top level');\ndescribe('unit', () => {\n  test('works inside describe');\n});\n\n// after\ntest('works at top level');\ndescribe('unit', () => {\n  it('works inside describe');\n});","handlingStrategy":"validation","validationCode":"oxlint --jest-plugin test/ # consistent-test-it with optional config:\n# { \"fn\": \"it\", \"withinDescribe\": \"it\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one keyword convention, encode it in the rule config once, and let the autofix enforce it.","Remember the oxlint defaults: `test` at top level, `it` inside describe.","Setting `fn` alone makes withinDescribe inherit it — configure both only if you want the split style."],"tags":["jest","vitest","style","consistency","oxlint","lint"],"backgroundTag":"jest-test-it-consistency","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"}