tools: require function declarations#12711
Conversation
doc/api/util.md
Outdated
There was a problem hiding this comment.
@abouthiroppy Are you confusing this doc file with a test?
.eslintrc.yaml
Outdated
There was a problem hiding this comment.
Can the quotes be omitted here?
There was a problem hiding this comment.
Can the quotes be omitted here?
Yes, indeed. Done!
test/addons-napi/test_async/test.js
Outdated
There was a problem hiding this comment.
Can it also be common.mustCall()?
There was a problem hiding this comment.
Can it also be common.mustCall()?
Sure seems like it! Done! Thanks!
There was a problem hiding this comment.
Not here or on the line below, and this is actually something that I've worried about for a while: common.noop doesn't really save us a lot of code and can lead to subtle bugs such as if it is used here.
If used here and the line below, then listen1 and listen2 are the same object, thus invalidating the test!
This could perhaps be fixed by making common.noop a getter that returns a different no-op function object each time it is called. But I kinda wonder if we might just be better off doing a global find/replace on common.noop and using () => {} instead.
/cc @nodejs/testing
There was a problem hiding this comment.
@Trott on the other hand, test/parallel/test-event-emitter-remove-all-listeners relies on common.noop being the same object (discovered that by actually making common.noop a getter).
There was a problem hiding this comment.
@aqrln In that case, I imagine explicitly defining const noop = () => {}; in the test itself would make it clear that everything is intentionally using the same function object and that it's not a mistake.
There was a problem hiding this comment.
@Trott yeah, makes sense. I will follow up with a PR quickly.
There was a problem hiding this comment.
I just simply would not use common.noop here. In fact, if memory serves correctly, when I opened the common.noop PR just a few weeks ago I intentionally left this test alone because it did not make sense to use it here... and that is perfectly fine. It's ok not to use it when it doesn't make sense to.
test/parallel/test-util-inspect.js
Outdated
There was a problem hiding this comment.
This is another place where common.noop usage can lead to subtle bugs. The next line adds a property to the object, which would end up adding the property to common.noop which means possible side effects in other tests.
test/parallel/test-os.js
Outdated
There was a problem hiding this comment.
e => e.address === '127.0.0.1'?
There was a problem hiding this comment.
Sure! It's the predominant style and if it inches us closer to being able to enable arrow-body-style in .eslintrc.yaml, then I'm all for it.
test/parallel/test-os.js
Outdated
There was a problem hiding this comment.
e => e.address === '127.0.0.1'?
There was a problem hiding this comment.
e => e.address === '127.0.0.1'?
👍
test/parallel/test-preload.js
Outdated
There was a problem hiding this comment.
const fixture = name => path.join(common.fixturesDir, name);?
There was a problem hiding this comment.
const completer = line => [[], line];?
f79ef5b to
fbac2cf
Compare
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations.
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations).
|
Arrow function and quotation mark nits applied. |
Make `common.noop` a getter that returns a new function object each time the propery is read, not the same one. The old behavior could possibly lead to subtle and hard to catch bugs in some cases. Refs: nodejs#12711 (comment)
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations. PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations). PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations. PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations). PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations. PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations). PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations). PR-URL: #12711 Backport-PR-URL: #13774 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations). PR-URL: #12711 Backport-PR-URL: #13774 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations. PR-URL: nodejs#12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Welp, not sure how this will be received, but since it is the predominant style in our code base and since we are occasionally offering nits to new contributors to use the style to avoid potential confusion over the Temporal Dead Zone....
In lib, doc, and test (but mostly test): Replace function expressions with function declarations in preparation for a lint rule requiring function declarations.
Then: Except for arrow functions, require function declarations instead of function expressions via linting. This is the predominant style in our code base (77 instances of expressions to 2344 instances of declarations).
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
tools test lib doc