-
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
used es6 conventions for variables and anonymous functions declaration #9669
Conversation
If we're going to refactor the test for mostly stylistic reasons, I'd ask that we also change the three instances of |
I agree with @Trott. I think the |
done |
assert.equal(err_, err); | ||
process.nextTick(() => { | ||
assert.strictEqual(stream.fd, null); | ||
assert.strictEqual(err_, err); |
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.
Use common.mustCall()
to make sure those assertions a run, as @cjihrig suggested
process.nextTick(function() { | ||
assert.equal(stream.fd, null); | ||
assert.equal(err_, err); | ||
process.nextTick(() => { |
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.
why did you use an () =>
here, and leave function()
on line 11?
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.
because I saw that in line 11 the previous developer used a named function expression, contrary to other places where he used an anonymous function in the old form.
Named function expressions can be handy when errors are thrown and I believe that was the reason for using a named function on line 11.
I didn't want to break this behavior.
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 see your thinking, but think its too subtle, function names don't matter, particularly not in tests. Better change them all.
const arguably does something useful, es6 functions don't (unless you are trying to access the enclosing |
I changed all the functions in the code except for the function declaration on line 11 which was originally set as a named function, for the sake of easier debugging, by the original developer. I changed all of the anonymous functions to their respective es6 arrow function form, but did not want to affect code stability or ease of debugging by changing line 11. Should line 11 also be changed? |
I think none should be changed, but if we are going to go all es6y, lets go all the way, not half way. I'm a bit worried that the wave of "name functions for readability of stack traces" is going to crash against the wave of "use the new es6 function syntax", and leave confusion, but for now, all es6 in this test is fine. |
I see your point. Removed the named function to maintain consistency across this file. |
|
||
stream.on('error', common.mustCall(function errorHandler(err_) { | ||
stream.on('error', common.mustCall((err_) => { | ||
console.error('error event'); |
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 this line can be removed
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.
@ruggertech Do you agree with @targos 's suggestion 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.
I do, will take it off
do we need anything else for this to be merged ? |
}; | ||
|
||
stream.on('data', function(buf) { | ||
stream.on('data', (buf) => { | ||
stream.on('data', common.fail); // no more 'data' events should follow |
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.
It would be better not not invoke common.fail
directly but rather wrap it in a function and pass it a message string.
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.
Something like that:
stream.on('data', () => {
stream.on('data', () => common.fail('no more "data" events should follow'));
});
?
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.
done
commit message doesn't follow guidelines, it's too long and doesn't start with |
stream.on('data', function(buf) { | ||
stream.on('data', common.fail); // no more 'data' events should follow | ||
stream.on('data', () => { | ||
stream.on('data', () => common.fail); // no more 'data' events should follow |
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 be either () => common.fail()
or just common.fail
.
Can someone merge please :-) |
var cb = arguments[arguments.length - 1]; | ||
process.nextTick(function() { | ||
fs.read = common.mustCall(() => { | ||
const cb = arguments[arguments.length - 1]; |
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.
arguments
now refers to the outer function's arguments. It doesn't change the outcome of the test but I think it's better not to change this one to an arrow function.
implemented arrow functions and changed var to const where appropriate.
Thanks. LGTM. Final CI: https://ci.nodejs.org/job/node-test-pull-request/5155/ |
implemented arrow functions and changed var to const where appropriate. PR-URL: #9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in ef74e03. |
implemented arrow functions and changed var to const where appropriate. PR-URL: #9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
implemented arrow functions and changed var to const where appropriate. PR-URL: nodejs#9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
implemented arrow functions and changed var to const where appropriate. PR-URL: nodejs#9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
implemented arrow functions and changed var to const where appropriate. PR-URL: #9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
implemented arrow functions and changed var to const where appropriate. PR-URL: #9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
implemented arrow functions and changed var to const where appropriate. PR-URL: #9669 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesDescription of change
changed es5 "var" to "const" and anonymous functions to arrow function syntax