-
Notifications
You must be signed in to change notification settings - Fork 30k
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: fixes for more strict linting #7920
Conversation
})); | ||
.on('online', function() { this.disconnect(); }) | ||
.on('exit', common.mustCall(function(status) { | ||
assert.equal(status, SENTINEL); |
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.
strictEqual ?
+1 for better readability. LGTM. |
.from(b.toString('hex'), 'hex') | ||
.includes(Buffer.from('64', 'hex'), 0, 'hex'), | ||
true | ||
); |
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.
Is this really an improvement? It looks like the opposite to my eyes...
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.
@Slayer95 This was a bit outside the scope of what is described in the commit message, so (as @targos suggested previously), I should update the commit message. This is an improvement (in my opinion, anyway) because the previous test passed as long as buf.includes()
returned any truthy value. But, in fact, buf.includes()
is broken if it returns some other value than true
. So this makes the test more strict.
However, in the process of making the test better, we've made the assertion less readable because now there is a second argument and the previous layout messes with the second argument.
If you do this, then it's easy to miss the second argument entirely:
assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'), true
);
This is better, but it's not immediately clear that true
is the second argument and not the third:
assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
true
);
This next one is more lines to take in at once than might be ideal, but once you see the pattern, it's easy to scan the subsequent occurrences of the pattern. The same is not true for the above. They are more difficult to scan, especially if the number of chained properties in the first argument varies or if the number of arguments varies. So, in my opinion, this is the more readable formatting:
assert.strictEqual(
Buffer
.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
true
);
I think the above (which is the one I chose) is better than this next one, but I could live with this too:
assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
true
);
Addressed comments by @targos (including improving the commit message) , squashed, force pushed. |
I generally think this is an improvement - especially the changes to assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
true
); |
LGTM |
Changed to format preferred by @cjihrig. |
LGTM (although that might be premature for a WIP). |
Removing the |
A new version of ESLint flags chained properties on multiple lines that were not flagged by the previous version of ESLint. In preparation for turning that feature on, adjust alignment to that expected by the linter. This change happened to be predominantly around assertions using `assert()` and `assert.equal()`. These were changed to `assert.strictEqual()` where possible.
A new version of ESLint flags chained properties on multiple lines that were not flagged by the previous version of ESLint. In preparation for turning that feature on, adjust alignment to that expected by the linter. This change happened to be predominantly around assertions using `assert()` and `assert.equal()`. These were changed to `assert.strictEqual()` where possible. PR-URL: nodejs#7920 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in b4258bb |
Refs: nodejs#7920 PR-URL: nodejs#7999 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
A new version of ESLint flags chained properties on multiple lines that were not flagged by the previous version of ESLint. In preparation for turning that feature on, adjust alignment to that expected by the linter. This change happened to be predominantly around assertions using `assert()` and `assert.equal()`. These were changed to `assert.strictEqual()` where possible. PR-URL: #7920 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Conflicts: test/parallel/test-readline-interface.js
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
tools test
Description of change
A new version of ESLint flags chained properties on multiple lines that
were not flagged by the previous version of ESLint. In preparation for
turning that feature on, adjust alignment to that expected by linter.
WIP. Will probably update ESLint itself after
3.2.1 is released, likely on Monday.a new version is released on August 12 (either 3.2.2 or 3.3.0). (The current 3.2.1 flags this issue a bit too liberally and would result in enormous churn.)These changes seem to me to improve readability in most cases (especially the
readline
test file) and also provide an opportunity to change some instances ofassert.equal()
andassert()
toassert.strictEqual()
.