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)
Trott
left a comment
There was a problem hiding this comment.
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!
| const assert = require('assert'); | ||
| const events = require('events'); | ||
|
|
||
|
|
There was a problem hiding this comment.
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.
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.noopa 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