diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 4f691caefd..81c93e533b 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -40,6 +40,7 @@ rules: no-octal: 2 no-redeclare: 2 no-self-assign: 2 + no-throw-literal: 2 no-unused-labels: 2 no-useless-call: 2 no-useless-escape: 2 diff --git a/test/message/throw_custom_error.js b/test/message/throw_custom_error.js index 8866ca8514..97df4fd390 100644 --- a/test/message/throw_custom_error.js +++ b/test/message/throw_custom_error.js @@ -2,4 +2,5 @@ require('../common'); // custom error throwing +// eslint-disable-next-line no-throw-literal throw ({ name: 'MyCustomError', message: 'This is a custom message' }); diff --git a/test/message/throw_custom_error.out b/test/message/throw_custom_error.out index 401581f31d..ef73c52c88 100644 --- a/test/message/throw_custom_error.out +++ b/test/message/throw_custom_error.out @@ -1,4 +1,4 @@ -*test*message*throw_custom_error.js:5 +*test*message*throw_custom_error.js:6 throw ({ name: 'MyCustomError', message: 'This is a custom message' }); ^ MyCustomError: This is a custom message diff --git a/test/message/throw_in_line_with_tabs.js b/test/message/throw_in_line_with_tabs.js index ad95d66e97..f02e5479d6 100644 --- a/test/message/throw_in_line_with_tabs.js +++ b/test/message/throw_in_line_with_tabs.js @@ -6,6 +6,7 @@ console.error('before'); (function() { // these lines should contain tab! + // eslint-disable-next-line no-throw-literal throw ({ foo: 'bar' }); })(); diff --git a/test/message/throw_in_line_with_tabs.out b/test/message/throw_in_line_with_tabs.out index d245cca494..e83b057684 100644 --- a/test/message/throw_in_line_with_tabs.out +++ b/test/message/throw_in_line_with_tabs.out @@ -1,5 +1,5 @@ before -*test*message*throw_in_line_with_tabs.js:9 +*test*message*throw_in_line_with_tabs.js:10 throw ({ foo: 'bar' }); ^ [object Object] diff --git a/test/message/throw_non_error.js b/test/message/throw_non_error.js index d4dae642af..7a23908eec 100644 --- a/test/message/throw_non_error.js +++ b/test/message/throw_non_error.js @@ -2,4 +2,5 @@ require('../common'); // custom error throwing +// eslint-disable-next-line no-throw-literal throw ({ foo: 'bar' }); diff --git a/test/message/throw_non_error.out b/test/message/throw_non_error.out index b98edc46ae..15f95fcc11 100644 --- a/test/message/throw_non_error.out +++ b/test/message/throw_non_error.out @@ -1,4 +1,4 @@ -*test*message*throw_non_error.js:5 +*test*message*throw_non_error.js:6 throw ({ foo: 'bar' }); ^ [object Object] diff --git a/test/message/throw_null.js b/test/message/throw_null.js index 9b17aa68f1..2c5a8f47cc 100644 --- a/test/message/throw_null.js +++ b/test/message/throw_null.js @@ -1,4 +1,5 @@ 'use strict'; require('../common'); +// eslint-disable-next-line no-throw-literal throw null; diff --git a/test/message/throw_null.out b/test/message/throw_null.out index 5d2c677240..eb3eeb1294 100644 --- a/test/message/throw_null.out +++ b/test/message/throw_null.out @@ -1,5 +1,5 @@ -*test*message*throw_null.js:4 +*test*message*throw_null.js:5 throw null; ^ null diff --git a/test/message/throw_undefined.js b/test/message/throw_undefined.js index 18c27dbac8..7d0fef0dbd 100644 --- a/test/message/throw_undefined.js +++ b/test/message/throw_undefined.js @@ -1,4 +1,5 @@ 'use strict'; require('../common'); +// eslint-disable-next-line no-throw-literal throw undefined; diff --git a/test/message/throw_undefined.out b/test/message/throw_undefined.out index 32a71f0486..c23dac051f 100644 --- a/test/message/throw_undefined.out +++ b/test/message/throw_undefined.out @@ -1,5 +1,5 @@ -*test*message*throw_undefined.js:4 +*test*message*throw_undefined.js:5 throw undefined; ^ undefined diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index f9e82c758a..ba3f8ad352 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -394,7 +394,7 @@ threw = false; try { assert.throws( function() { - throw ({}); + throw ({}); // eslint-disable-line no-throw-literal }, Array ); @@ -576,6 +576,7 @@ testBlockTypeError(assert.throws, undefined); testBlockTypeError(assert.doesNotThrow, undefined); // https://github.com/nodejs/node/issues/3275 +// eslint-disable-next-line no-throw-literal assert.throws(() => { throw 'error'; }, (err) => err === 'error'); assert.throws(() => { throw new Error(); }, (err) => err instanceof Error);