eslint: Fix new-cap errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-12-10 19:26:23 -08:00
parent f84fd0839d
commit 2c5e9f65f8
18 changed files with 39 additions and 46 deletions

View File

@ -38,12 +38,7 @@
}
],
"import/unambiguous": "error",
"new-cap": [
"error",
{
"capIsNew": false
}
],
"new-cap": "error",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "error",

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert");
const fs = require("fs");
const JQuery = require("jquery");
const jQueryFactory = require("jquery");
const {JSDOM} = require("jsdom");
const {set_global, zrequire} = require("../zjsunit/namespace");
@ -12,7 +12,7 @@ const {make_zjquery} = require("../zjsunit/zjquery");
const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8");
const dom = new JSDOM(template, {pretendToBeVisual: true});
const jquery = JQuery(dom.window);
const jquery = jQueryFactory(dom.window);
set_global("$", make_zjquery());
set_global("page_params", {});

View File

@ -37,7 +37,7 @@ const createPasteEvent = function () {
const clipboardData = new DataTransfer();
const pasteEvent = new window.Event("paste");
pasteEvent.clipboardData = clipboardData;
return $.Event(pasteEvent);
return new $.Event(pasteEvent);
};
run_test("paste_handler", () => {

View File

@ -173,7 +173,7 @@ run_test("hash_interactions", () => {
]);
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events([
"overlays.close_for_hash_change",
"message_viewport.stop_auto_scrolling",
@ -185,7 +185,7 @@ run_test("hash_interactions", () => {
window.location.hash = "#narrow/stream/Denmark";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events([
"overlays.close_for_hash_change",
"message_viewport.stop_auto_scrolling",
@ -199,7 +199,7 @@ run_test("hash_interactions", () => {
window.location.hash = "#narrow";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events([
"overlays.close_for_hash_change",
"message_viewport.stop_auto_scrolling",
@ -213,43 +213,43 @@ run_test("hash_interactions", () => {
window.location.hash = "#streams/whatever";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "subs.launch"]);
window.location.hash = "#keyboard-shortcuts/whatever";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "info: keyboard-shortcuts"]);
window.location.hash = "#message-formatting/whatever";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "info: message-formatting"]);
window.location.hash = "#search-operators/whatever";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "info: search-operators"]);
window.location.hash = "#drafts";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "drafts.launch"]);
window.location.hash = "#settings/alert-words";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "settings.launch"]);
window.location.hash = "#organization/user-list-admin";
helper.clear_events();
$(window).trigger($.Event("hashchange", {}));
$(window).trigger("hashchange");
helper.assert_events(["overlays.close_for_hash_change", "admin.launch"]);
let called_back;

View File

@ -208,7 +208,7 @@ run_test("initialize", () => {
};
search_query_box.val("test string");
narrow_state.search_string = () => "ver";
search_query_box.trigger($.Event("blur", stub_event));
search_query_box.trigger(new $.Event("blur", stub_event));
assert.equal(search_query_box.val(), "test string");
searchbox.css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});

View File

@ -435,7 +435,7 @@ class CommonUtils {
$(field_selector)
.trigger("focus")
.val(str)
.trigger($.Event("keyup", {which: 0}));
.trigger(new $.Event("keyup", {which: 0}));
// Trigger the typeahead.
// Reaching into the guts of Bootstrap Typeahead like this is not

View File

@ -255,8 +255,8 @@ async function test_search_venice(page) {
.expectOne()
.trigger("focus")
.val("vEnI") // Must be case insensitive.
.trigger($.Event("input"))
.trigger($.Event("click"));
.trigger("input")
.trigger("click");
});
await page.waitForSelector(await get_stream_li(page, "Denmark"), {hidden: true});
@ -267,7 +267,7 @@ async function test_search_venice(page) {
// Clearing list gives back all the streams in the list
await page.evaluate(() =>
$(".stream-list-filter").expectOne().trigger("focus").val("").trigger($.Event("input")),
$(".stream-list-filter").expectOne().trigger("focus").val("").trigger("input"),
);
await page.waitForSelector(await get_stream_li(page, "Denmark"), {visible: true});
await page.waitForSelector(await get_stream_li(page, "Venice"), {visible: true});
@ -292,7 +292,7 @@ async function test_stream_search_filters_stream_list(page) {
// Enter the search box and test highlighted suggestion
await page.evaluate(() =>
$(".stream-list-filter").expectOne().trigger("focus").trigger($.Event("click")),
$(".stream-list-filter").expectOne().trigger("focus").trigger("click"),
);
await page.waitForSelector("#stream_filters .highlighted_stream", {visible: true});
@ -327,7 +327,7 @@ async function test_stream_search_filters_stream_list(page) {
// Search for brginning of "Verona".
await page.evaluate(() =>
$(".stream-list-filter").expectOne().trigger("focus").val("ver").trigger($.Event("input")),
$(".stream-list-filter").expectOne().trigger("focus").val("ver").trigger("input"),
);
await page.waitForSelector(await get_stream_li(page, "Denmark"), {hidden: true});
await page.click(await get_stream_li(page, "Verona"));
@ -365,9 +365,7 @@ async function test_users_search(page) {
await assert_in_list(page, "aaron");
// Enter the search box and test selected suggestion navigation
await page.evaluate(() =>
$("#user_filter_icon").expectOne().trigger("focus").trigger($.Event("click")),
);
await page.evaluate(() => $("#user_filter_icon").expectOne().trigger("focus").trigger("click"));
await page.waitForSelector("#user_presences .highlighted_user", {visible: true});
await assert_selected(page, "Desdemona");
await assert_not_selected(page, "Cordelia Lear");

View File

@ -239,7 +239,7 @@ async function get_suggestions(page, str) {
$(".create_default_stream")
.trigger("focus")
.val(str)
.trigger($.Event("keyup", {which: 0}));
.trigger(new $.Event("keyup", {which: 0}));
}, str);
}

View File

@ -24,7 +24,7 @@ async function copy_messages(page, start_message, end_message) {
$("#copytempdiv").remove();
// emulate copy event
$("body").trigger($.Event("keydown", {which: 67, ctrlKey: true}));
$("body").trigger(new $.Event("keydown", {which: 67, ctrlKey: true}));
// find temp div with copied text
const temp_div = $("#copytempdiv");

View File

@ -97,7 +97,7 @@ try {
}
namespace.restore();
Handlebars.HandlebarsEnvironment();
Handlebars.HandlebarsEnvironment.call(Handlebars);
});
} catch (error) {
if (error.stack) {

View File

@ -425,7 +425,7 @@ exports.do_post_send_tasks = function () {
exports.clear_preview_area();
// TODO: Do we want to fire the event even if the send failed due
// to a server-side error?
$(document).trigger($.Event("compose_finished.zulip"));
$(document).trigger("compose_finished.zulip");
};
exports.update_email = function (user_id, new_email) {

View File

@ -119,7 +119,7 @@ exports.complete_starting_tasks = function (msg_type, opts) {
ui_util.change_tab_to("#message_feed_container");
compose_fade.start_compose(msg_type);
ui_util.decorate_stream_bar(opts.stream, $("#stream-message .message_header_stream"), true);
$(document).trigger($.Event("compose_started.zulip", opts));
$(document).trigger(new $.Event("compose_started.zulip", opts));
exports.update_placeholder_text();
};
@ -270,7 +270,7 @@ exports.cancel = function () {
compose.abort_video_callbacks(undefined);
compose_state.set_message_type(false);
compose_pm_pill.clear();
$(document).trigger($.Event("compose_canceled.zulip"));
$(document).trigger("compose_canceled.zulip");
};
exports.respond_to_message = function (opts) {

View File

@ -109,7 +109,7 @@ const DropdownListWidget = function (opts) {
return;
}
e.preventDefault();
const custom_event = jQuery.Event("keydown.dropdown.data-api", {
const custom_event = new jQuery.Event("keydown.dropdown.data-api", {
keyCode: e.keyCode,
which: e.keyCode,
});

View File

@ -197,7 +197,7 @@ class MessageList {
this.view.maybe_rerender();
}
$(document).trigger($.Event("message_selected.zulip", opts));
$(document).trigger(new $.Event("message_selected.zulip", opts));
}
reselect_selected_id() {

View File

@ -299,7 +299,7 @@ exports.check_for_unsuspend = function () {
watchdog_time = new_time;
// Our app's JS wasn't running, which probably means the machine was
// asleep.
$(document).trigger($.Event("unsuspend"));
$(document).trigger("unsuspend");
}
watchdog_time = new_time;
};

View File

@ -172,7 +172,7 @@ exports.upload_files = function (uppy, config, files) {
};
exports.setup_upload = function (config) {
const uppy = Uppy({
const uppy = new Uppy({
debug: false,
autoProceed: true,
restrictions: {

View File

@ -13,7 +13,7 @@
that the documented examples are all correct, runnable code.
*/
const ExamplesHandler = function () {
const examples_handler = function () {
const config = {
username: process.env.ZULIP_USERNAME,
apiKey: process.env.ZULIP_API_KEY,
@ -47,8 +47,8 @@ const ExamplesHandler = function () {
};
const main = async () => {
const Zulip = require("zulip-js");
const client = await Zulip(config);
const zulipInit = require("zulip-js");
const client = await zulipInit(config);
await generate_validation_data(client, examples.send_message);
await generate_validation_data(client, examples.create_user);
@ -90,7 +90,7 @@ const ExamplesHandler = function () {
};
};
const {main, add_example} = ExamplesHandler();
const {main, add_example} = examples_handler();
const send_test_message = async (client) => {
const params = {

View File

@ -46,7 +46,7 @@ client = zulip.Client(config_file="~/zuliprc-admin")
"""
JS_CLIENT_CONFIG = """
const Zulip = require('zulip-js');
const zulipInit = require('zulip-js');
// Pass the path to your zuliprc file here.
const config = { zuliprc: 'zuliprc' };
@ -54,7 +54,7 @@ const config = { zuliprc: 'zuliprc' };
"""
JS_CLIENT_ADMIN_CONFIG = """
const Zulip = require('zulip-js');
const zulipInit = require('zulip-js');
// The user for this zuliprc file must be an organization administrator.
const config = { zuliprc: 'zuliprc-admin' };
@ -156,7 +156,7 @@ def render_javascript_code_example(function: str, admin_config: bool=False,
code_example.append('```js')
code_example.extend(config)
for snippet in snippets:
code_example.append("Zulip(config).then(async (client) => {")
code_example.append("zulipInit(config).then(async (client) => {")
for line in snippet:
result = re.search('const result.*=(.*);', line)
if result: