mirror of https://github.com/zulip/zulip.git
eslint: Fix unicorn/{new-for-builtins,throw-new-error,error-message}.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/new-for-builtins.md https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/throw-new-error.md https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/error-message.md Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
48f5e5179a
commit
c7cbdba257
|
@ -106,7 +106,7 @@ run_test("basics", () => {
|
||||||
case ".ind-tab":
|
case ".ind-tab":
|
||||||
return ind_tab;
|
return ind_tab;
|
||||||
default:
|
default:
|
||||||
throw Error("unknown selector: " + sel);
|
throw new Error("unknown selector: " + sel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ run_test("basics", () => {
|
||||||
case "<div class='ind-tab' data-tab-key='search-operators' data-tab-id='2' tabindex='0'>translated: Search operators</div>":
|
case "<div class='ind-tab' data-tab-key='search-operators' data-tab-id='2' tabindex='0'>translated: Search operators</div>":
|
||||||
return make_tab(2);
|
return make_tab(2);
|
||||||
default:
|
default:
|
||||||
throw Error("unknown selector: " + sel);
|
throw new Error("unknown selector: " + sel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -405,7 +405,7 @@ run_test("content_typeahead_selected", () => {
|
||||||
// silent mention
|
// silent mention
|
||||||
fake_this.completing = "silent_mention";
|
fake_this.completing = "silent_mention";
|
||||||
compose.warn_if_mentioning_unsubscribed_user = () => {
|
compose.warn_if_mentioning_unsubscribed_user = () => {
|
||||||
throw Error("unexpected call for silent mentions");
|
throw new Error("unexpected call for silent mentions");
|
||||||
};
|
};
|
||||||
|
|
||||||
fake_this.query = "@_kin";
|
fake_this.query = "@_kin";
|
||||||
|
@ -434,7 +434,7 @@ run_test("content_typeahead_selected", () => {
|
||||||
|
|
||||||
// user group mention
|
// user group mention
|
||||||
compose.warn_if_mentioning_unsubscribed_user = () => {
|
compose.warn_if_mentioning_unsubscribed_user = () => {
|
||||||
throw Error("unexpected call for user groups");
|
throw new Error("unexpected call for user groups");
|
||||||
};
|
};
|
||||||
|
|
||||||
fake_this.query = "@back";
|
fake_this.query = "@back";
|
||||||
|
|
|
@ -641,7 +641,7 @@ function make_jquery_helper() {
|
||||||
case "#stream_filters":
|
case "#stream_filters":
|
||||||
return stream_filters;
|
return stream_filters;
|
||||||
default:
|
default:
|
||||||
throw Error("unknown selector: " + selector);
|
throw new Error("unknown selector: " + selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ run_test("test_early_returns", () => {
|
||||||
elem: stub,
|
elem: stub,
|
||||||
handlers: {
|
handlers: {
|
||||||
left_arrow: () => {
|
left_arrow: () => {
|
||||||
throw Error("do not dispatch this with alt key");
|
throw new Error("do not dispatch this with alt key");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -257,7 +257,7 @@ function sort_button(opts) {
|
||||||
case "sort-prop":
|
case "sort-prop":
|
||||||
return opts.prop_name;
|
return opts.prop_name;
|
||||||
default:
|
default:
|
||||||
throw Error("unknown selector: " + sel);
|
throw new Error("unknown selector: " + sel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +685,7 @@ run_test("render item", () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const list = [...Array(100).keys()];
|
const list = [...new Array(100).keys()];
|
||||||
|
|
||||||
let text = "initial";
|
let text = "initial";
|
||||||
const get_item = (item) => ({text: `${text}: ${item}`, value: item});
|
const get_item = (item) => ({text: `${text}: ${item}`, value: item});
|
||||||
|
|
|
@ -749,7 +749,7 @@ run_test("extract_people_from_message", () => {
|
||||||
|
|
||||||
// Get line coverage
|
// Get line coverage
|
||||||
people.__Rewire__("report_late_add", () => {
|
people.__Rewire__("report_late_add", () => {
|
||||||
throw Error("unexpected late add");
|
throw new Error("unexpected late add");
|
||||||
});
|
});
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
|
|
|
@ -279,7 +279,7 @@ run_test("ensure coverage", () => {
|
||||||
// where functions early exit.
|
// where functions early exit.
|
||||||
narrow_state.active = () => false;
|
narrow_state.active = () => false;
|
||||||
pm_list.rebuild_recent = () => {
|
pm_list.rebuild_recent = () => {
|
||||||
throw Error("we should not call rebuild_recent");
|
throw new Error("we should not call rebuild_recent");
|
||||||
};
|
};
|
||||||
pm_list.update_private_messages();
|
pm_list.update_private_messages();
|
||||||
});
|
});
|
||||||
|
|
|
@ -181,7 +181,7 @@ run_test("sender_hover", (override) => {
|
||||||
return "content-html";
|
return "content-html";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Error("unrecognized template: " + fn);
|
throw new Error("unrecognized template: " + fn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ run_test("actions_popover", (override) => {
|
||||||
);
|
);
|
||||||
return "actions-content";
|
return "actions-content";
|
||||||
default:
|
default:
|
||||||
throw Error("unrecognized template: " + fn);
|
throw new Error("unrecognized template: " + fn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -72,15 +72,15 @@ const setup = function () {
|
||||||
server_events.home_view_loaded();
|
server_events.home_view_loaded();
|
||||||
set_global("message_events", {
|
set_global("message_events", {
|
||||||
insert_new_messages() {
|
insert_new_messages() {
|
||||||
throw Error("insert error");
|
throw new Error("insert error");
|
||||||
},
|
},
|
||||||
update_messages() {
|
update_messages() {
|
||||||
throw Error("update error");
|
throw new Error("update error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
set_global("stream_events", {
|
set_global("stream_events", {
|
||||||
update_property() {
|
update_property() {
|
||||||
throw Error("subs update error");
|
throw new Error("subs update error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -318,7 +318,7 @@ run_test("server_history_end_to_end", () => {
|
||||||
// Try getting server history for a second time.
|
// Try getting server history for a second time.
|
||||||
|
|
||||||
channel.get = () => {
|
channel.get = () => {
|
||||||
throw Error("We should not get more data.");
|
throw new Error("We should not get more data.");
|
||||||
};
|
};
|
||||||
|
|
||||||
on_success_called = false;
|
on_success_called = false;
|
||||||
|
|
|
@ -58,7 +58,7 @@ run_test("initialize", () => {
|
||||||
assert.equal(numeric_inputs, undefined);
|
assert.equal(numeric_inputs, undefined);
|
||||||
assert.equal(redirect_to, "/");
|
assert.equal(redirect_to, "/");
|
||||||
} else {
|
} else {
|
||||||
throw Error("Unhandled case");
|
throw new Error("Unhandled case");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ run_test("upload_files", () => {
|
||||||
uppy.addFile = (file) => {
|
uppy.addFile = (file) => {
|
||||||
assert.equal(file.name, "budapest.png");
|
assert.equal(file.name, "budapest.png");
|
||||||
add_file_counter += 1;
|
add_file_counter += 1;
|
||||||
throw Error();
|
throw new Error("some error");
|
||||||
};
|
};
|
||||||
upload.upload_files(uppy, config, files);
|
upload.upload_files(uppy, config, files);
|
||||||
assert.equal(add_file_counter, 1);
|
assert.equal(add_file_counter, 1);
|
||||||
|
|
|
@ -182,7 +182,7 @@ run_test("partial updates", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
replace_content = () => {
|
replace_content = () => {
|
||||||
throw Error("should not replace entire html");
|
throw new Error("should not replace entire html");
|
||||||
};
|
};
|
||||||
|
|
||||||
let patched_html;
|
let patched_html;
|
||||||
|
@ -216,7 +216,7 @@ run_test("partial updates", () => {
|
||||||
|
|
||||||
run_test("eq_array easy cases", () => {
|
run_test("eq_array easy cases", () => {
|
||||||
const bogus_eq = () => {
|
const bogus_eq = () => {
|
||||||
throw Error("we should not be comparing elements");
|
throw new Error("we should not be comparing elements");
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.equal(vdom.eq_array(undefined, undefined, bogus_eq), true);
|
assert.equal(vdom.eq_array(undefined, undefined, bogus_eq), true);
|
||||||
|
|
|
@ -16,7 +16,7 @@ exports.make_zblueslip = function () {
|
||||||
|
|
||||||
// For fatal messages, we should use assert.throws
|
// For fatal messages, we should use assert.throws
|
||||||
lib.fatal = (msg) => {
|
lib.fatal = (msg) => {
|
||||||
throw Error(msg);
|
throw new Error(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store valid test data for options.
|
// Store valid test data for options.
|
||||||
|
@ -30,10 +30,10 @@ exports.make_zblueslip = function () {
|
||||||
|
|
||||||
lib.expect = (name, message, count = 1) => {
|
lib.expect = (name, message, count = 1) => {
|
||||||
if (opts[name] === undefined) {
|
if (opts[name] === undefined) {
|
||||||
throw Error("unexpected arg for expect: " + name);
|
throw new Error("unexpected arg for expect: " + name);
|
||||||
}
|
}
|
||||||
if (count <= 0 && Number.isInteger(count)) {
|
if (count <= 0 && Number.isInteger(count)) {
|
||||||
throw Error("expected count should be a positive integer");
|
throw new Error("expected count should be a positive integer");
|
||||||
}
|
}
|
||||||
const obj = {message, count, expected_count: count};
|
const obj = {message, count, expected_count: count};
|
||||||
lib.test_data[name].push(obj);
|
lib.test_data[name].push(obj);
|
||||||
|
@ -48,7 +48,7 @@ exports.make_zblueslip = function () {
|
||||||
// Only throw this for message types we want to explicitly track.
|
// Only throw this for message types we want to explicitly track.
|
||||||
// For example, we do not want to throw here for debug messages.
|
// For example, we do not want to throw here for debug messages.
|
||||||
if (opts[name]) {
|
if (opts[name]) {
|
||||||
throw Error(`Unexpected '${name}' message: ${message}`);
|
throw new Error(`Unexpected '${name}' message: ${message}`);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,11 @@ exports.make_zblueslip = function () {
|
||||||
for (const obj of lib.test_data[name]) {
|
for (const obj of lib.test_data[name]) {
|
||||||
const message = obj.message;
|
const message = obj.message;
|
||||||
if (obj.count > 0) {
|
if (obj.count > 0) {
|
||||||
throw Error(
|
throw new Error(
|
||||||
`We did not see expected ${obj.expected_count} of '${name}': ${message}`,
|
`We did not see expected ${obj.expected_count} of '${name}': ${message}`,
|
||||||
);
|
);
|
||||||
} else if (obj.count < 0) {
|
} else if (obj.count < 0) {
|
||||||
throw Error(
|
throw new Error(
|
||||||
`We saw ${obj.expected_count - obj.count} (expected ${
|
`We saw ${obj.expected_count - obj.count} (expected ${
|
||||||
obj.expected_count
|
obj.expected_count
|
||||||
}) of '${name}': ${message}`,
|
}) of '${name}': ${message}`,
|
||||||
|
@ -101,14 +101,14 @@ exports.make_zblueslip = function () {
|
||||||
if (message.toString().includes("exception")) {
|
if (message.toString().includes("exception")) {
|
||||||
message = message.toString();
|
message = message.toString();
|
||||||
} else {
|
} else {
|
||||||
throw Error("message should be string: " + message);
|
throw new Error("message should be string: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lib.test_logs[name].push({message, more_info, stack});
|
lib.test_logs[name].push({message, more_info, stack});
|
||||||
const matched_error_message = lib.test_data[name].find((x) => x.message === message);
|
const matched_error_message = lib.test_data[name].find((x) => x.message === message);
|
||||||
const exact_match_fail = !matched_error_message;
|
const exact_match_fail = !matched_error_message;
|
||||||
if (exact_match_fail) {
|
if (exact_match_fail) {
|
||||||
const error = Error(`Invalid ${name} message: "${message}".`);
|
const error = new Error(`Invalid ${name} message: "${message}".`);
|
||||||
error.blueslip = true;
|
error.blueslip = true;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ exports.make_event_store = (selector) => {
|
||||||
if (child_selector === undefined) {
|
if (child_selector === undefined) {
|
||||||
handler = on_functions.get(name);
|
handler = on_functions.get(name);
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
throw Error("no " + name + " handler for " + selector);
|
throw new Error("no " + name + " handler for " + selector);
|
||||||
}
|
}
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ exports.make_event_store = (selector) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
throw Error("no " + name + " handler for " + selector + " " + child_selector);
|
throw new Error("no " + name + " handler for " + selector + " " + child_selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
|
@ -61,7 +61,7 @@ exports.make_event_store = (selector) => {
|
||||||
// .off in code that we test: $(...).off('click', child_sel);
|
// .off in code that we test: $(...).off('click', child_sel);
|
||||||
//
|
//
|
||||||
// So we don't support this for now.
|
// So we don't support this for now.
|
||||||
throw Error("zjquery does not support this call sequence");
|
throw new Error("zjquery does not support this call sequence");
|
||||||
},
|
},
|
||||||
|
|
||||||
on(event_name, ...args) {
|
on(event_name, ...args) {
|
||||||
|
@ -73,7 +73,7 @@ exports.make_event_store = (selector) => {
|
||||||
if (on_functions.has(event_name)) {
|
if (on_functions.has(event_name)) {
|
||||||
console.info("\nEither the app or the test can be at fault here..");
|
console.info("\nEither the app or the test can be at fault here..");
|
||||||
console.info("(sometimes you just want to call $.clear_all_elements();)\n");
|
console.info("(sometimes you just want to call $.clear_all_elements();)\n");
|
||||||
throw Error("dup " + event_name + " handler for " + selector);
|
throw new Error("dup " + event_name + " handler for " + selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
on_functions.set(event_name, handler);
|
on_functions.set(event_name, handler);
|
||||||
|
@ -81,7 +81,7 @@ exports.make_event_store = (selector) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length !== 2) {
|
if (args.length !== 2) {
|
||||||
throw Error("wrong number of arguments passed in");
|
throw new Error("wrong number of arguments passed in");
|
||||||
}
|
}
|
||||||
|
|
||||||
const [sel, handler] = args;
|
const [sel, handler] = args;
|
||||||
|
@ -95,7 +95,7 @@ exports.make_event_store = (selector) => {
|
||||||
const child_on = child_on_functions.get(sel);
|
const child_on = child_on_functions.get(sel);
|
||||||
|
|
||||||
if (child_on.has(event_name)) {
|
if (child_on.has(event_name)) {
|
||||||
throw Error("dup " + event_name + " handler for " + selector + " " + sel);
|
throw new Error("dup " + event_name + " handler for " + selector + " " + sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
child_on.set(event_name, handler);
|
child_on.set(event_name, handler);
|
||||||
|
@ -213,7 +213,7 @@ exports.make_new_elem = function (selector, opts) {
|
||||||
if (opts.silent) {
|
if (opts.silent) {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
throw Error("Cannot find " + child_selector + " in " + selector);
|
throw new Error("Cannot find " + child_selector + " in " + selector);
|
||||||
},
|
},
|
||||||
get(idx) {
|
get(idx) {
|
||||||
// We have some legacy code that does $('foo').get(0).
|
// We have some legacy code that does $('foo').get(0).
|
||||||
|
@ -408,7 +408,7 @@ exports.make_zjquery = function (opts) {
|
||||||
const error =
|
const error =
|
||||||
"\nInstead of doing equality checks on a full object, " +
|
"\nInstead of doing equality checks on a full object, " +
|
||||||
'do `assert_equal(foo.selector, ".some_class")\n';
|
'do `assert_equal(foo.selector, ".some_class")\n';
|
||||||
throw Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const val = target[key];
|
const val = target[key];
|
||||||
|
@ -417,7 +417,7 @@ exports.make_zjquery = function (opts) {
|
||||||
// For undefined values, we'll throw errors to devs saying
|
// For undefined values, we'll throw errors to devs saying
|
||||||
// they need to create stubs. We ignore certain keys that
|
// they need to create stubs. We ignore certain keys that
|
||||||
// are used for simply printing out the object.
|
// are used for simply printing out the object.
|
||||||
throw Error('You must create a stub for $("' + selector + '").' + key);
|
throw new Error('You must create a stub for $("' + selector + '").' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
@ -457,14 +457,14 @@ exports.make_zjquery = function (opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg2 !== undefined) {
|
if (arg2 !== undefined) {
|
||||||
throw Error("We only use one-argument variations of $(...) in Zulip code.");
|
throw new Error("We only use one-argument variations of $(...) in Zulip code.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const selector = arg;
|
const selector = arg;
|
||||||
|
|
||||||
if (typeof selector !== "string") {
|
if (typeof selector !== "string") {
|
||||||
console.info(arg);
|
console.info(arg);
|
||||||
throw Error("zjquery does not know how to wrap this object yet");
|
throw new Error("zjquery does not know how to wrap this object yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
const valid_selector =
|
const valid_selector =
|
||||||
|
|
|
@ -237,7 +237,7 @@ exports.warn = function blueslip_warn(msg, more_info) {
|
||||||
|
|
||||||
exports.error = function blueslip_error(msg, more_info, stack) {
|
exports.error = function blueslip_error(msg, more_info, stack) {
|
||||||
if (stack === undefined) {
|
if (stack === undefined) {
|
||||||
stack = Error().stack;
|
stack = new Error().stack;
|
||||||
}
|
}
|
||||||
const args = build_arg_list(msg, more_info);
|
const args = build_arg_list(msg, more_info);
|
||||||
logger.error(...args);
|
logger.error(...args);
|
||||||
|
|
|
@ -25,7 +25,7 @@ exports.get_translated_status = function (file) {
|
||||||
|
|
||||||
exports.get_item = function (key, config) {
|
exports.get_item = function (key, config) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
throw Error("Missing config");
|
throw new Error("Missing config");
|
||||||
}
|
}
|
||||||
if (config.mode === "compose") {
|
if (config.mode === "compose") {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
@ -50,11 +50,11 @@ exports.get_item = function (key, config) {
|
||||||
case "markdown_preview_hide_button":
|
case "markdown_preview_hide_button":
|
||||||
return $("#undo_markdown_preview");
|
return $("#undo_markdown_preview");
|
||||||
default:
|
default:
|
||||||
throw Error(`Invalid key name for mode "${config.mode}"`);
|
throw new Error(`Invalid key name for mode "${config.mode}"`);
|
||||||
}
|
}
|
||||||
} else if (config.mode === "edit") {
|
} else if (config.mode === "edit") {
|
||||||
if (!config.row) {
|
if (!config.row) {
|
||||||
throw Error("Missing row in config");
|
throw new Error("Missing row in config");
|
||||||
}
|
}
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "textarea":
|
case "textarea":
|
||||||
|
@ -80,10 +80,10 @@ exports.get_item = function (key, config) {
|
||||||
case "markdown_preview_hide_button":
|
case "markdown_preview_hide_button":
|
||||||
return $("#undo_markdown_preview_" + config.row);
|
return $("#undo_markdown_preview_" + config.row);
|
||||||
default:
|
default:
|
||||||
throw Error(`Invalid key name for mode "${config.mode}"`);
|
throw new Error(`Invalid key name for mode "${config.mode}"`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Error("Invalid upload mode!");
|
throw new Error("Invalid upload mode!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,7 @@ add_example("remove_subscriptions", "/users/me/subscriptions:delete", 200, async
|
||||||
|
|
||||||
add_example("update_message_flags", "/messages/flags:post", 200, async (client) => {
|
add_example("update_message_flags", "/messages/flags:post", 200, async (client) => {
|
||||||
// Send 3 messages to run this example on
|
// Send 3 messages to run this example on
|
||||||
const message_ids = [...Array(3)];
|
const message_ids = [...new Array(3)];
|
||||||
for (let i = 0; i < message_ids.length; i = i + 1) {
|
for (let i = 0; i < message_ids.length; i = i + 1) {
|
||||||
message_ids[i] = await send_test_message(client);
|
message_ids[i] = await send_test_message(client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue