-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
tools: auto fix custom eslint rule for lowercase-name-for-primitive.js #17715
tools: auto fix custom eslint rule for lowercase-name-for-primitive.js #17715
Conversation
Hey @apapirovski @BridgeAR . |
8654800
to
594ae58
Compare
@@ -35,9 +35,20 @@ module.exports = function(context) { | |||
function checkName(node, name) { | |||
const lowercaseName = name.toLowerCase(); | |||
if (primitives.includes(lowercaseName) && !primitives.includes(name)) { | |||
console.log(lowercaseName); |
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.
Please remove the console.log()
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.
Yeah forgot it was there! Removed 👍🏻.
594ae58
to
ece39e7
Compare
Do we usually have tests for fixer functions? /cc @not-an-aardvark |
@Trott not afaik. |
@shobhitchittora Looks good to me. Thanks for the pull request! |
1. Fixer for lowercase-name-for-primitive.js 2. Modified the node passed to fix it. Refs : nodejs#16636
ece39e7
to
a389548
Compare
Hi @shobhitchittora ! Thank you for working on this! Could you expand the test in Here is an example to see how it works: |
Happy to approve again after @strakwang's requested test is implemented.
1. Extends test cases with output scenarios. Refs : nodejs#16636
@starkwang Thanks for the heads up. |
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.
Seems good but a bit of clean up would be nice.
names.elements.forEach((name) => { | ||
checkName(node, name.value); | ||
names.elements.forEach((name, index) => { | ||
checkName(names.elements[index], name.value); |
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.
Couldn't this just be name
instead of names.elements[index]
? Pretty sure we can also get rid of the second argument here and above.
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.
👍🏻
@@ -36,8 +36,18 @@ module.exports = function(context) { | |||
const lowercaseName = name.toLowerCase(); | |||
if (primitives.includes(lowercaseName) && !primitives.includes(name)) { |
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.
name
could just be replaced with node.value
now.
Also, pretty sure !primitives.includes(name)
could be simplified to name !== lowercaseName
(and it could be put as the first condition so the includes
only runs if necessary).
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.
Made the changes.
1. Changes as per review comments. Refs : nodejs#16636
@@ -23,19 +23,23 @@ new RuleTester().run('lowercase-name-for-primitive', rule, { | |||
invalid: [ | |||
{ | |||
code: 'new errors.TypeError("ERR_INVALID_ARG_TYPE", "a", "Number")', | |||
errors: [{ message: 'primitive should use lowercase: Number' }] | |||
errors: [{ message: 'primitive should use lowercase: Number' }], | |||
output: 'new errors.TypeError("ERR_INVALID_ARG_TYPE", "a", "number")' |
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.
CI failed due to a small problem:
The input code and expected output are using double quotes "
, but the autofixer will change it to single quotes, which makes the actual output cannot match the expected output.
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.
@shobhitchittora Could you change these double quotes in code
and output
to using single quotes?
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.
@starkwang pushed a fix. How did you check the problem in Jenkins that the output is not correct?
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.
I modified some codes in eslint (eslint/lib/testers/rule-tester.js) to expose the error message.
You can see eslint/eslint#9769 for more detail. 😉
I also send a PR to eslint for more detailed assert message: eslint/eslint#9769 |
1. Fixed test with proper quotes. Refs : nodejs#16636
The CI failed again:
|
code: 'new errors.TypeError("ERR_INVALID_ARG_TYPE", "a", "Number")', | ||
errors: [{ message: 'primitive should use lowercase: Number' }] | ||
code: `new errors.TypeError('ERR_INVALID_ARG_TYPE', 'a', | ||
'Number')`, |
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.
@shobhitchittora Could you change these backquote to singlequote? For example:
{
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'\'Number\''
}
In addition, you can use this command to check if your change will pass CI:
node test/parallel/test-eslint-lowercase-name-for-primitive.js
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.
Done and started a build.
1. Removes template string 2. Uses escaped quote. Refs : nodejs#16636
Landed in 639770c 💯 🥇 |
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
PR-URL: #17715 Refs: #16636 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Weijia Wang <[email protected]>
Refs: #16636
Checklist
Affected core subsystem(s)
Tools