eslint: Fix no-throw-literal.

https://eslint.org/docs/rules/no-throw-literal

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-10-07 04:01:09 -07:00 committed by Tim Abbott
parent 5c8117a426
commit 043c34d944
5 changed files with 6 additions and 5 deletions

View File

@ -73,6 +73,7 @@
"no-script-url": "error", "no-script-url": "error",
"no-self-compare": "error", "no-self-compare": "error",
"no-sync": "error", "no-sync": "error",
"no-throw-literal": "error",
"no-undef-init": "error", "no-undef-init": "error",
"no-unneeded-ternary": ["error", {"defaultAssignment": false}], "no-unneeded-ternary": ["error", {"defaultAssignment": false}],
"no-unused-expressions": "error", "no-unused-expressions": "error",

View File

@ -91,7 +91,7 @@ function config_fake_channel(conf) {
channel.get = function (opts) { channel.get = function (opts) {
if (called && !conf.can_call_again) { if (called && !conf.can_call_again) {
throw "only use this for one call"; throw new Error("only use this for one call");
} }
if (!conf.can_call_again) { if (!conf.can_call_again) {
assert(self.success === undefined); assert(self.success === undefined);

View File

@ -56,7 +56,7 @@ run_test("transmit_message_ajax", () => {
run_test("transmit_message_ajax_reload_pending", () => { run_test("transmit_message_ajax_reload_pending", () => {
const success = function () { const success = function () {
throw "unexpected success"; throw new Error("unexpected success");
}; };
reload_state.is_pending = function () { reload_state.is_pending = function () {

View File

@ -107,12 +107,12 @@ run_test("robust_uri_decode", () => {
assert.equal(util.robust_uri_decode("xxx%3"), "xxx"); assert.equal(util.robust_uri_decode("xxx%3"), "xxx");
set_global("decodeURIComponent", () => { set_global("decodeURIComponent", () => {
throw "foo"; throw new Error("foo");
}); });
try { try {
util.robust_uri_decode("%E0%A4%A"); util.robust_uri_decode("%E0%A4%A");
} catch (error) { } catch (error) {
assert.equal(error, "foo"); assert.equal(error.message, "foo");
} }
}); });

View File

@ -35,7 +35,7 @@ function immediate(f) {
// Find the files we need to run. // Find the files we need to run.
const files = process.argv.slice(2); const files = process.argv.slice(2);
if (files.length === 0) { if (files.length === 0) {
throw "No tests found"; throw new Error("No tests found");
} }
// Set up our namespace helpers. // Set up our namespace helpers.