Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,106 +8,122 @@ 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]
1 │ let value: Boolean;
· ───────
╰────
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]
1 │ let value: Number;
· ──────
╰────
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]
1 │ let value: Object;
· ──────
╰────
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]
1 │ let value: String;
· ──────
╰────
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]
1 │ let value: Symbol;
· ──────
╰────
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]
1 │ let value: Number | Symbol;
· ──────
╰────
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]
1 │ let value: Number | Symbol;
· ──────
╰────
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]
1 │ let value: { property: Number };
· ──────
╰────
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]
1 │ 0 as Number;
· ──────
╰────
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]
1 │ type MyType = Number;
· ──────
╰────
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]
1 │ type MyType = [Number];
· ──────
╰────
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]
1 │ type MyType = Number & String;
· ──────
╰────
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]
1 │ type MyType = Number & String;
· ──────
╰────
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.
Loading