diff --git a/.eslintrc.json b/.eslintrc.json index 50a1da790e..6e46a9573c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js index 64d445fc97..59e17dc961 100644 --- a/frontend_tests/node_tests/billing_helpers.js +++ b/frontend_tests/node_tests/billing_helpers.js @@ -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", {}); diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index 55c882c257..cbf5098701 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -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", () => { diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 1b39f11e5c..17998c0a08 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -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; diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index 19c0fd3c8e..dc0cc29b09 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -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%)"}); diff --git a/frontend_tests/puppeteer_lib/common.js b/frontend_tests/puppeteer_lib/common.js index ff8db1f020..091a8106a9 100644 --- a/frontend_tests/puppeteer_lib/common.js +++ b/frontend_tests/puppeteer_lib/common.js @@ -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 diff --git a/frontend_tests/puppeteer_tests/02-message-basics.js b/frontend_tests/puppeteer_tests/02-message-basics.js index 1bae1300a2..c456aa7376 100644 --- a/frontend_tests/puppeteer_tests/02-message-basics.js +++ b/frontend_tests/puppeteer_tests/02-message-basics.js @@ -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"); diff --git a/frontend_tests/puppeteer_tests/08-admin.js b/frontend_tests/puppeteer_tests/08-admin.js index 890dbe73fd..0a615cb9b4 100644 --- a/frontend_tests/puppeteer_tests/08-admin.js +++ b/frontend_tests/puppeteer_tests/08-admin.js @@ -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); } diff --git a/frontend_tests/puppeteer_tests/14-copy-and-paste.js b/frontend_tests/puppeteer_tests/14-copy-and-paste.js index 28a222f7e1..1134c0be11 100644 --- a/frontend_tests/puppeteer_tests/14-copy-and-paste.js +++ b/frontend_tests/puppeteer_tests/14-copy-and-paste.js @@ -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"); diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 4b8e5b43ea..ab1022e3cd 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -97,7 +97,7 @@ try { } namespace.restore(); - Handlebars.HandlebarsEnvironment(); + Handlebars.HandlebarsEnvironment.call(Handlebars); }); } catch (error) { if (error.stack) { diff --git a/static/js/compose.js b/static/js/compose.js index cd5035eebc..6568a681ed 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -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) { diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 6b3f129b12..4be6b914ca 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -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) { diff --git a/static/js/dropdown_list_widget.js b/static/js/dropdown_list_widget.js index ee93889c58..a8ce68a7d7 100644 --- a/static/js/dropdown_list_widget.js +++ b/static/js/dropdown_list_widget.js @@ -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, }); diff --git a/static/js/message_list.js b/static/js/message_list.js index 60a75fc06e..b3b7d42afb 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -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() { diff --git a/static/js/server_events.js b/static/js/server_events.js index 560600fe51..73b59a6435 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -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; }; diff --git a/static/js/upload.js b/static/js/upload.js index ea38103152..c0a4ae5a45 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -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: { diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js index 7794cd9af3..00ab2dcf9b 100644 --- a/zerver/openapi/javascript_examples.js +++ b/zerver/openapi/javascript_examples.js @@ -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 = { diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index f9a60dcd36..864adeb64a 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -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: