-
-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prefer-math-min-max
: Ignore BigInt
#2467
prefer-math-min-max
: Ignore BigInt
#2467
Conversation
Maybe we should only report when there is a number, since strings, |
@axetroy What do you think? |
You mean like this? const isNumber = require("./utils/is-number.js");
// ...
const { sourceCode } = context;
const scope = sourceCode.getScope(conditionalExpression);
const isInvalidExpression = [left, right, alternate, consequent].some(
(node) => !isNumber(node, scope),
);
if (isInvalidExpression) {
return;
} Ensure that everything, be it an Identifier, Literal, or any other expression, is a Number. |
Make sense.
But I think we should only need to determine whether one of the left or right is a number (Identifier/Literal/Expression). And ignore bigInt const isNumber = require("./utils/is-number.js");
// ...
const { sourceCode } = context;
const scope = sourceCode.getScope(conditionalExpression);
const isValidExpression = [left, right].some((node) => isNumber(node, scope));
if (!isValidExpression) {
return;
}
const isBigIntInResult = [alternate, consequent].some((node) => isBigIntLiteral(node)
|| isCallExpression(node, {
name: 'BigInt',
argumentsLength: 1,
optional: false,
}))
if (isBigIntInResult) {
return;
} |
The logic is good, but it makes this rule almost useless.. since it's rare that both left and right matches |
Maybe we can skip this check with
@sindresorhus Not sure what we should do here. |
Not sure I understand. We only need to check if one of the sides is a number, right? |
If we were to do that, it would be better to use TypeScrip as its type inference is much more reliable. |
Just check one of them to make sure it is a comparison of numbers, not strings. |
Yes |
I thought the same, #2467 (comment) Turns out I was wrong
|
That is awful code and not something we should care about. We should be pragmatic. |
This reverts commit 96d8ea3.
prefer-math-min-max
: ignore BigIntprefer-math-min-max
: Ignore BigInt
Close #2465