{"record":{"id":"249755a31db37185","repo":"oxc-project/oxc","slug":"unexpected-void-operator","errorCode":null,"errorMessage":"Unexpected `void` operator","messagePattern":"Unexpected `void` operator","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_void.rs","lineNumber":17,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::UnaryOperator;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::outermost_paren_parent,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_void_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected `void` operator\")\n        .with_help(\"Use `undefined` instead\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoVoid {\n    /// If set to `true`, using `void` as a standalone statement is allowed.\n    pub allow_as_statement: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows the use of the `void` operator.\n    ///\n    /// ### Why is this bad?\n    ///","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_void.rs#L1-L35","documentation":"Diagnostic from the `no-void` rule. The `void` operator evaluates its operand and discards the result, usually to obtain `undefined` or to mark an expression as intentionally unused (e.g. `void promise`). Because `undefined` is a global since ES5, the operator is confusing to readers, so oxlint flags `void expr` with help 'Use `undefined` instead'. The rule config `NoUselessEscape`-style struct exposes `allowAsStatement: bool` to permit `void` used purely as a statement.","triggerScenarios":"`const u = void 0;`, `void someAsyncFn();` as an expression, `() => void doWork()` arrow bodies. Fires on UnaryExpression with operator Void; when `allowAsStatement: true` is configured, statement-position voids are skipped and only expression uses (like `const x = void y`) are reported.","commonSituations":"Minifier-era idioms `void 0` copied into source; React/Angular code marking fire-and-forget promises; TypeScript code using `void` to satisfy no-floating-promises.","solutions":["Replace value uses with `undefined`: `const u = void 0` -> `const u = undefined`.","For discarding promises, configure `\"allowAsStatement\": true` and keep `void fetch(...)` in statement position, or use `.catch` / proper awaiting.","In TypeScript, prefer `await` or explicit `void`-returning helpers over the operator.","Disable the rule if your style guide embraces `void` for fire-and-forget semantics."],"exampleFix":"// before\nconst u = void 0;\n\n// after\nconst u = undefined;","handlingStrategy":"validation","validationCode":"const usesVoidOperator = /(?:^|[^.\\w$])void\\s/.test(sourceLine);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `undefined` instead of `void 0` for values.","If you intentionally discard promises, set `allowAsStatement: true` in config.","In TypeScript, satisfy no-floating-promises with real handling or typed helpers."],"tags":["lint","eslint","oxlint","void-operator","javascript"],"backgroundTag":"no-void-operator","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"}