-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
test: convert var->const/let in tests #10685
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
Conversation
|
cc/ @nodejs/testing cc/ @silverwind @Trott @not-an-aardvark Is there an easy way to make rules only apply to |
Add the rule to |
Thanks, done |
cjihrig
left a 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.
Rubber stamp LGTM if the CI passes.
|
CI: https://ci.nodejs.org/job/node-test-commit/7103/ EDIT: CI passed |
jasnell
left a 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.
Rubber-stamp LGTM
test/.eslintrc
Outdated
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.
Should these be:
no-var: 2
prefer-const: 2
? I'm not sure what the 2 represents here.
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.
2 means error
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.
Changed error to 2 for consistency.
|
CI 2: https://ci.nodejs.org/job/node-test-commit/7112/ EDIT: Still green |
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 think you can const this one.
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.
➜ node git:(var2const) tools/test.py test/parallel/test-http-get-pipeline-problem.js
=== release test-http-get-pipeline-problem ===
Path: parallel/test-http-get-pipeline-problem
image.length = 45658
/Users/gib/wrk/com/node/test/parallel/test-http-get-pipeline-problem.js:38
for (const i = 0; i < total; i++) {
^
TypeError: Assignment to constant variable.If this is what you meant, I don't think so. I can do for (let i = 0; though.
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.
Weird, I could swear const loop variables once worked, but I see it's failing now. Your let suggestion sounds good.
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.
unneccesary wrapping?
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 semicolon puts it over 80 chars 😭
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.
unneccesary wrapping?
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.
81 chars again
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.
Move the string to a variable so it doesn't look so hideous? :)
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.
unneccesary wrapping?
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.
➜ node git:(var2const) ✗ make lint
./node tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules \
benchmark lib test tools
/Users/gib/wrk/com/node/test/parallel/test-net-local-address-port.js
16:1 error Line 16 exceeds the maximum line length of 80 max-len
test/parallel/test-repl-tab.js
Outdated
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.
unneccesary wrapping?
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.
as above
test/parallel/test-vm-static-this.js
Outdated
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.
unneccesary wrapping?
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.
as above
test/parallel/test-writeuint.js
Outdated
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.
Same here, can probably use const.
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.
Changed to let as above (const didn't work)
test/parallel/test-zlib.js
Outdated
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.
const again.
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.
const here too.
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.
const doesn't work (the pending++ would be modifying it)
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.
Actually, as is the test failed (it's not run in CI), to fix I had to move the let to the previous line.
test/.eslintrc
Outdated
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 alphabetically sort the rules?
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.
Will do
|
@silverwind Updated, PTAL |
|
Actually, I just realised that the eslint rule isn't showing up all the vars for some reason, I'll investigate later. |
Manually fix issues that eslint --fix couldn't do automatically. PR-URL: #10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
PR-URL: #10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Manually fix issues that eslint --fix couldn't do automatically. PR-URL: nodejs#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
PR-URL: nodejs#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Manually fix issues that eslint --fix couldn't do automatically. PR-URL: nodejs#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
PR-URL: nodejs#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
|
This will need backport PRs in order to land on v6 or v4 |
|
This is likely preventing a lot of pull requests from back-porting cleanly so I think it should be back-ported with some urgency. Likewise for #10698. |
|
v4.x backport: #10685 |
|
@gibfahn did can you do a v6.x backport too? |
|
@MylesBorins I'll do it once I get the v4.x backport working. There's more pig-wrestling than I'd expected. |
Backport-PR-URL: nodejs/node#11775 PR-URL: nodejs/node#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Manually fix issues that eslint --fix couldn't do automatically. Backport-PR-URL: nodejs/node#11775 PR-URL: nodejs/node#10685 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Overview
Use eslint to convert all var to const/let in
test/, manually fix anything that eslint messed up.If we're going to go ES6 in
test/, we might as well go all the way.To fix rules with eslint
Apply this:
Run this:
eslint --fix --rulesdir=tools/eslint-rules "test/**/*.js"Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test