Skip to content

Commit 9f319d5

Browse files
Trottaddaleax
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. 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 5094f2c commit 9f319d5

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
}, {
@@ -162,7 +168,6 @@ rules:
162168
template-curly-spacing: error
163169

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

168173
# Global scoped method and vars

doc/api/assert.md

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

585-
<!-- eslint-disable assert-throws-arguments -->
585+
<!-- eslint-disable no-restricted-syntax -->
586586
```js
587587
// THIS IS A MISTAKE! DO NOT DO THIS!
588588
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
@@ -646,7 +646,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
646646
{
647647
let threw = false;
648648
try {
649-
// eslint-disable-next-line assert-throws-arguments
649+
// eslint-disable-next-line no-restricted-syntax
650650
assert.throws(function() {
651651
assert.ifError(null);
652652
});

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

-60
This file was deleted.

0 commit comments

Comments
 (0)