-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
new-for-builtins
: Correct fix for Date()
#2543
Conversation
fisker
commented
Jan 24, 2025
> Error 1/1 | ||
`␊ | ||
> 1 | const foo = Date(/*comment*/);␊ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no fix this to
const foo = String(new Date(/*comment*/));
It should be safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's suggestion, see L1455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misunderstood, we should try not remove comments, and it's hard to fix to your version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct fix seems like
function * fix(fixer) {
yield * fixSpaceAroundKeyword(fixer, node, sourceCode);
yield fixer.insertTextBefore(node, 'String(');
yield fixer.insertTextAfter(node, ')');
yield * switchCallExpressionToNewExpression(node, sourceCode, fixer, /* fixSpaces */ false);
yield * removeArguments();
}
Just not worth the effort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you wonder why switchCallExpressionToNewExpression
is necessary, something like
Array(globalThis)[0].Date(/*comment*/);
is not easy to fix correctly, but switchCallExpressionToNewExpression
already considered this.