Skip to content

Commit f8b85e1

Browse files
TrottMylesBorins
authored andcommitted
tools: replace assert-throw-arguments custom lint
The functionality of ESLint custom rule assert-throws-arguments can be replaced with no-restricted-syntax entries. Backport-PR-URL: #15253 PR-URL: #14547 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 921876d commit f8b85e1

File tree

4 files changed

+10
-65
lines changed

4 files changed

+10
-65
lines changed

.eslintrc.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ rules:
117117
no-mixed-spaces-and-tabs: 2
118118
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
119119
no-restricted-syntax: [2, {
120+
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
121+
message: "use a regular expression for second argument of assert.throws()"
122+
}, {
123+
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]",
124+
message: "assert.throws() must be invoked with at least two arguments."
125+
}, {
120126
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
121127
message: "setTimeout() must be invoked with at least two arguments."
122128
}, {
@@ -161,7 +167,6 @@ rules:
161167
template-curly-spacing: 2
162168

163169
# Custom rules in tools/eslint-rules
164-
assert-throws-arguments: [2, { requireTwo: true }]
165170

166171
# Global scoped method and vars
167172
globals:

doc/api/assert.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ Note that `error` can not be a string. If a string is provided as the second
478478
argument, then `error` is assumed to be omitted and the string will be used for
479479
`message` instead. This can lead to easy-to-miss mistakes:
480480

481-
<!-- eslint-disable assert-throws-arguments -->
481+
<!-- eslint-disable no-restricted-syntax -->
482482
```js
483483
// THIS IS A MISTAKE! DO NOT DO THIS!
484484
assert.throws(myFunction, 'missing foo', 'did not throw with expected message');

test/parallel/test-assert.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ function thrower(errorConstructor) {
345345
assert.throws(makeBlock(thrower, a.AssertionError),
346346
a.AssertionError, 'message');
347347
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError);
348-
// eslint-disable-next-line assert-throws-arguments
348+
// eslint-disable-next-line no-restricted-syntax
349349
assert.throws(makeBlock(thrower, a.AssertionError));
350350

351351
// if not passing an error, catch all.
352-
// eslint-disable-next-line assert-throws-arguments
352+
// eslint-disable-next-line no-restricted-syntax
353353
assert.throws(makeBlock(thrower, TypeError));
354354

355355
// when passing a type, only catch errors of the appropriate type
@@ -524,7 +524,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
524524

525525
// #2893
526526
try {
527-
// eslint-disable-next-line assert-throws-arguments
527+
// eslint-disable-next-line no-restricted-syntax
528528
assert.throws(function() {
529529
assert.ifError(null);
530530
});

tools/eslint-rules/assert-throws-arguments.js

-60
This file was deleted.

0 commit comments

Comments
 (0)