{"record":{"id":"b9b468002034c485","repo":"oxc-project/oxc","slug":"avoid-having-conditionals-in-tests","errorCode":null,"errorMessage":"Avoid having conditionals in tests","messagePattern":"Avoid having conditionals in tests","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs","lineNumber":12,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    rule::Rule,\n    utils::{JestFnKind, JestGeneralFnKind, PossibleJestNode, is_type_of_jest_fn_call},\n};\n\nfn no_conditional_tests(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Avoid having conditionals in tests\")\n        .with_help(\"Remove the surrounding if statement.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoConditionalTests;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// The rule disallows the use of conditional statements within test cases to\n    /// ensure that tests are deterministic and clearly readable.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Conditional statements in test cases can make tests unpredictable and\n    /// harder to understand. Tests should be consistent and straightforward to\n    /// ensure reliable results and maintainability.","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs#L1-L30","documentation":"Emitted by the vitest/no-conditional-tests rule at a conditional statement (`if`, ternary, switch, etc.) found inside a `test`/`it` body. Conditional logic in a test usually means some paths are silently skipped, weakening coverage; the rule demands unconditional tests or separate tests per path.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs:12 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the surrounding if statement and always run the assertions","Split the test into separate tests, one per branch","Use `test.skip`/`test.skipIf` instead of runtime conditionals when skipping is intended"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}