diff --git a/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs b/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs index 922fba7d5e7e4..9e6428fd27801 100644 --- a/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs +++ b/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs @@ -9,8 +9,13 @@ use oxc_span::Span; use crate::{AstNode, context::LintContext, rule::Rule}; -fn no_wrapper_object_types(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("Do not use wrapper object types.").with_label(span) +fn no_wrapper_object_types(ident_name: &str, span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn("Do not use wrapper object types.") + .with_note(format!( + "`{ident_name}` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `{}` for values, and in `extends`/`implements` use an interface/object shape instead.", + ident_name.cow_to_ascii_lowercase() + )) + .with_label(span) } #[derive(Debug, Default, Clone)] @@ -90,11 +95,11 @@ impl Rule for NoWrapperObjectTypes { let can_fix = matches!(node.kind(), AstKind::TSTypeReference(_)); if can_fix { - ctx.diagnostic_with_fix(no_wrapper_object_types(ident_span), |fixer| { + ctx.diagnostic_with_fix(no_wrapper_object_types(ident_name, ident_span), |fixer| { fixer.replace(ident_span, ident_name.cow_to_ascii_lowercase().to_string()) }); } else { - ctx.diagnostic(no_wrapper_object_types(ident_span)); + ctx.diagnostic(no_wrapper_object_types(ident_name, ident_span)); } } } diff --git a/crates/oxc_linter/src/snapshots/typescript_no_wrapper_object_types.snap b/crates/oxc_linter/src/snapshots/typescript_no_wrapper_object_types.snap index fb51ea5618cd8..d3ece4c44d14a 100644 --- a/crates/oxc_linter/src/snapshots/typescript_no_wrapper_object_types.snap +++ b/crates/oxc_linter/src/snapshots/typescript_no_wrapper_object_types.snap @@ -8,6 +8,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `BigInt` with `bigint`. + note: `BigInt` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `bigint` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -15,6 +16,7 @@ source: crates/oxc_linter/src/tester.rs · ─────── ╰──── help: Replace `Boolean` with `boolean`. + note: `Boolean` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `boolean` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -22,6 +24,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -29,6 +32,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Object` with `object`. + note: `Object` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `object` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -36,6 +40,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `String` with `string`. + note: `String` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `string` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -43,6 +48,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Symbol` with `symbol`. + note: `Symbol` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `symbol` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:12] @@ -50,6 +56,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:21] @@ -57,6 +64,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Symbol` with `symbol`. + note: `Symbol` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `symbol` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:24] @@ -64,6 +72,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:6] @@ -71,6 +80,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:15] @@ -78,6 +88,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:16] @@ -85,18 +96,21 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:26] 1 │ class MyClass implements Number {} · ────── ╰──── + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:31] 1 │ interface MyInterface extends Number {} · ────── ╰──── + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:15] @@ -104,6 +118,7 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `Number` with `number`. + note: `Number` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `number` for values, and in `extends`/`implements` use an interface/object shape instead. ⚠ typescript-eslint(no-wrapper-object-types): Do not use wrapper object types. ╭─[no_wrapper_object_types.tsx:1:24] @@ -111,3 +126,4 @@ source: crates/oxc_linter/src/tester.rs · ────── ╰──── help: Replace `String` with `string`. + note: `String` is a boxed object type, not a primitive. Boxed types have object semantics (identity/truthiness) that can be surprising. Use `string` for values, and in `extends`/`implements` use an interface/object shape instead.