test, tools: add common.noop and common.mustNotCall lint rule#12027
test, tools: add common.noop and common.mustNotCall lint rule#12027jasnell wants to merge 2 commits intonodejs:masterfrom
Conversation
There was a problem hiding this comment.
Nit: Indicate what you are preferring it over. Maybe Prefer common.mustNotCall(msg) over common.mustCall(fn, 0) or whatever.
There was a problem hiding this comment.
(Ah, I see it's also in the message supplied to the user. Might not be terrible to put it in the comment overview too, though.)
Fishrock123
left a comment
There was a problem hiding this comment.
Seems good to me.
CI: https://ci.nodejs.org/job/node-test-pull-request/7027/
(LGTM but I'd like more eyes, large changes XD)
There was a problem hiding this comment.
Are you using nested ifs instead of lots of && because it looks cleaner?
There was a problem hiding this comment.
Could you at least break these out into one or more helper functions (isCommonMethod(), isMustCall())?
|
cc/ @not-an-aardvark, @silverwind, @targos for the eslint side |
not-an-aardvark
left a comment
There was a problem hiding this comment.
Linter rule LGTM
There was a problem hiding this comment.
Could you at least break these out into one or more helper functions (isCommonMethod(), isMustCall())?
|
@cjihrig ... updated! new and improved! |
|
Beautiful. One thing I just noticed - do you think it's worth adjusting the argument checking in the lint rule, since |
|
Good point lol |
Out of interest, is there a reason to allow |
|
The point is that |
Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)`
|
@cjihrig ... updated to catch |
|
The rule LGTM. I didn't re-review everything else. I'm assuming that part didn't change. |
|
Only CI failure is unrelated. |
Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)` PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
|
Landed in 4f2e372...20b1823 |
|
This will need to be manually backported to v7.x |
|
ping @jasnell one more time for backport |
Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)` PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)` PR-URL: #12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Throughout the tests, creation of non-op functions is fairly extensive, and it is not uncommon to find
common.mustCall(() => {})orcommon.mustCall(function() {}), ornoop = () => {};type declarations throughout.This PR introduces a
common.noopnon-op function that is used as an alternative to redeclaring nonops all the time.The
common.mustCall()method is also modified such that thefnargument defaults tocommon.noopifundefined, making it unnecessary to pass in a function when a nonop is needed.There were also a couple of places where
common.mustCall(fn, 0)was used to identify a function that should not be called. These are replace withcommon.mustNotCall()and a lint rule is added.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test, tools