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..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 @@ -10,7 +10,10 @@ 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_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) } #[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..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 @@ -7,57 +7,77 @@ 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 (`!`). + 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] 1 │ const foo: { bar: number } | null = null; const bar = foo!!!.bar; · ▲ ╰──── + 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] 1 │ const foo: { bar: number } | null = null; const bar = foo!!.bar; · ▲ ╰──── + 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] 1 │ function foo(bar: number | undefined) { const a: number = bar!!; } · ▲ ╰──── + 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] 1 │ function foo(bar?: { n: number }) { return bar!?.n; } · ▲ ╰──── + 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] 1 │ function foo(bar?: { n: number }) { return bar!?.(); } · ▲ ╰──── + 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] 1 │ const foo: { bar: number } | null = null; const bar = (foo!)!.bar; · ▲ ╰──── + 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] 1 │ function foo(bar?: { n: number }) { return (bar!)?.n; } · ▲ ╰──── + 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] 1 │ function foo(bar?: { n: number }) { return (bar)!?.n; } · ▲ ╰──── + 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] 1 │ function foo(bar?: { n: number }) { return (bar!)?.(); } · ▲ ╰──── + 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.