diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js index 3bd1435315..7074030b65 100644 --- a/frontend_tests/node_tests/common.js +++ b/frontend_tests/node_tests/common.js @@ -101,25 +101,25 @@ run_test("adjust_mac_shortcuts", () => { return false; }; key_no = 1; - keys_to_test_non_mac.forEach((value, key) => { + for (const [key, value] of keys_to_test_non_mac) { keys_elem_list.push(get_key_stub_html(key, value, "hotkey_non_mac_" + key_no)); key_no += 1; - }); + } common.adjust_mac_shortcuts(".markdown_content"); - keys_elem_list.forEach((key_elem) => { + for (const key_elem of keys_elem_list) { assert(key_elem.text(), key_elem.expected_key()); - }); + } keys_elem_list = []; key_no = 1; common.has_mac_keyboard = function () { return true; }; - keys_to_test_mac.forEach((value, key) => { + for (const [key, value] of keys_to_test_mac) { keys_elem_list.push(get_key_stub_html(key, value, "hotkey_" + key_no)); key_no += 1; - }); + } $(".markdown_content").each = (f) => { for (const key_elem of keys_elem_list) { @@ -127,9 +127,9 @@ run_test("adjust_mac_shortcuts", () => { } }; common.adjust_mac_shortcuts(".markdown_content"); - keys_elem_list.forEach((key_elem) => { + for (const key_elem of keys_elem_list) { assert.equal(key_elem.text(), key_elem.expected_key()); - }); + } const markdown_hotkey_1 = get_key_stub_html( "Ctrl + Backspace", diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 7b23251cb4..ad9c087da6 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -1338,13 +1338,13 @@ run_test("begins_typeahead", () => { assert_typeahead_equals("```test", "ing", false); assert_typeahead_equals("~~~test", "ing", false); const terminal_symbols = ",.;?!()[]> \"'\n\t"; - terminal_symbols.split().forEach((symbol) => { + for (const symbol of terminal_symbols.split()) { assert_stream_list("#test", symbol); assert_typeahead_equals("@test", symbol, all_mentions); assert_typeahead_equals(":test", symbol, emoji_list); assert_typeahead_equals("```test", symbol, lang_list); assert_typeahead_equals("~~~test", symbol, lang_list); - }); + } }); run_test("tokenizing", () => { diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index aabbae962b..5a230b2e42 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -1481,9 +1481,9 @@ run_test("navbar_helpers", () => { }, ]; - test_cases.forEach((test_case) => { + for (const test_case of test_cases) { test_helpers(test_case); - }); + } // TODO: these may be removed, based on design decisions const sender_me = [{operator: "sender", operand: "me"}]; @@ -1504,9 +1504,9 @@ run_test("navbar_helpers", () => { }, ]; - redirect_edge_cases.forEach((test_case) => { + for (const test_case of redirect_edge_cases) { test_redirect_url_with_search(test_case); - }); + } // TODO: test every single one of the "ALL" redirects from the navbar behaviour table diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index b5d5b5fa36..d666077796 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -235,22 +235,22 @@ run_test("markdown_detection", () => { "YouTube URL https://www.youtube.com/watch?v=HHZ8iqswiCw&feature=youtu.be&a", ]; - no_markup.forEach((content) => { + for (const content of no_markup) { assert.equal(markdown.contains_backend_only_syntax(content), false); - }); + } - markup.forEach((content) => { + for (const content of markup) { assert.equal(markdown.contains_backend_only_syntax(content), true); - }); + } }); run_test("marked_shared", () => { const tests = markdown_test_cases.regular_tests; - tests.forEach((test) => { + for (const test of tests) { // Ignore tests if specified if (test.ignore === true) { - return; + continue; } const message = {raw_content: test.input}; @@ -266,7 +266,7 @@ run_test("marked_shared", () => { } else { markdown_assert.equal(test.expected_output, output, error_message); } - }); + } }); run_test("message_flags", () => { @@ -531,7 +531,7 @@ run_test("marked", () => { }, ]; - test_cases.forEach((test_case) => { + for (const test_case of test_cases) { // Disable emoji conversion by default. page_params.translate_emoticons = test_case.translate_emoticons || false; @@ -542,7 +542,7 @@ run_test("marked", () => { markdown.apply_markdown(message); const output = message.content; assert.equal(output, expected); - }); + } }); run_test("topic_links", () => { @@ -671,9 +671,9 @@ run_test("backend_only_realm_filters", () => { "Here is the PR-#123.", "Function abc() was introduced in (PR)#123.", ]; - backend_only_realm_filters.forEach((content) => { + for (const content of backend_only_realm_filters) { assert.equal(markdown.contains_backend_only_syntax(content), true); - }); + } }); run_test("python_to_js_filter", () => { diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 54b7714cae..ec1a8c4363 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -170,14 +170,14 @@ run_test("message_booleans_parity", () => { const update_message = {topic: "update_booleans"}; message_store.set_message_booleans(set_message); message_store.update_booleans(update_message, flags); - Object.keys(expected_message).forEach((key) => { + for (const key of Object.keys(expected_message)) { assert.equal( set_message[key], expected_message[key], `'${key}' != ${expected_message[key]}`, ); assert.equal(update_message[key], expected_message[key]); - }); + } assert.equal(set_message.topic, "set_message_booleans"); assert.equal(update_message.topic, "update_booleans"); }; diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js index e5acec1efa..183acb9ae6 100644 --- a/frontend_tests/node_tests/rendered_markdown.js +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -59,9 +59,9 @@ stream_data.add_sub(stream); const $array = (array) => { const each = (func) => { - array.forEach((e) => { + for (const e of array) { func.call(e); - }); + } }; return {each}; }; diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 0c545800de..8f7f36e13e 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -1018,10 +1018,10 @@ run_test("misc", () => { ".dropdown_list_reset_button:enabled", $.create(""), ); - widget_settings.forEach((name) => { + for (const name of widget_settings) { const elem = $.create(`#${name}_widget #${name}_name`); elem.closest = () => dropdown_list_parent; - }); + } // We do not define any settings we need in page_params yet, but we don't need to for this test. blueslip.expect( diff --git a/frontend_tests/node_tests/spoilers.js b/frontend_tests/node_tests/spoilers.js index 5876677239..4632f329fc 100644 --- a/frontend_tests/node_tests/spoilers.js +++ b/frontend_tests/node_tests/spoilers.js @@ -12,9 +12,9 @@ zrequire("spoilers"); // This function is taken from rendered_markdown.js and slightly modified. const $array = (array) => { const each = (func) => { - array.forEach((elem, index) => { + for (const [index, elem] of array.entries()) { func.call(this, index, elem); - }); + } }; return {each}; }; diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index 42efea3b56..e9a1f4188e 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -115,7 +115,9 @@ run_test("sort_streams", () => { ]; process_test_streams(); - test_streams.forEach(stream_data.update_calculated_fields); + for (const sub of test_streams) { + stream_data.update_calculated_fields(sub); + } test_streams = th.sort_streams(test_streams, "wr"); assert.deepEqual(test_streams[0].name, "Docs"); // Description match assert.deepEqual(test_streams[1].name, "Denmark"); // Popular stream diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index ab1022e3cd..12dcdb1f05 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -75,7 +75,7 @@ function run_one_module(file) { test.set_verbose(files.length === 1); try { - files.forEach((file) => { + for (const file of files) { namespace.set_global("window", window); namespace.set_global("to_$", () => window); namespace.set_global("location", { @@ -98,7 +98,7 @@ try { namespace.restore(); Handlebars.HandlebarsEnvironment.call(Handlebars); - }); + } } catch (error) { if (error.stack) { console.info(short_tb(error.stack)); diff --git a/frontend_tests/zjsunit/markdown_assert.js b/frontend_tests/zjsunit/markdown_assert.js index 49566cbd7f..445daa225e 100644 --- a/frontend_tests/zjsunit/markdown_assert.js +++ b/frontend_tests/zjsunit/markdown_assert.js @@ -76,9 +76,9 @@ class MarkdownComparer { } // If put in above forEach loop, causes issues (possible nodes.attribute invalidation?) - attributeList.forEach((attr) => { + for (const attr of attributeList) { node.removeAttribute(attr.name); - }); + } attributeList.sort((a, b) => { const name_a = a.name; @@ -92,9 +92,9 @@ class MarkdownComparer { }); // Put them back in, in order - attributeList.forEach((attribute) => { + for (const attribute of attributeList) { node.setAttribute(attribute.name, attribute.value); - }); + } if (node.hasChildNodes()) { for (const childNode of node.children) { diff --git a/frontend_tests/zjsunit/mdiff.js b/frontend_tests/zjsunit/mdiff.js index 464fe0ee6b..2c6996558e 100644 --- a/frontend_tests/zjsunit/mdiff.js +++ b/frontend_tests/zjsunit/mdiff.js @@ -25,7 +25,7 @@ function apply_color(input_string, changes) { ["insert", (string) => "\u001B[32m" + string + "\u001B[0m"], ["replace", (string) => "\u001B[33m" + string + "\u001B[0m"], ]); - changes.forEach((change) => { + for (const change of changes) { if (formatter.has(change.tag)) { processed_string += input_string.slice(previous_index, change.beginning_index); processed_string += formatter.get(change.tag)( @@ -33,7 +33,7 @@ function apply_color(input_string, changes) { ); previous_index = change.ending_index; } - }); + } processed_string += input_string.slice(previous_index); return processed_string; @@ -102,7 +102,7 @@ function diff_strings(string_0, string_1) { ndiff_output = difflib.ndiff(string_0.split("\n"), string_1.split("\n")); - ndiff_output.forEach((line) => { + for (const line of ndiff_output) { if (line.startsWith("+")) { output_lines.push(line); } else if (line.startsWith("-")) { @@ -116,7 +116,7 @@ function diff_strings(string_0, string_1) { } else { output_lines.push(line); } - }); + } const emphasize_codes = (string) => "\u001B[34m" + string.slice(0, 1) + "\u001B[0m" + string.slice(1); diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 10cafc89fe..77a69512e8 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -61,9 +61,9 @@ exports.clear_zulip_refs = function () { }; exports.restore = function () { - requires.forEach((fn) => { + for (const fn of requires) { delete require.cache[require.resolve(fn)]; - }); + } Object.assign(global, old_globals); old_globals = {}; for (const name of new_globals) { diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 3ece134d58..cf4ce0e8bc 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -300,9 +300,9 @@ exports.make_new_elem = function (selector, opts) { }, removeClass(class_names) { class_names = class_names.split(" "); - class_names.forEach((class_name) => { + for (const class_name of class_names) { classes.delete(class_name); - }); + } return self; }, remove() { diff --git a/static/js/billing/helpers.js b/static/js/billing/helpers.js index 2435844620..06e63a873c 100644 --- a/static/js/billing/helpers.js +++ b/static/js/billing/helpers.js @@ -32,13 +32,13 @@ exports.create_ajax_request = function ( data.stripe_token = JSON.stringify(stripe_token.id); } - form.serializeArray().forEach((item) => { + for (const item of form.serializeArray()) { if (numeric_inputs.includes(item.name)) { data[item.name] = item.value; } else { data[item.name] = JSON.stringify(item.value); } - }); + } $.post({ url, diff --git a/static/js/color_data.js b/static/js/color_data.js index e62eff0441..a0fa34125d 100644 --- a/static/js/color_data.js +++ b/static/js/color_data.js @@ -55,7 +55,9 @@ exports.claim_color = function (color) { exports.claim_colors = function (subs) { const colors = new Set(subs.map((sub) => sub.color)); - colors.forEach(exports.claim_color); + for (const color of colors) { + exports.claim_color(color); + } }; exports.pick_color = function () { diff --git a/static/js/components.js b/static/js/components.js index 7e44b97463..07058d92bc 100644 --- a/static/js/components.js +++ b/static/js/components.js @@ -20,7 +20,7 @@ exports.toggle = function (opts) { // classes need to be added for correct alignment or other purposes _component.addClass(opts.html_class); } - opts.values.forEach((value, i) => { + for (const [i, value] of opts.values.entries()) { // create a tab with a tab-id so they don't have to be referenced // by text value which can be inconsistent. const tab = $( @@ -43,7 +43,7 @@ exports.toggle = function (opts) { tab.addClass("middle"); } _component.append(tab); - }); + } return _component; })(opts); diff --git a/static/js/debug.js b/static/js/debug.js index 94b7b8bcc1..a32bc43231 100644 --- a/static/js/debug.js +++ b/static/js/debug.js @@ -23,7 +23,7 @@ export function check_duplicate_ids() { const collisions = []; let total_collisions = 0; - Array.prototype.slice.call(document.querySelectorAll("*")).forEach((o) => { + for (const o of Array.prototype.slice.call(document.querySelectorAll("*"))) { if (o.id && ids.has(o.id)) { const el = collisions.find((c) => c.id === o.id); @@ -53,7 +53,7 @@ export function check_duplicate_ids() { } else if (o.id) { ids.add(o.id); } - }); + } return { collisions, diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index decc522b4a..215a791661 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -546,11 +546,11 @@ exports.emoji_select_tab = function (elt) { const scrollheight = elt.prop("scrollHeight"); const elt_height = elt.height(); let currently_selected = ""; - section_head_offsets.forEach((o) => { + for (const o of section_head_offsets) { if (scrolltop + elt_height / 2 >= o.position_y) { currently_selected = o.section; } - }); + } // Handles the corner case of the last category being // smaller than half of the emoji picker height. if (elt_height + scrolltop === scrollheight) { diff --git a/static/js/hotspots.js b/static/js/hotspots.js index a926e69836..92c5901d95 100644 --- a/static/js/hotspots.js +++ b/static/js/hotspots.js @@ -235,7 +235,7 @@ function insert_hotspot_into_DOM(hotspot) { } // reposition on any event that might update the UI - ["resize", "scroll", "onkeydown", "click"].forEach((event_name) => { + for (const event_name of ["resize", "scroll", "onkeydown", "click"]) { window.addEventListener( event_name, _.debounce(() => { @@ -245,7 +245,7 @@ function insert_hotspot_into_DOM(hotspot) { }, 10), true, ); - }); + } }, hotspot.delay * 1000); } @@ -278,10 +278,10 @@ function close_read_hotspots(new_hotspots) { exports.load_new = function (new_hotspots) { close_read_hotspots(new_hotspots); - new_hotspots.forEach((hotspot) => { + for (const hotspot of new_hotspots) { hotspot.location = HOTSPOT_LOCATIONS.get(hotspot.name); - }); - new_hotspots.forEach(insert_hotspot_into_DOM); + insert_hotspot_into_DOM(hotspot); + } }; exports.initialize = function () { diff --git a/static/js/input_pill.js b/static/js/input_pill.js index a62fae7aef..0743503a68 100644 --- a/static/js/input_pill.js +++ b/static/js/input_pill.js @@ -198,15 +198,12 @@ exports.create = function (opts) { // this is an array to push all the errored values to, so it's drafts // of pills for the user to fix. - const drafts = []; - - pills.forEach((pill) => { - // if this returns `false`, it erroed and we should push it to - // the draft pills. - if (funcs.appendPill(pill) === false) { - drafts.push(pill); - } - }); + const drafts = pills.filter( + (pill) => + // if this returns `false`, it erroed and we should push it to + // the draft pills. + funcs.appendPill(pill) === false, + ); store.$input.text(drafts.join(", ")); // when using the `text` insertion feature with jQuery the caret is diff --git a/static/js/invite.js b/static/js/invite.js index 9c453aeedf..7c1f92001b 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -76,14 +76,14 @@ function submit_invitation_form() { const invitee_emails_errored = []; const error_list = []; let is_invitee_deactivated = false; - arr.errors.forEach((value) => { + for (const value of arr.errors) { const [email, error_message, deactivated] = value; error_list.push(`${email}: ${error_message}`); if (deactivated) { is_invitee_deactivated = true; } invitee_emails_errored.push(email); - }); + } const error_response = render_invitation_failed_error({ error_message: arr.msg, diff --git a/static/js/lightbox.js b/static/js/lightbox.js index d00954fbf2..2070eb51d7 100644 --- a/static/js/lightbox.js +++ b/static/js/lightbox.js @@ -12,7 +12,7 @@ function render_lightbox_list_images(preview_source) { const images = Array.prototype.slice.call($(".focused_table .message_inline_image img")); const $image_list = $("#lightbox_overlay .image-list").html(""); - images.forEach((img) => { + for (const img of images) { const src = img.getAttribute("src"); const className = preview_source === src ? "image selected" : "image"; @@ -28,7 +28,7 @@ function render_lightbox_list_images(preview_source) { // that navigating within the list only needs the `src` // attribute used to construct the node object above. exports.parse_image_data(img); - }, ""); + } } } diff --git a/static/js/localstorage.js b/static/js/localstorage.js index 5196964661..d2c52123f8 100644 --- a/static/js/localstorage.js +++ b/static/js/localstorage.js @@ -68,9 +68,9 @@ const ls = { const key_regex = new RegExp(this.formGetter(version, regex)); const keys = Object.keys(localStorage).filter((key) => key_regex.test(key)); - keys.forEach((key) => { + for (const key of keys) { localStorage.removeItem(key); - }); + } }, // migrate from an older version of a data src to a newer one with a diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index bc1951a0e4..6e49325911 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -34,8 +34,10 @@ function process_result(data, opts) { narrow.show_empty_narrow_message(); } - messages.forEach(message_store.set_message_booleans); - messages = messages.map(message_store.add_message_metadata); + messages = messages.map((message) => { + message_store.set_message_booleans(message); + return message_store.add_message_metadata(message); + }); // In case any of the newly fetched messages are new, add them to // our unread data structures. It's important that this run even diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js index 5315db28a2..9c7a86a800 100644 --- a/static/js/message_list_data.js +++ b/static/js/message_list_data.js @@ -430,7 +430,7 @@ class MessageListData { } _add_to_hash(messages) { - messages.forEach((elem) => { + for (const elem of messages) { const id = Number.parseFloat(elem.id); if (Number.isNaN(id)) { throw new TypeError("Bad message id"); @@ -440,10 +440,10 @@ class MessageListData { } if (this._hash.has(id)) { blueslip.error("Duplicate message added to MessageListData"); - return; + continue; } this._hash.set(id, elem); - }); + } } _is_localonly_id(id) { diff --git a/static/js/message_store.js b/static/js/message_store.js index 0912678586..452cd075cc 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -43,7 +43,9 @@ exports.get = function get(message_id) { }; exports.each = function (f) { - stored_messages.forEach(f); + for (const [id, message] of stored_messages) { + f(message, id); + } }; exports.get_pm_emails = function (message) { diff --git a/static/js/popovers.js b/static/js/popovers.js index 07b5b1a700..b1858fc70e 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -897,10 +897,10 @@ exports.register_click_handlers = function () { const url_prefix = playground_info[0].url_prefix; view_in_playground_button.attr("href", url_prefix + encodeURIComponent(extracted_code)); } else { - playground_info.forEach(($playground) => { + for (const $playground of playground_info) { $playground.playground_url = $playground.url_prefix + encodeURIComponent(extracted_code); - }); + } exports.toggle_playground_link_popover(this, playground_info); } }); @@ -1309,11 +1309,11 @@ exports.hide_all_except_sidebars = function () { exports.hide_playground_links_popover(); // look through all the popovers that have been added and removed. - list_of_popovers.forEach(($o) => { + for (const $o of list_of_popovers) { if (!document.body.contains($o.$element[0]) && $o.$tip) { $o.$tip.remove(); } - }); + } list_of_popovers = []; }; diff --git a/static/js/portico/integrations.js b/static/js/portico/integrations.js index ad91048fa8..ca84e7bd6d 100644 --- a/static/js/portico/integrations.js +++ b/static/js/portico/integrations.js @@ -11,27 +11,23 @@ const INTEGRATIONS = new Map(); const CATEGORIES = new Map(); function load_data() { - $(".integration-lozenge") - .toArray() - .forEach((integration) => { - const name = $(integration).data("name"); - const display_name = $(integration).find(".integration-name").text().trim(); + for (const integration of $(".integration-lozenge")) { + const name = $(integration).data("name"); + const display_name = $(integration).find(".integration-name").text().trim(); - if (display_name && name) { - INTEGRATIONS.set(name, display_name); - } - }); + if (display_name && name) { + INTEGRATIONS.set(name, display_name); + } + } - $(".integration-category") - .toArray() - .forEach((category) => { - const name = $(category).data("category"); - const display_name = $(category).text().trim(); + for (const category of $(".integration-category")) { + const name = $(category).data("category"); + const display_name = $(category).text().trim(); - if (display_name && name) { - CATEGORIES.set(name, display_name); - } - }); + if (display_name && name) { + CATEGORIES.set(name, display_name); + } + } } const INITIAL_STATE = { @@ -43,27 +39,25 @@ const INITIAL_STATE = { let state = {...INITIAL_STATE}; function adjust_font_sizing() { - $(".integration-lozenge") - .toArray() - .forEach((integration) => { - const $integration_name = $(integration).find(".integration-name"); - const $integration_category = $(integration).find(".integration-category"); + for (const integration of $(".integration-lozenge")) { + const $integration_name = $(integration).find(".integration-name"); + const $integration_category = $(integration).find(".integration-category"); - // if the text has wrapped to two lines, decrease font-size + // if the text has wrapped to two lines, decrease font-size + if ($integration_name.height() > 30) { + $integration_name.css("font-size", "1em"); if ($integration_name.height() > 30) { - $integration_name.css("font-size", "1em"); - if ($integration_name.height() > 30) { - $integration_name.css("font-size", ".95em"); - } + $integration_name.css("font-size", ".95em"); } + } + if ($integration_category.height() > 30) { + $integration_category.css("font-size", ".8em"); if ($integration_category.height() > 30) { - $integration_category.css("font-size", ".8em"); - if ($integration_category.height() > 30) { - $integration_category.css("font-size", ".75em"); - } + $integration_category.css("font-size", ".75em"); } - }); + } + } } function update_path() { @@ -105,8 +99,7 @@ function update_categories() { const update_integrations = _.debounce(() => { const max_scrollY = window.scrollY; - const integrations = $(".integration-lozenges").children().toArray(); - integrations.forEach((integration) => { + for (const integration of $(".integration-lozenges").children()) { const $integration = $(integration).find(".integration-lozenge"); const $integration_category = $integration.find(".integration-category"); @@ -133,7 +126,7 @@ const update_integrations = _.debounce(() => { } document.body.scrollTop = Math.min(window.scrollY, max_scrollY); - }); + } adjust_font_sizing(); }, 50); @@ -151,7 +144,7 @@ function hide_catalog_show_integration() { function show_integration(doc) { $("#integration-instructions-group .name").text(INTEGRATIONS.get(state.integration)); $("#integration-instructions-group .categories .integration-category").remove(); - categories.forEach((category) => { + for (const category of categories) { let link; for (const [name, display_name] of CATEGORIES) { if (display_name === category) { @@ -163,7 +156,7 @@ function hide_catalog_show_integration() { .append('

'); category_el.find(".integration-category").attr("data-category", link).text(category); $("#integration-instructions-group .categories").append(category_el); - }); + } $("#integration-instructions-group").css({ opacity: 0, display: "flex", @@ -305,9 +298,8 @@ function toggle_categories_dropdown() { function integration_events() { $('#integration-search input[type="text"]').on("keypress", (e) => { - const integrations = $(".integration-lozenges").children().toArray(); if (e.which === 13 && e.target.value !== "") { - for (const integration_element of integrations) { + for (const integration_element of $(".integration-lozenges").children()) { const integration = $(integration_element).find(".integration-lozenge"); if ($(integration).css("display") !== "none") { diff --git a/static/js/portico/integrations_dev_panel.js b/static/js/portico/integrations_dev_panel.js index ef56a5d702..410ec02161 100644 --- a/static/js/portico/integrations_dev_panel.js +++ b/static/js/portico/integrations_dev_panel.js @@ -38,7 +38,7 @@ const clear_handlers = { function clear_elements(elements) { // Supports strings (a selector to clear) or calling a function // (for more complex logic). - elements.forEach((element_name) => { + for (const element_name of elements) { const handler = clear_handlers[element_name]; if (typeof handler === "string") { const element_object = $(handler)[0]; @@ -47,7 +47,7 @@ function clear_elements(elements) { } else { handler(); } - }); + } return; } @@ -102,7 +102,7 @@ function set_results(response) { const responses = response.responses; let data = "Results:\n\n"; - responses.forEach((response) => { + for (const response of responses) { if (response.fixture_name !== undefined) { data += "Fixture: " + response.fixture_name; data += "\nStatus Code: " + response.status_code; @@ -110,7 +110,7 @@ function set_results(response) { data += "Status Code: " + response.status_code; } data += "\nResponse: " + response.message + "\n\n"; - }); + } $("#idp-results")[0].value = data; } @@ -142,12 +142,12 @@ function load_fixture_options(integration_name) { const fixtures_options_dropdown = $("#fixture_name")[0]; const fixtures_names = Object.keys(loaded_fixtures.get(integration_name)).sort(); - fixtures_names.forEach((fixture_name) => { + for (const fixture_name of fixtures_names) { const new_dropdown_option = document.createElement("option"); new_dropdown_option.value = fixture_name; new_dropdown_option.innerHTML = fixture_name; fixtures_options_dropdown.add(new_dropdown_option); - }); + } load_fixture_body(fixtures_names[0]); return; diff --git a/static/js/portico/landing-page.js b/static/js/portico/landing-page.js index 10dada3e22..bd0eef25fb 100644 --- a/static/js/portico/landing-page.js +++ b/static/js/portico/landing-page.js @@ -79,11 +79,11 @@ const apps_events = function () { let result; const parts = path_parts(); - Object.keys(info).forEach((version) => { + for (const version of Object.keys(info)) { if (parts.includes(version)) { result = version; } - }); + } result = result || detect_user_os(); return result; diff --git a/static/js/portico/team.js b/static/js/portico/team.js index 8a798a2511..e142cb0607 100644 --- a/static/js/portico/team.js +++ b/static/js/portico/team.js @@ -20,9 +20,9 @@ const loaded_repos = []; function calculate_total_commits(contributor) { let commits = 0; - Object.keys(repo_name_to_tab_name).forEach((repo_name) => { + for (const repo_name of Object.keys(repo_name_to_tab_name)) { commits += contributor[repo_name] || 0; - }); + } return commits; } diff --git a/static/js/server_events.js b/static/js/server_events.js index 73b59a6435..9e8fc347d9 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -102,7 +102,9 @@ function get_events_success(events) { try { messages = echo.process_from_server(messages); if (messages.length > 0) { - messages.forEach(message_store.set_message_booleans); + for (const message of messages) { + message_store.set_message_booleans(message); + } const sent_by_this_client = messages.some((msg) => sent_messages.messages.has(msg.local_id), diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 8d64e57359..909824c7d9 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -345,42 +345,42 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { } } } else if (event.op === "peer_add") { - event.stream_ids.forEach((stream_id) => { + for (const stream_id of event.stream_ids) { const sub = stream_data.get_sub_by_id(stream_id); if (!sub) { blueslip.warn("Cannot find stream for peer_add: " + stream_id); - return; + continue; } - event.user_ids.forEach((user_id) => { + for (const user_id of event.user_ids) { if (!peer_data.add_subscriber(stream_id, user_id)) { blueslip.warn("Cannot process peer_add event"); - return; + continue; } - }); + } subs.update_subscribers_ui(sub); - }); + } compose_fade.update_faded_users(); } else if (event.op === "peer_remove") { - event.stream_ids.forEach((stream_id) => { + for (const stream_id of event.stream_ids) { const sub = stream_data.get_sub_by_id(stream_id); if (!sub) { blueslip.warn("Cannot find stream for peer_remove: " + stream_id); - return; + continue; } - event.user_ids.forEach((user_id) => { + for (const user_id of event.user_ids) { if (!peer_data.remove_subscriber(sub.stream_id, user_id)) { blueslip.warn("Cannot process peer_remove event."); - return; + continue; } - }); + } subs.update_subscribers_ui(sub); - }); + } compose_fade.update_faded_users(); } else if (event.op === "remove") { for (const rec of event.subscriptions) { diff --git a/static/js/settings_account.js b/static/js/settings_account.js index ec2e064e6e..17c8a93791 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -146,7 +146,7 @@ exports.append_custom_profile_fields = function (element_id, user_id) { [all_field_types.URL.id, "url"], ]); - all_custom_fields.forEach((field) => { + for (const field of all_custom_fields) { let field_value = people.get_custom_profile_data(user_id, field.id); const is_choice_field = field.type === all_field_types.CHOICE.id; const field_choices = []; @@ -178,7 +178,7 @@ exports.append_custom_profile_fields = function (element_id, user_id) { field_choices, }); $(element_id).append(html); - }); + } }; exports.initialize_custom_date_type_fields = function (element_id) { @@ -219,7 +219,7 @@ exports.initialize_custom_user_type_fields = function ( return user_pills; } - page_params.custom_profile_fields.forEach((field) => { + for (const field of page_params.custom_profile_fields) { let field_value_raw = people.get_custom_profile_data(user_id, field.id); if (field_value_raw) { @@ -249,10 +249,10 @@ exports.initialize_custom_user_type_fields = function ( if (field_value_raw) { const field_value = JSON.parse(field_value_raw); if (field_value) { - field_value.forEach((pill_user_id) => { + for (const pill_user_id of field_value) { const user = people.get_by_user_id(pill_user_id); user_pill.append_user(user, pills); - }); + } } } @@ -270,7 +270,7 @@ exports.initialize_custom_user_type_fields = function ( } user_pills.set(field.id, pills); } - }); + } return user_pills; }; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 877d946912..d91a95452d 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -644,7 +644,9 @@ exports.build_page = function () { // Populate authentication methods table exports.populate_auth_methods(page_params.realm_authentication_methods); - simple_dropdown_properties.forEach(set_property_dropdown_value); + for (const property_name of simple_dropdown_properties) { + set_property_dropdown_value(property_name); + } set_realm_waiting_period_dropdown(); set_video_chat_provider_dropdown(); @@ -684,7 +686,9 @@ exports.build_page = function () { (e) => { e.preventDefault(); e.stopPropagation(); - get_subsection_property_elements(e.target).forEach(discard_property_element_changes); + for (const elem of get_subsection_property_elements(e.target)) { + discard_property_element_changes(elem); + } const save_btn_controls = $(e.target).closest(".save-button-controls"); exports.change_save_button_state(save_btn_controls, "discarded"); }, diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js index 4d7f19ae1c..69dedf5493 100644 --- a/static/js/settings_user_groups.js +++ b/static/js/settings_user_groups.js @@ -65,10 +65,10 @@ exports.populate_user_groups = function () { } const userg = $('div.user-group[id="' + data.id + '"]'); - data.members.forEach((user_id) => { + for (const user_id of data.members) { const user = people.get_by_user_id(user_id); user_pill.append_user(user, pills); - }); + } function update_membership(group_id) { if (exports.can_edit(group_id)) { diff --git a/static/js/stats/stats.js b/static/js/stats/stats.js index 6fba87703f..0b67ce02bb 100644 --- a/static/js/stats/stats.js +++ b/static/js/stats/stats.js @@ -183,9 +183,9 @@ function populate_messages_sent_over_time(data) { document.querySelector("#hover_date").textContent = data.points[0].data.text[data.points[0].pointNumber]; const values = [null, null, null]; - data.points.forEach((trace) => { + for (const trace of data.points) { values[trace.curveNumber] = trace.y; - }); + } const hover_text_ids = ["#hover_me", "#hover_human", "#hover_bot"]; const hover_value_ids = ["#hover_me_value", "#hover_human_value", "#hover_bot_value"]; for (const [i, value] of values.entries()) { @@ -391,14 +391,14 @@ function compute_summary_chart_data(time_series_data, num_steps, labels_) { } const labels = labels_.slice(); const values = []; - labels.forEach((label) => { + for (const label of labels) { if (data.has(label)) { values.push(data.get(label)); data.delete(label); } else { values.push(0); } - }); + } if (data.size !== 0) { labels[labels.length - 1] = "Other"; for (const sum of data.values()) { @@ -443,9 +443,9 @@ function populate_messages_sent_by_client(data) { } label_values.sort((a, b) => b.value - a.value); const labels = []; - label_values.forEach((item) => { + for (const item of label_values) { labels.push(item.label); - }); + } function make_plot_data(time_series_data, num_steps) { const plot_data = compute_summary_chart_data(time_series_data, num_steps, labels); @@ -732,9 +732,9 @@ function populate_number_of_users(data) { document.querySelector("#users_hover_date").textContent = data.points[0].data.text[data.points[0].pointNumber]; const values = [null, null, null]; - data.points.forEach((trace) => { + for (const trace of data.points) { values[trace.curveNumber] = trace.y; - }); + } const hover_value_ids = [ "#users_hover_1day_value", "#users_hover_15day_value", @@ -865,9 +865,9 @@ function populate_messages_read_over_time(data) { document.querySelector("#read_hover_date").textContent = data.points[0].data.text[data.points[0].pointNumber]; const values = [null, null]; - data.points.forEach((trace) => { + for (const trace of data.points) { values[trace.curveNumber] = trace.y; - }); + } const read_hover_text_ids = ["#read_hover_me", "#read_hover_everyone"]; const read_hover_value_ids = ["#read_hover_me_value", "#read_hover_everyone_value"]; for (const [i, value] of values.entries()) { diff --git a/static/js/stream_data.js b/static/js/stream_data.js index d6680d23ed..312d7c802b 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -602,9 +602,9 @@ exports.all_topics_in_cache = function (sub) { exports.set_realm_default_streams = function (realm_default_streams) { default_stream_ids.clear(); - realm_default_streams.forEach((stream) => { + for (const stream of realm_default_streams) { default_stream_ids.add(stream.stream_id); - }); + } }; exports.get_default_stream_ids = function () { @@ -903,12 +903,12 @@ exports.initialize = function (params) { color_data.claim_colors(subscriptions); function populate_subscriptions(subs, subscribed, previously_subscribed) { - subs.forEach((sub) => { + for (const sub of subs) { sub.subscribed = subscribed; sub.previously_subscribed = previously_subscribed; exports.create_sub_from_server_data(sub); - }); + } } exports.set_realm_default_streams(realm_default_streams); diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 3086041059..72e8658e43 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -114,7 +114,9 @@ exports.build_stream_list = function (force_rerender) { topic_list.clear(); parent.empty(); - stream_groups.pinned_streams.forEach(add_sidebar_li); + for (const stream_id of stream_groups.pinned_streams) { + add_sidebar_li(stream_id); + } const any_pinned_streams = stream_groups.pinned_streams.length > 0; const any_normal_streams = stream_groups.normal_streams.length > 0; @@ -124,13 +126,17 @@ exports.build_stream_list = function (force_rerender) { elems.push('
'); } - stream_groups.normal_streams.forEach(add_sidebar_li); + for (const stream_id of stream_groups.normal_streams) { + add_sidebar_li(stream_id); + } if (any_dormant_streams && any_normal_streams) { elems.push('
'); } - stream_groups.dormant_streams.forEach(add_sidebar_li); + for (const stream_id of stream_groups.dormant_streams) { + add_sidebar_li(stream_id); + } parent.append(elems); }; diff --git a/static/js/upload.js b/static/js/upload.js index c0a4ae5a45..219e95c3b6 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -136,13 +136,13 @@ exports.upload_files = function (uppy, config, files) { .show(); exports.get_item("send_status_message", config).html($("

").text(i18n.t("Uploading…"))); exports.get_item("send_status_close_button", config).one("click", () => { - uppy.getFiles().forEach((file) => { + for (const file of uppy.getFiles()) { compose_ui.replace_syntax( exports.get_translated_status(file), "", exports.get_item("textarea", config), ); - }); + } compose_ui.autosize_textarea(exports.get_item("textarea", config)); uppy.cancelAll(); exports.get_item("textarea", config).trigger("focus"); @@ -261,7 +261,7 @@ exports.setup_upload = function (config) { uppy.on("complete", () => { let uploads_in_progress = false; - uppy.getFiles().forEach((file) => { + for (const file of uppy.getFiles()) { if (file.progress.uploadComplete) { // The uploaded files should be removed since uppy don't allow files in the store // to be re-uploaded again. @@ -272,7 +272,7 @@ exports.setup_upload = function (config) { // still be in progress. uploads_in_progress = true; } - }); + } const has_errors = exports.get_item("send_status", config).hasClass("alert-error"); if (!uploads_in_progress && !has_errors) {