Uh oh!
There was an error while loading. Please reload this page.
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#17715shobhitchittora wants to merge 5 commits into
Conversation
shobhitchittora
commented
Dec 17, 2017
Hey @apapirovski@BridgeAR . |
8654800 to
594ae58CompareThere was a problem hiding this comment.
Please remove the console.log()
There was a problem hiding this comment.
Yeah forgot it was there! Removed 👍🏻.
594ae58 to
ece39e7CompareTrott
commented
Dec 17, 2017
Do we usually have tests for fixer functions? /cc @not-an-aardvark |
shobhitchittora
commented
Dec 17, 2017
@Trott not afaik. |
Trott
commented
Dec 17, 2017
@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
a389548CompareHi @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
shobhitchittora
commented
Dec 18, 2017
@starkwang Thanks for the heads up. |
apapirovski
left a comment
There was a problem hiding this comment.
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.
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.
| @@ -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.
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.
Made the changes.
apapirovski
commented
Dec 18, 2017
1. Changes as per review comments. Refs : nodejs#16636
apapirovski
commented
Dec 24, 2017
| 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.
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.
@shobhitchittora Could you change these double quotes in code and output to using single quotes?
There was a problem hiding this comment.
@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.
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. 😉
starkwang
commented
Dec 25, 2017
I also send a PR to eslint for more detailed assert message: eslint/eslint#9769 |
1. Fixed test with proper quotes. Refs : nodejs#16636
starkwang
commented
Dec 26, 2017
starkwang
commented
Dec 26, 2017
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.
@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.
Done and started a build.
1. Removes template string 2. Uses escaped quote. Refs : nodejs#16636
starkwang
commented
Dec 26, 2017
starkwang
commented
Dec 26, 2017
Landed in 639770c 💯 🥇 |
Refs: #16636
Checklist
Affected core subsystem(s)
Tools