Skip to content
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

Closed
wants to merge 1 commit into from
Closed

used es6 conventions for variables and anonymous functions declaration #9669

wants to merge 1 commit into from

Conversation

ruggertech
Copy link
Contributor

@ruggertech ruggertech commented Nov 17, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Description of change

changed es5 "var" to "const" and anonymous functions to arrow function syntax

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Nov 17, 2016
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Nov 17, 2016
@mscdex
Copy link
Contributor

mscdex commented Nov 17, 2016

@Trott
Copy link
Member

Trott commented Nov 18, 2016

If we're going to refactor the test for mostly stylistic reasons, I'd ask that we also change the three instances of assert.equal() to assert.strictEqual().

@cjihrig
Copy link
Contributor

cjihrig commented Nov 18, 2016

I agree with @Trott. I think the process.nextTick() that surrounds those assertions should also have a common.mustCall().

@ruggertech
Copy link
Contributor Author

done

assert.equal(err_, err);
process.nextTick(() => {
assert.strictEqual(stream.fd, null);
assert.strictEqual(err_, err);
Copy link
Member

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(() => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@sam-github
Copy link
Contributor

const arguably does something useful, es6 functions don't (unless you are trying to access the enclosing this). I don't really mind all the code churn, but if you are going to change some functions to es6, please do them all, so the file is internally consistent.

@ruggertech
Copy link
Contributor Author

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?

@sam-github
Copy link
Contributor

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.

@ruggertech
Copy link
Contributor Author

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');
Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

@ruggertech ruggertech Nov 24, 2016

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

@ruggertech
Copy link
Contributor Author

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
Copy link
Contributor

@Fishrock123 Fishrock123 Nov 20, 2016

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.

Copy link
Contributor Author

@ruggertech ruggertech Nov 20, 2016

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'));
});

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sam-github
Copy link
Contributor

commit message doesn't follow guidelines, it's too long and doesn't start with test: , see https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-3-commit

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
Copy link
Contributor

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.

@cjihrig
Copy link
Contributor

cjihrig commented Nov 27, 2016

@ruggertech
Copy link
Contributor Author

Can someone merge please :-)

var cb = arguments[arguments.length - 1];
process.nextTick(function() {
fs.read = common.mustCall(() => {
const cb = arguments[arguments.length - 1];
Copy link
Member

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.

@ruggertech ruggertech closed this Dec 3, 2016
implemented arrow functions and changed var to
const where appropriate.
@ruggertech ruggertech reopened this Dec 3, 2016
@targos
Copy link
Member

targos commented Dec 3, 2016

Thanks. LGTM. Final CI: https://ci.nodejs.org/job/node-test-pull-request/5155/

jasnell pushed a commit that referenced this pull request Dec 5, 2016
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>
@jasnell
Copy link
Member

jasnell commented Dec 5, 2016

Landed in ef74e03.

@jasnell jasnell closed this Dec 5, 2016
Fishrock123 pushed a commit that referenced this pull request Dec 6, 2016
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>
addaleax pushed a commit to addaleax/node that referenced this pull request Dec 8, 2016
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>
jmdarling pushed a commit to jmdarling/node that referenced this pull request Dec 8, 2016
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>
MylesBorins pushed a commit that referenced this pull request Dec 20, 2016
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>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
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>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
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>
This was referenced Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.