GeezerVison is showing github.com — tools: disallow constructing an Error without using it · nodejs/node@c3e7d57
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: benchmark/error/error.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ const bench = common.createBenchmark(main, { |
9 | 9 | function main({ n }) { |
10 | 10 | bench.start(); |
11 | 11 | for (let i = 0; i < n; ++i) |
| 12 | + // eslint-disable-next-line no-restricted-syntax |
12 | 13 | new Error('test'); |
13 | 14 | bench.end(n); |
14 | 15 | } |
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-errors-systemerror.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ const { E, SystemError, codes, kIsNodeError } = require('internal/errors'); |
7 | 7 | const { inspect } = require('internal/util/inspect'); |
8 | 8 |
|
9 | 9 | assert.throws( |
| 10 | + // eslint-disable-next-line no-restricted-syntax |
10 | 11 | () => { new SystemError(); }, |
11 | 12 | { |
12 | 13 | name: 'TypeError', |
|
Collapse file
Copy file name to clipboardExpand all lines: tools/eslint/eslint.config_utils.mjs +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,10 @@ export const noRestrictedSyntaxCommonAll = [ |
16 | 16 | selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]', |
17 | 17 | message: 'Use `new` keyword when throwing an `Error`.', |
18 | 18 | }, |
| 19 | + { |
| 20 | + selector: 'ExpressionStatement > NewExpression[callee.name=/Error$/]', |
| 21 | + message: 'Throw, return, or assign the `Error`; constructing it alone does nothing.', |
| 22 | + }, |
19 | 23 | { |
20 | 24 | selector: "CallExpression[callee.property.name='substr']", |
21 | 25 | message: 'Use String.prototype.slice() or String.prototype.substring() instead of String.prototype.substr()', |
|