Skip to content

Commit e506bcd

Browse files
committed
tools: replace assert-throw-arguments custom lint
The functionality of ESLint custom rule assert-throws-arguments can be replaced with no-restricted-syntax entries. 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 548cc72 commit e506bcd

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
@@ -119,6 +119,12 @@ rules:
119119
no-mixed-spaces-and-tabs: error
120120
no-multiple-empty-lines: [error, {max: 2, maxEOF: 0, maxBOF: 0}]
121121
no-restricted-syntax: [error, {
122+
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
123+
message: "use a regular expression for second argument of assert.throws()"
124+
}, {
125+
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]",
126+
message: "assert.throws() must be invoked with at least two arguments."
127+
}, {
122128
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
123129
message: "setTimeout() must be invoked with at least two arguments."
124130
}, {
@@ -163,7 +169,6 @@ rules:
163169
template-curly-spacing: error
164170

165171
# Custom rules in tools/eslint-rules
166-
assert-throws-arguments: [error, { requireTwo: true }]
167172
no-unescaped-regexp-dot: error
168173

169174
# Global scoped method and vars

doc/api/assert.md

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

586-
<!-- eslint-disable assert-throws-arguments -->
586+
<!-- eslint-disable no-restricted-syntax -->
587587
```js
588588
// THIS IS A MISTAKE! DO NOT DO THIS!
589589
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
@@ -412,11 +412,11 @@ function thrower(errorConstructor) {
412412
assert.throws(makeBlock(thrower, a.AssertionError),
413413
a.AssertionError, 'message');
414414
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError);
415-
// eslint-disable-next-line assert-throws-arguments
415+
// eslint-disable-next-line no-restricted-syntax
416416
assert.throws(makeBlock(thrower, a.AssertionError));
417417

418418
// if not passing an error, catch all.
419-
// eslint-disable-next-line assert-throws-arguments
419+
// eslint-disable-next-line no-restricted-syntax
420420
assert.throws(makeBlock(thrower, TypeError));
421421

422422
// when passing a type, only catch errors of the appropriate type
@@ -618,7 +618,7 @@ testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity },
618618
{
619619
let threw = false;
620620
try {
621-
// eslint-disable-next-line assert-throws-arguments
621+
// eslint-disable-next-line no-restricted-syntax
622622
assert.throws(function() {
623623
assert.ifError(null);
624624
});

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

-60
This file was deleted.

0 commit comments

Comments
 (0)