FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: convert var->const/let in tests by gibfahn · Pull Request #10685 · nodejs/node · GitHub

/ node Public

test: convert var->const/let in tests - #10685

Merged
gibfahn merged 2 commits into
nodejs:masterfrom
gibfahn:var2const
Jan 11, 2017
Merged

test: convert var->const/let in tests#10685
gibfahn merged 2 commits into
nodejs:masterfrom
gibfahn:var2const

Conversation

gibfahn commented Jan 8, 2017
edited
Loading

Copy link
Copy Markdown
Member

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:

diff --git a/.eslintrc b/.eslintrc
index cf1f36c86b..e09fd6ac64 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -110,6 +110,8 @@ rules:
 
   # ECMAScript 6
   # http://eslint.org/docs/rules/#ecmascript-6
+  no-var: error
+  prefer-const: error
   arrow-parens: [2, always]
   arrow-spacing: [2, {before: true, after: true}]
   constructor-super: 2
@@ -119,7 +121,6 @@ rules:
   no-dupe-class-members: 2
   no-new-symbol: 2
   no-this-before-super: 2
-  prefer-const: [2, {ignoreReadBeforeAssign: true}]
   rest-spread-spacing: 2
   template-curly-spacing: 2

Run this:

eslint --fix --rulesdir=tools/eslint-rules "test/**/*.js"

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test

gibfahn added the test Issues and PRs related to the tests. label Jan 8, 2017

gibfahn commented Jan 8, 2017

Copy link
Copy Markdown
Member Author

cc/ @nodejs/testing

cc/ @silverwind @Trott @not-an-aardvark Is there an easy way to make rules only apply to test/? Also should @not-an-aardvark be on the tools/eslint cc list in onboarding-extras?

targos commented Jan 8, 2017

Copy link
Copy Markdown
Member

Is there an easy way to make rules only apply to test/

Add the rule to test/.eslintrc.

gibfahn commented Jan 8, 2017

Copy link
Copy Markdown
Member Author

@targos

Add the rule to test/.eslintrc.

Thanks, done

cjihrig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rubber stamp LGTM if the CI passes.

gibfahn commented Jan 8, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

CI: https://ci.nodejs.org/job/node-test-commit/7103/

EDIT: CI passed

gibfahn commented Jan 8, 2017

Copy link
Copy Markdown
Member Author

It's probably worth checking the second and third commits:

  • second (manual fixups of eslint issues): 27d10c0
  • third (require let/const in test/): 21725bf

jasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rubber-stamp LGTM

Comment thread test/.eslintrc Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should these be:

no-var: 2
prefer-const: 2

? I'm not sure what the 2 represents here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

2 means error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Changed error to 2 for consistency.

gibfahn commented Jan 9, 2017

Copy link
Copy Markdown
Member Author

CI 2: https://ci.nodejs.org/job/node-test-commit/7112/

EDIT: Still green

gibfahn commented Jan 10, 2017

Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think you can const this one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
➜  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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Weird, I could swear const loop variables once worked, but I see it's failing now. Your let suggestion sounds good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unneccesary wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The semicolon puts it over 80 chars 😭

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unneccesary wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

81 chars again

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Move the string to a variable so it doesn't look so hideous? :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unneccesary wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
➜  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

Comment thread test/parallel/test-repl-tab.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unneccesary wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

as above

Comment thread test/parallel/test-vm-static-this.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unneccesary wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

as above

Comment thread test/parallel/test-writeuint.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Same here, can probably use const.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Changed to let as above (const didn't work)

Comment thread test/parallel/test-zlib.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

const again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

const here too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

const doesn't work (the pending++ would be modifying it)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actually, as is the test failed (it's not run in CI), to fix I had to move the let to the previous line.

Comment thread test/.eslintrc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe alphabetically sort the rules?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Will do

gibfahn commented Jan 10, 2017

Copy link
Copy Markdown
Member Author

@silverwind Updated, PTAL

gibfahn commented Jan 10, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Actually, I just realised that the eslint rule isn't showing up all the vars for some reason, I'll investigate later.

targos pushed a commit that referenced this pull request Jan 28, 2017
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>
targos pushed a commit that referenced this pull request Jan 28, 2017
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>
italoacasas mentioned this pull request Jan 29, 2017
gibfahn restored the var2const branch January 29, 2017 22:30
gibfahn deleted the var2const branch January 29, 2017 22:32
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 30, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 30, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 30, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 30, 2017
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>

jasnell commented Mar 8, 2017

Copy link
Copy Markdown
Member

This will need backport PRs in order to land on v6 or v4

Copy link
Copy Markdown
Member

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.

gibfahn restored the var2const branch March 9, 2017 08:28

gibfahn commented Mar 9, 2017

Copy link
Copy Markdown
Member Author

v4.x backport: #10685

Copy link
Copy Markdown
Contributor

@gibfahn did can you do a v6.x backport too?

gibfahn commented Mar 9, 2017

Copy link
Copy Markdown
Member Author

@MylesBorins I'll do it once I get the v4.x backport working. There's more pig-wrestling than I'd expected.

MylesBorins pushed a commit that referenced this pull request Apr 13, 2017
Backport-PR-URL: #11775
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>
MylesBorins pushed a commit that referenced this pull request Apr 13, 2017
Manually fix issues that eslint --fix couldn't do automatically.

Backport-PR-URL: #11775
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>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
Backport-PR-URL: #11775
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>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
Manually fix issues that eslint --fix couldn't do automatically.

Backport-PR-URL: #11775
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>
MylesBorins mentioned this pull request Apr 19, 2017
gibfahn deleted the var2const branch June 3, 2017 14:34
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
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>
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL