Skip to content

Conversation

@fisker
Copy link
Collaborator

@fisker fisker commented Jan 22, 2025

It's not safe to fix

new Number instanceof Number
true
typeof new Number === 'number'
false

Sorry that I missed this in #2523, cc @axetroy

@axetroy
Copy link
Contributor

axetroy commented Jan 22, 2025

I reminded it in that PR, I thought you knew, after all, there are very few such cases.

After all, the package @sindresorhus/is is also check with typeof and did not consider the object

https://github.com/sindresorhus/is/blob/e0976457e04ba5df210ca0c976844b580b62f741/source/index.ts#L610-L612

import { isNumber } from '@sindresorhus/is';

isNumber(new Number(123)) // false

@axetroy
Copy link
Contributor

axetroy commented Jan 22, 2025

BTW, All of primitive wrappers did not have a safe fix.

If this is unacceptable, we should change the auto-fix to suggestions

String

// ❌
'abc' instanceof String; // false
typeof 'abc' === 'string'; // true

Number

// ❌
123 instanceof Number; // false
typeof 123 === 'number'; // true

Boolean

// ❌
true instanceof Boolean; // false
typeof true === 'boolean'; // true

BigInt

// ❌
123n instanceof BigInt; // false
typeof 123n === 'bigint'; // true

Symbol

// ❌
Symbol('[[test]]') instanceof Symbol; // false
typeof Symbol('[[test]]') === 'symbol'; // true

@fisker
Copy link
Collaborator Author

fisker commented Jan 22, 2025

All of primitive wrappers did not have a safe fix.

I forgot that 123 instanceof Number; // false

@fisker
Copy link
Collaborator Author

fisker commented Jan 23, 2025

We already have a rule named new-for-builtins, should we rename this rule to no-instanceof-builtins?

@axetroy
Copy link
Contributor

axetroy commented Jan 23, 2025

We already have a rule named new-for-builtins, should we rename this rule to no-instanceof-builtins?

The name seems more consistent

@fisker fisker changed the title no-instanceof-builtin-object: Use suggestion for primitive wrappers no-instanceof-builtin-object: Rename to no-instanceof-builtins and use suggestions for unsafe cases Jan 23, 2025
@sindresorhus
Copy link
Owner

Merge conflict

@fisker fisker merged commit 41548c4 into sindresorhus:main Jan 24, 2025
16 checks passed
@fisker fisker deleted the no-instanceof-builtin-object-suggestion branch January 24, 2025 09:02
timvandermeij added a commit to timvandermeij/pdf.js that referenced this pull request Feb 23, 2025
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v57.0.0
doesn't indicate any breaking changes that should impact us.

However, we do replace the deprecated `no-instanceof-array` rule with
the new `no-instanceof-builtins` rule. Note that the changelog calls
this rule `no-instanceof-builtin-object`, but it got renamed in
sindresorhus/eslint-plugin-unicorn#2537.
nanalucky pushed a commit to nanalucky/pdf.js that referenced this pull request Jul 31, 2025
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v57.0.0
doesn't indicate any breaking changes that should impact us.

However, we do replace the deprecated `no-instanceof-array` rule with
the new `no-instanceof-builtins` rule. Note that the changelog calls
this rule `no-instanceof-builtin-object`, but it got renamed in
sindresorhus/eslint-plugin-unicorn#2537.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants