eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Rule proposal: `prefer-number-is-safe-integer`

Open fisker opened this issue 7 months ago • 1 comments

Description

I think in all cases use Number.isInteger, Number.isSafeInteger should be preferred.

Examples

// ❌
if (!Number.isInteger(x)) {}

// ✅
if (!Number.isSafeInteger(x)) {}

Additional Info

No response

fisker avatar Apr 09 '25 01:04 fisker

Sounds useful. The only problem I can think of are the checks assuming the inverse case is not an integer.

if (Number.isInteger(x)) {

} else {
	// Assumes this is not an integer.
}

sindresorhus avatar Apr 09 '25 08:04 sindresorhus