From efc633dfcb9b7ee319555ddd6040803e6f760197 Mon Sep 17 00:00:00 2001 From: Daniel Osmond Date: Thu, 26 Feb 2026 08:11:38 -0700 Subject: [PATCH 1/2] fix(linter/no-extra-non-null-assertion): add help messages to missing diagnostics Made-with: Cursor --- .../rules/typescript/no_extra_non_null_assertion.rs | 4 +++- .../typescript_no_extra_non_null_assertion.snap | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs b/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs index 58e965a4b30e6..18496dee7024a 100644 --- a/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs +++ b/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs @@ -10,7 +10,9 @@ use crate::{ }; fn no_extra_non_null_assertion_diagnostic(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("extra non-null assertion").with_label(span) + OxcDiagnostic::warn("extra non-null assertion") + .with_help("Remove the redundant non-null assertion operator (`!`).") + .with_label(span) } #[derive(Debug, Default, Clone)] diff --git a/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap b/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap index dea232b8de272..fb08c5471b48a 100644 --- a/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap +++ b/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap @@ -7,57 +7,67 @@ source: crates/oxc_linter/src/tester.rs 1 │ const foo: { bar: number } | null = null; const bar = foo!!!.bar; · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:58] 1 │ const foo: { bar: number } | null = null; const bar = foo!!!.bar; · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:58] 1 │ const foo: { bar: number } | null = null; const bar = foo!!.bar; · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:62] 1 │ function foo(bar: number | undefined) { const a: number = bar!!; } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:47] 1 │ function foo(bar?: { n: number }) { return bar!?.n; } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:47] 1 │ function foo(bar?: { n: number }) { return bar!?.(); } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:59] 1 │ const foo: { bar: number } | null = null; const bar = (foo!)!.bar; · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:48] 1 │ function foo(bar?: { n: number }) { return (bar!)?.n; } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:49] 1 │ function foo(bar?: { n: number }) { return (bar)!?.n; } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:48] 1 │ function foo(bar?: { n: number }) { return (bar!)?.(); } · ▲ ╰──── + help: Remove the redundant non-null assertion operator (`!`). From 66c71bb3a9b33c00f66d05bbfef3669909475daa Mon Sep 17 00:00:00 2001 From: Cameron Clark Date: Thu, 26 Feb 2026 16:14:07 +0000 Subject: [PATCH 2/2] add note --- .../rules/typescript/no_extra_non_null_assertion.rs | 1 + .../typescript_no_extra_non_null_assertion.snap | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs b/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs index 18496dee7024a..e8888386a74e4 100644 --- a/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs +++ b/crates/oxc_linter/src/rules/typescript/no_extra_non_null_assertion.rs @@ -12,6 +12,7 @@ use crate::{ fn no_extra_non_null_assertion_diagnostic(span: Span) -> OxcDiagnostic { OxcDiagnostic::warn("extra non-null assertion") .with_help("Remove the redundant non-null assertion operator (`!`).") + .with_note("The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant.") .with_label(span) } diff --git a/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap b/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap index fb08c5471b48a..20fceb566312c 100644 --- a/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap +++ b/crates/oxc_linter/src/snapshots/typescript_no_extra_non_null_assertion.snap @@ -8,6 +8,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:58] @@ -15,6 +16,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:58] @@ -22,6 +24,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:62] @@ -29,6 +32,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:47] @@ -36,6 +40,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:47] @@ -43,6 +48,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:59] @@ -50,6 +56,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:48] @@ -57,6 +64,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:49] @@ -64,6 +72,7 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant. ⚠ typescript-eslint(no-extra-non-null-assertion): extra non-null assertion ╭─[no_extra_non_null_assertion.tsx:1:48] @@ -71,3 +80,4 @@ source: crates/oxc_linter/src/tester.rs · ▲ ╰──── help: Remove the redundant non-null assertion operator (`!`). + note: The non-null assertion operator in TypeScript, written as `!`, tells the compiler that an expression is definitely not `null` or `undefined` at that point. Chaining multiple non-null assertions on the same expression does not provide any additional safety and is redundant.