Skip to content

Commit

Permalink
tools: replace assert-throw-arguments custom lint
Browse files Browse the repository at this point in the history
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 <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Sep 19, 2017
1 parent 921876d commit f8b85e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 65 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ rules:
no-mixed-spaces-and-tabs: 2
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
no-restricted-syntax: [2, {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
message: "use a regular expression for second argument of assert.throws()"
}, {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]",
message: "assert.throws() must be invoked with at least two arguments."
}, {
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
message: "setTimeout() must be invoked with at least two arguments."
}, {
Expand Down Expand Up @@ -161,7 +167,6 @@ rules:
template-curly-spacing: 2

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

# Global scoped method and vars
globals:
Expand Down
2 changes: 1 addition & 1 deletion doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Note that `error` can not be a string. If a string is provided as the second
argument, then `error` is assumed to be omitted and the string will be used for
`message` instead. This can lead to easy-to-miss mistakes:

<!-- eslint-disable assert-throws-arguments -->
<!-- eslint-disable no-restricted-syntax -->
```js
// THIS IS A MISTAKE! DO NOT DO THIS!
assert.throws(myFunction, 'missing foo', 'did not throw with expected message');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ function thrower(errorConstructor) {
assert.throws(makeBlock(thrower, a.AssertionError),
a.AssertionError, 'message');
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError);
// eslint-disable-next-line assert-throws-arguments
// eslint-disable-next-line no-restricted-syntax
assert.throws(makeBlock(thrower, a.AssertionError));

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

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

// #2893
try {
// eslint-disable-next-line assert-throws-arguments
// eslint-disable-next-line no-restricted-syntax
assert.throws(function() {
assert.ifError(null);
});
Expand Down
60 changes: 0 additions & 60 deletions tools/eslint-rules/assert-throws-arguments.js

This file was deleted.

0 comments on commit f8b85e1

Please sign in to comment.