-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
test: enable linting for tests and fix tests #1721
Conversation
Why? The only reason for using strict mode in core was
What for? |
Tests do run strict once
There's at least As for unreachable, there are a few tests that do stuff after a throw:
I guess we could just remove the unreachable code in these. |
0daf392
to
234eb90
Compare
Because it requires a change in all the test files, and yet yields no benefit eslint doesn't provide already. That's a good enough reason imho.
Hmm... that's unusual. Maybe still disable that rule on per-file basis, because it is useful rule generally. I wonder what purpose those statements have though. |
Examples of code after throw: 1 2 3 4. No benefit there, right? Regarding strict mode: enabling it lead me to at least 2 cases of duplicate property or argumentsnames and to a few cases of unintentional global variable usage, which I fixed. It has some benefits. I guess now that these issues are fixed, I could revert to non-strict if we want to keep the number of changed files low. |
+1. Ref: joyent/node#25280, joyent/node#25288 |
LGTM with a comment (see below.) For the record: I'm in favor of turning on strict mode. @silverwind Can you make the function arguments line up in test/common.js, test/parallel/test-fs-read-stream-inherit.js, test/parallel/test-http-url.parse-only-support-http-https-protocol.js, test/parallel/test-repl-reset-event.js and test/parallel/test-timers-ordering.js? I see you've been doing that in other files so it would be best to stay consistent. By the way, doesn't eslint complain about |
Will try. It's not always possible to line them up at
That's not enforced yet, which style should we enforce? Rule here.
Didn't want to split the long strings there in two, should I go for it? |
@bnoordhuis all done. added 2 more rules for function style. PTAL |
@silverwind And I would like to upgrade our eslint from v0.20 to v0.21 before our eslint changes. So we don't modify extends: "../.eslintrc"
ecmaFeatures:
"forOf": true
rules:
space-before-function-paren: [2, "never"]
space-before-blocks: [2, "always"]
But I have not confirmed the eslint config inheritance yet... If I finished to confirm the feature then, I will pull request it. |
@yosuke-furukawa I was under the impression that |
@silverwind In my understanding, we can inherit the config, but we don't apply the differenct configuration on a directory. that is eslint v0.21 feature. current version is v0.20. |
I doubt |
OK, I will check it. |
@silverwind +1 for I think the following code style checks are not needed currently. quotes: 0
semi: 0
indent: 0
max-len: 0 current chages are huge, I cannot check the chages are proper or not... |
Yeah, a shame GitHub cuts the diff here. Except maybe 5 cases, all changes are of stylistic nature. If you like, I can highlight the actual changes to code, if that makes the review easier. But I think @bnoordhuis already did an overall check. |
I also browsed the changes roughly. I would like to know why this change is needed. }, function(err) {
if (err instanceof Error) {
- assert.strictEqual(err.message,
- 'Protocol "file:" not supported. Expected "http:".');
+ assert.strictEqual(err.message, 'Protocol "file:" not supported.' +
+ ' Expected "http:".');
return true;
}
}); I don't think this is readable but eslint warns some messages ?? |
Well, the normal recommendation on how to split lines like this that go over 80 chars is to align additional lines to the function parens like this: assert.strictEqual(err.message,
'Protocol "file:" not supported. Expected "http:".'); Now the issue in this case is, the second line goes above 80 chars as well, which forced me to split the string unfortunately. |
@silverwind |
I'm not sure it's worth the time to change back now again. Tests do pass with the same strict rules like The 80 chars rule is there for an valid, albeit archaic reason, and I think @bnoordhuis would agree to keeping it in place. |
I also think the huge benefit for linting test codes. but If i were you, i would change the code like this. if (err instanceof Error) {
- assert.strictEqual(err.message,
- 'Protocol "file:" not supported. Expected "http:".');
+ assert.strictEqual(
+ err.message, 'Protocol "file:" not supported. Expected "http:".'); //75 chars
return true;
} or if (err instanceof Error) {
- assert.strictEqual(err.message,
- 'Protocol "file:" not supported. Expected "http:".');
+ assert.strictEqual(
+ err.message,
+ 'Protocol "file:" not supported. Expected "http:".'); // down indent
return true;
} |
I do not understand what is wrong with the original code here: assert.strictEqual(err.message,
'Protocol "file:" not supported. Expected "http:".'); Breaking a line and starting a new one with +4 spaces indent is somewhat a standard in this case. If linter doesn't complain, don't change the existing code. If linter complains about this particular case, fix the linter. In any case I don't think it should be changed. edit: nevermind, the diff above confused me. |
THE 80 CHARACTER LIMIT IS INVIOLATE! (In all seriousness, there needs to be a limit and 80 chars is traditional.)
io.js / node.js follows a lisp-y style where arguments need to line up. |
Had a quick look and rubber-stamp LGTM. It needs a rebase and you should run the CI after that just in case but it looks good to go to me. |
Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed.
Fixed up CI: https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/686/ |
A few unrelated failures were from #1707. One new failure on windows boxes: not ok 215 - test-fs-non-number-arguments-throw.js
#
# assert.js:88
# throw new assert.AssertionError({
# ^
# AssertionError: read uire('assert' instead of ire('assert')
# at ReadStream.<anonymous> (c:\workspace\iojs+any-pr+multi\nodes\win2012r2\test\parallel\test-fs-non-number-arguments-throw.js:23:10)
# at emitOne (events.js:77:13)
# at ReadStream.emit (events.js:169:7)
# at readableAddChunk (_stream_readable.js:145:16)
# at ReadStream.Readable.push (_stream_readable.js:109:10)
# at onread (fs.js:1734:12)
# at FSReqWrap.wrapper [as oncomplete] (fs.js:576:17) The test reads itself, and for some reason reads one position to low on both win2008 and win2012. Strangely, I can't reproduce on my Windows 7 box. |
Curious. I wonder if the test has been broken all along. For posterity, here is the diff: diff --git a/test/parallel/test-fs-non-number-arguments-throw.js b/test/parallel/test-fs-non-number-arguments-throw.js
index 7a1e7bd..4e7af86 100644
--- a/test/parallel/test-fs-non-number-arguments-throw.js
+++ b/test/parallel/test-fs-non-number-arguments-throw.js
@@ -1,23 +1,24 @@
+'use strict';
var assert = require('assert'),
fs = require('fs'),
saneEmitter,
sanity = 'ire(\'assert\')';
-saneEmitter = fs.createReadStream(__filename, { start: 17, end: 29 });
+saneEmitter = fs.createReadStream(__filename, { start: 31, end: 43 });
-assert.throws(function () {
- fs.createReadStream(__filename, { start: "17", end: 29 });
+assert.throws(function() {
+ fs.createReadStream(__filename, { start: '31', end: 43 });
}, "start as string didn't throw an error for createReadStream");
-assert.throws(function () {
- fs.createReadStream(__filename, { start: 17, end: "29" });
+assert.throws(function() {
+ fs.createReadStream(__filename, { start: 31, end: '43' });
}, "end as string didn't throw an error");
-assert.throws(function () {
- fs.createWriteStream(__filename, { start: "17" });
+assert.throws(function() {
+ fs.createWriteStream(__filename, { start: '31' });
}, "start as string didn't throw an error for createWriteStream");
-saneEmitter.on('data', function (data) {
+saneEmitter.on('data', function(data) {
// a sanity check when using numbers instead of strings
assert.strictEqual(sanity, data.toString('utf8'), 'read ' +
data.toString('utf8') + ' instead of ' + sanity);
It passes both times on my Linux machine, however. |
Guessing it's related to the newline introduced. Started off another CI: https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/688/ |
Works fine in both python and iojs on my Windows machine:
|
Working fine on a Windows 8.1 VM I just set up: branch master
branch test-lint
Either this is CI-specific or Windows Server specific. I'm thinking that this could maybe point us to the reason of the other test failures on Windows too. Could someone with access to the Windows CI machines check why |
For giggles, I also spun up a Windows 2012 VM, unable to reproduce:
At this point, I'm certain that this is another issue with the Windows CI and it didn't manifest before because the test only read from the first line. |
I'll revert changes on that test and add it to |
No new failures in the CI now, noteably a few build targets like CoreOS and CentOS didn't start up correctly, but I'm confident the changes here are fine now. |
Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed. test-fs-non-number-arguments-throw had to be excluded from the changes because of a weird issue on Windows CI. PR-URL: #1721 Reviewed-By: Ben Noordhuis <[email protected]>
Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed. test-fs-non-number-arguments-throw had to be excluded from the changes because of a weird issue on Windows CI. PR-URL: nodejs#1721 Reviewed-By: Ben Noordhuis <[email protected]> Conflicts: test/parallel/test-arm-math-exp-regress-1376.js test/parallel/test-net-dns-custom-lookup.js test/parallel/test-net-dns-lookup-skip.js test/parallel/test-repl-mode.js test/parallel/test-repl-options.js test/parallel/test-repl-tab.js test/parallel/test-util-inspect.js
Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed. test-fs-non-number-arguments-throw had to be excluded from the changes because of a weird issue on Windows CI. PR-URL: nodejs/node#1721 Reviewed-By: Ben Noordhuis <[email protected]>
This enables eslint for the
test
subdirectory. Noteable changes:debugger
and unreachable code are allowed in testsforOf
in global .eslintrc, as one test made use of itHad to fix a ton of whitespace, semicolons and line wrappings to get all tests to pass the linter.