{"record":{"id":"f52af5a1ef54aa30","repo":"oxc-project/oxc","slug":"confusing-combinations-of-non-null-assertion-and-e","errorCode":null,"errorMessage":"Confusing combinations of non-null assertion and equal test like `a! {op_str} b`, which looks very similar to not equal `a !{op_str} b`.","messagePattern":"Confusing combinations of non-null assertion and equal test like `a! (.+?) b`, which looks very similar to not equal `a !(.+?) b`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_confusing_non_null_assertion.rs","lineNumber":58,"sourceCode":"    ///    a! instanceof b;\n    /// ```\n    ///\n    /// Examples of **correct** code for this rule:\n    /// ```ts\n    /// a == b;\n    /// a !== b;\n    /// a === b;\n    /// ```\n    NoConfusingNonNullAssertion,\n    typescript,\n    suspicious,\n    suggestion,\n    version = \"0.6.1\",\n    short_description = \"Disallow non-null assertion in locations that may be confusing.\",\n);\n\nfn not_need_no_confusing_non_null_assertion_diagnostic(op_str: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        r\"Confusing combinations of non-null assertion and equal test like `a! {op_str} b`, which looks very similar to not equal `a !{op_str} b`.\"\n    ))\n    .with_help(r\"Remove the `!`, or prefix the `=` with it.\")\n    .with_label(span)\n}\n\nfn wrap_up_no_confusing_non_null_assertion_diagnostic(op_str: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        r\"Confusing combinations of non-null assertion and equal test like `a! {op_str} b`, which looks very similar to not equal `a !{op_str} b`.\"\n    ))\n    .with_help(\n        r\"Wrap left-hand side in parentheses to avoid putting non-null assertion `!` and `=` together.\",\n    )\n    .with_label(span)\n}\n\nfn confusing_non_null_assignment_assertion_diagnostic(op_str: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/oxc-project/oxc/blob/36ec0ef2bae567d1a8413ada2fe795f1af1f2785/crates/oxc_linter/src/rules/typescript/no_confusing_non_null_assertion.rs#L40-L76","documentation":"typescript/no-confusing-non-null-assertion flags binary expressions with ==, ===, !=, !== whose left side ends in a non-null assertion `!`. When the expression ends directly in `!` at depth 0 (e.g. `a! === b`), this variant is emitted because the text looks like the negated comparison `a !== b` / `a != b` with one stray space.","triggerScenarios":"`a! == b`, `a! === b`, `a! != b`, `a! !== b` where the LHS is a plain TSNonNullExpression (bang_depth == 0 in get_depth_ends_in_bang); also `a!.b! === c` style chains ending in `!`.","commonSituations":"Developers intending `a !== b` but typing `a! == b` or vice versa; optional-heavy code where `!` assertions are habitual; typos that are syntactically valid and silently change meaning.","solutions":["If you meant the comparison, remove the `!`: `a === b`","If you meant negation, prefix the `=` with the `!`: write `a !== b` instead of `a! == b`","If the assertion is intentional, disambiguate by wrapping: `(a!) === b`"],"exampleFix":"// before (assertion intended)\nif (a! == b) {}\n\n// after\nif (a === b) {} // no assertion needed\n// or, if the assertion is intentional:\nif ((a!) === b) {}","handlingStrategy":"type-guard","validationCode":"// Keep the rule on in CI so visual-confusion comparisons never land:\n// .oxlintrc.json\n{\n  \"rules\": { \"typescript/no-confusing-non-null-assertion\": \"warn\" }\n}","typeGuard":"function isDefined<T>(v: T | null | undefined): v is T {\n  return v !== null && v !== undefined;\n}\n\n// instead of `a! === b`, narrow first\nif (isDefined(a)) {\n  if (a === b) { /* ... */ }\n}","tryCatchPattern":null,"preventionTips":["Prefer nullish checks or default values over `!` before comparisons: `a ?? fallback === b` needs parens too, so keep it simple","Format with spaces consistently (a! vs a !) and read `!` before `=` as assertion, not negation","Enable typescript/no-non-null-assertion in stricter codebases to remove `!` entirely"],"tags":["typescript","lint","non-null-assertion","readability","oxlint"],"backgroundTag":"non-null-assertion-confusion","analyzedSha":"36ec0ef2bae567d1a8413ada2fe795f1af1f2785","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}