-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: make common.noop a getter #12732
Conversation
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)
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.
LGTM if CI is green. I'd be just as happy (maybe even slightly happier) to get rid of common.noop
altogether, but this works for me!
@@ -24,7 +24,6 @@ const common = require('../common'); | |||
const assert = require('assert'); | |||
const events = require('events'); | |||
|
|||
|
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.
Whoops, unintentional style change. I think I had written something there and then deleted too much.
I don't have a strong opinion on this change either way, but if |
What if we |
Object.defineProperty(exports, 'noop', { | ||
enumerable: true, | ||
get: () => () => {} | ||
}); |
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.
How about keeping the old noop
and add
export.newNoop = () => { return () => {}; };
+0.5 |
I think at this point writing |
Even better, we should adjust our lint rules to allow unused arrow fn parameters to be
|
@Fishrock123 although |
It was just added. A key reason I added this was to make it explicit that the function in question is intentionally a non-op. I'm definitely -1 on reverting back to the old approach. I'm also perfectly fine with cases that are better off not using I'm -1 on this PR. |
I'd just like to point out JavaScript already ships with a well known I still think a syntactical construct (like () => {}) or a built in (like Function.prototype) are clearer - but honestly all these ways are pretty obvious anyway and I don't think there is very much to gain/lose here. |
@jasnell should we then maybe warn about the difference between |
To me, it seems like if we have to document the gotchas of a noop function, it's already more trouble than it's worth. |
I think at this point this PR is superseded by #12822, so I'm going to go ahead and close it to clean up the backlog of PRs a bit :) Reopening is cheap if there ever be a need to do so. |
Make
common.noop
a getter that returns a new function object each timethe propery is read, not the same one. The old behavior could possibly
lead to subtle and hard to catch bugs in some cases.
Refs: #12711 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test