{"record":{"id":"b7dcf9e36d3d0171","repo":"oxc-project/oxc","slug":"unexpected-return-statement-in-describe-callback","errorCode":null,"errorMessage":"Unexpected return statement in describe callback","messagePattern":"Unexpected return statement in describe callback","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_describe_callback.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression, FunctionBody, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    utils::{JestFnKind, JestGeneralFnKind, PossibleJestNode, parse_general_jest_fn_call},\n};\n\nfn valid_describe_callback_diagnostic(\n    x1: &'static str,\n    x2: &'static str,\n    span3: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)\n}\n\n#[derive(Clone, Copy)]\npub struct ValidDescribeCallbackOptions {\n    allow_async_describe_callback: bool,\n    allow_describe_options_argument: bool,\n}\n\nimpl ValidDescribeCallbackOptions {\n    pub const JEST: Self =\n        Self { allow_async_describe_callback: false, allow_describe_options_argument: false };\n\n    pub const VITEST: Self =\n        Self { allow_async_describe_callback: true, allow_describe_options_argument: true };\n}\n\npub fn run<'a>(\n    possible_jest_node: &PossibleJestNode<'a, '_>,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_describe_callback.rs#L1-L36","documentation":"Diagnostic from the oxlint `jest/valid-describe-callback` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/valid_describe_callback.rs:18). This variant ('Unexpected return statement in describe callback') fires when the describe callback contains a `return` statement. Returning from describe does nothing meaningful and usually signals copy-pasted factory logic; jest similarly rejects it.","triggerScenarios":"`describe('feature', () => { return buildTests(); })` - any `return` statement in the describe callback body, found by walking the callback function for ReturnStatement nodes (source imports GetSpan for reporting the span).","commonSituations":"Converting a helper that builds tests via `return` into a describe body; early-exit logic copied from a test; generated test code that returns config objects.","solutions":["Remove the `return`; call the builder directly: `describe('feature', () => { buildTests(); })`.","If the return value was data for tests, assign it to a `const` inside the describe or compute it in `beforeAll`.","Keep the return inside the inner `test` callbacks, where returning from a test is allowed."],"exampleFix":"// before\ndescribe('routes', () => {\n  return registerRouteTests();\n});\n\n// after\ndescribe('routes', () => {\n  registerRouteTests();\n});","handlingStrategy":"validation","validationCode":"// rg -nU \"describe\\([\\s\\S]{0,200}?\\breturn\\b\" tests/ -t ts -t js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Describe callbacks register tests; they never return - call helper builders directly","Move computed values into const declarations or beforeAll"],"tags":["jest","vitest","oxlint","describe","return-statement"],"backgroundTag":"jest-describe-callback-validation","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}