Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: enable no-throw-literal ESLint rule #11168

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/message/throw_custom_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
2 changes: 1 addition & 1 deletion test/message/throw_custom_error.out
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/message/throw_in_line_with_tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ console.error('before');

(function() {
// these lines should contain tab!
// eslint-disable-next-line no-throw-literal
throw ({ foo: 'bar' });
})();

Expand Down
2 changes: 1 addition & 1 deletion test/message/throw_in_line_with_tabs.out
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions test/message/throw_non_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
require('../common');

// custom error throwing
// eslint-disable-next-line no-throw-literal
throw ({ foo: 'bar' });
2 changes: 1 addition & 1 deletion test/message/throw_non_error.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*test*message*throw_non_error.js:5
*test*message*throw_non_error.js:6
throw ({ foo: 'bar' });
^
[object Object]
1 change: 1 addition & 0 deletions test/message/throw_null.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
require('../common');

// eslint-disable-next-line no-throw-literal
throw null;
2 changes: 1 addition & 1 deletion test/message/throw_null.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

*test*message*throw_null.js:4
*test*message*throw_null.js:5
throw null;
^
null
1 change: 1 addition & 0 deletions test/message/throw_undefined.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
require('../common');

// eslint-disable-next-line no-throw-literal
throw undefined;
2 changes: 1 addition & 1 deletion test/message/throw_undefined.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

*test*message*throw_undefined.js:4
*test*message*throw_undefined.js:5
throw undefined;
^
undefined
3 changes: 2 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ threw = false;
try {
assert.throws(
function() {
throw ({});
throw ({}); // eslint-disable-line no-throw-literal
},
Array
);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-response-status-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const http = require('http');
const net = require('net');
Expand All @@ -23,7 +23,7 @@ testCases.findByPath = function(path) {
return testCase.path === path;
});
if (matching.length === 0) {
throw 'failed to find test case with path ' + path;
common.fail(`failed to find test case with path ${path}`);
}
return matching[0];
};
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-econnreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const ca = [ cert, cacert ];
let clientError = null;
let connectError = null;

const server = tls.createServer({ ca: ca, cert: cert, key: key }, (conn) => {
throw 'unreachable';
const server = tls.createServer({ ca: ca, cert: cert, key: key }, () => {
common.fail('should be unreachable');
}).on('tlsClientError', function(err, conn) {
assert(!clientError && conn);
clientError = err;
Expand Down