diff --git a/.eslintrc.json b/.eslintrc.json index d4a286300d..f0c938ef4d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -92,7 +92,6 @@ "unicorn/consistent-function-scoping": "off", "unicorn/explicit-length-check": "off", "unicorn/filename-case": "off", - "unicorn/no-fn-reference-in-iterator": "off", "unicorn/no-nested-ternary": "off", "unicorn/no-null": "off", "unicorn/no-process-exit": "off", diff --git a/frontend_tests/node_tests/lazy_set.js b/frontend_tests/node_tests/lazy_set.js index e7c184cdfa..ba4fb43f78 100644 --- a/frontend_tests/node_tests/lazy_set.js +++ b/frontend_tests/node_tests/lazy_set.js @@ -16,9 +16,10 @@ const {LazySet} = zrequire("lazy_set"); run_test("map", () => { const ls = new LazySet([1, 2]); - const triple = (n) => n * 3; - - assert.deepEqual(ls.map(triple), [3, 6]); + assert.deepEqual( + ls.map((n) => n * 3), + [3, 6], + ); }); run_test("conversions", () => { diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.js index be36ecf377..0fee38ae83 100644 --- a/frontend_tests/node_tests/list_render.js +++ b/frontend_tests/node_tests/list_render.js @@ -354,7 +354,7 @@ run_test("sorting", () => { }; function html_for(people) { - return people.map(opts.modifier).join(""); + return people.map((item) => opts.modifier(item)).join(""); } list_render.create(container, list, opts); diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js index 039241edb6..b9fa689c9f 100644 --- a/frontend_tests/node_tests/message_list_data.js +++ b/frontend_tests/node_tests/message_list_data.js @@ -28,7 +28,7 @@ function make_msg(msg_id) { } function make_msgs(msg_ids) { - return msg_ids.map(make_msg); + return msg_ids.map((msg_id) => make_msg(msg_id)); } function assert_contents(mld, msg_ids) { diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index a311799759..9dbe475513 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -197,8 +197,8 @@ run_test("merge_message_groups", () => { } function assert_message_groups_list_equal(list1, list2) { - const ids1 = list1.map(extract_group); - const ids2 = list2.map(extract_group); + const ids1 = list1.map((group) => extract_group(group)); + const ids2 = list2.map((group) => extract_group(group)); assert(ids1.length); assert.deepEqual(ids1, ids2); } diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.js index eacf84ea85..371cbb0678 100644 --- a/frontend_tests/node_tests/typeahead.js +++ b/frontend_tests/node_tests/typeahead.js @@ -35,7 +35,10 @@ const emojis = [emoji_japanese_post_office, emoji_panda_face, emoji_smile, emoji run_test("get_emoji_matcher", () => { function assert_matches(query, expected) { const matcher = typeahead.get_emoji_matcher(query); - assert.deepEqual(emojis.filter(matcher), expected); + assert.deepEqual( + emojis.filter((emoji) => matcher(emoji)), + expected, + ); } assert_matches("notaemoji", []); diff --git a/frontend_tests/puppeteer_lib/common.js b/frontend_tests/puppeteer_lib/common.js index 612b392601..db3100d9f7 100644 --- a/frontend_tests/puppeteer_lib/common.js +++ b/frontend_tests/puppeteer_lib/common.js @@ -381,9 +381,8 @@ class CommonUtils { */ async get_rendered_messages(page, table = "zhome") { return await page.evaluate((table) => { - const data = []; const $recipient_rows = $(`#${table}`).find(".recipient_row"); - $.map($recipient_rows, (element) => { + return $recipient_rows.toArray().map((element) => { const $el = $(element); const stream_name = $el.find(".stream_label").text().trim(); const topic_name = $el.find(".stream_topic a").text().trim(); @@ -395,15 +394,13 @@ class CommonUtils { key = `${stream_name} > ${topic_name}`; } - const messages = []; - $.map($el.find(".message_row .message_content"), (message_row) => { - messages.push(message_row.textContent.trim()); - }); + const messages = $el + .find(".message_row .message_content") + .toArray() + .map((message_row) => message_row.textContent.trim()); - data.push([key, messages]); + return [key, messages]; }); - - return data; }, table); } diff --git a/frontend_tests/zjsunit/mdiff.js b/frontend_tests/zjsunit/mdiff.js index 2c6996558e..54e469577f 100644 --- a/frontend_tests/zjsunit/mdiff.js +++ b/frontend_tests/zjsunit/mdiff.js @@ -118,9 +118,9 @@ function diff_strings(string_0, string_1) { } } - const emphasize_codes = (string) => - "\u001B[34m" + string.slice(0, 1) + "\u001B[0m" + string.slice(1); - output_lines = output_lines.map(emphasize_codes); + output_lines = output_lines.map( + (string) => "\u001B[34m" + string.slice(0, 1) + "\u001B[0m" + string.slice(1), + ); return output_lines.join("\n"); } diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js index eeefdc92f6..fca7d32bf1 100644 --- a/static/js/buddy_data.js +++ b/static/js/buddy_data.js @@ -286,7 +286,7 @@ function maybe_shrink_list(user_ids, user_filter_text) { return user_ids; } - user_ids = user_ids.filter(user_is_recently_active); + user_ids = user_ids.filter((user_id) => user_is_recently_active(user_id)); return user_ids; } @@ -327,7 +327,7 @@ exports.get_filtered_and_sorted_user_ids = function (user_filter_text) { }; exports.get_items_for_users = function (user_ids) { - const user_info = user_ids.map(exports.info_for); + const user_info = user_ids.map((user_id) => exports.info_for(user_id)); compose_fade.update_user_info(user_info, fade_config); return user_info; }; diff --git a/static/js/buddy_list.js b/static/js/buddy_list.js index 3c231b6372..5900293af5 100644 --- a/static/js/buddy_list.js +++ b/static/js/buddy_list.js @@ -23,8 +23,7 @@ class BuddyListConf { get_li_from_key(opts) { const user_id = opts.key; const container = $(this.container_sel); - const sel = this.item_sel + "[data-user-id='" + user_id + "']"; - return container.find(sel); + return container.find(this.item_sel + "[data-user-id='" + user_id + "']"); } get_key_from_li(opts) { @@ -97,7 +96,7 @@ class BuddyList extends BuddyListConf { } get_items() { - const obj = this.container.find(this.item_sel); + const obj = this.container.find(`${this.item_sel}`); return obj.map((i, elem) => $(elem)); } diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index 7508048e62..c571b70bfa 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -826,7 +826,7 @@ exports.initialize = function () { $("body").on("click", "[data-make-editable]", function () { const selector = $(this).attr("data-make-editable"); - const edit_area = $(this).parent().find(selector); + const edit_area = $(this).parent().find(`${selector}`); $(selector).removeClass("stream-name-edit-box"); if (edit_area.attr("contenteditable") === "true") { $("[data-finish-editing='" + selector + "']").hide(); @@ -857,7 +857,7 @@ exports.initialize = function () { if (map[selector].on_save) { map[selector].on_save(e); $(this).hide(); - $(this).parent().find(selector).attr("contenteditable", false); + $(this).parent().find(`${selector}`).attr("contenteditable", false); $("[data-make-editable='" + selector + "']").html(""); } }); diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index edf2a2d6e3..4725ac4b27 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -418,10 +418,6 @@ exports.get_pm_people = function (query) { exports.get_person_suggestions = function (query, opts) { query = typeahead.clean_query_lowercase(query); - const person_matcher = (item) => exports.query_matches_person(query, item); - - const group_matcher = (item) => query_matches_name_description(query, item); - function filter_persons(all_persons) { let persons; @@ -434,7 +430,7 @@ exports.get_person_suggestions = function (query, opts) { if (opts.want_broadcast) { persons = persons.concat(exports.broadcast_mentions()); } - return persons.filter(person_matcher); + return persons.filter((item) => exports.query_matches_person(query, item)); } let groups; @@ -445,7 +441,7 @@ exports.get_person_suggestions = function (query, opts) { groups = []; } - const filtered_groups = groups.filter(group_matcher); + const filtered_groups = groups.filter((item) => query_matches_name_description(query, item)); /* Let's say you're on a big realm and type diff --git a/static/js/drafts.js b/static/js/drafts.js index 9b1ac59721..c5ae8588b8 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -332,7 +332,9 @@ exports.launch = function () { (draft_a, draft_b) => draft_b.updatedAt - draft_a.updatedAt, ); - const sorted_formatted_drafts = sorted_raw_drafts.map(exports.format_draft).filter(Boolean); + const sorted_formatted_drafts = sorted_raw_drafts + .map((draft_row) => exports.format_draft(draft_row)) + .filter(Boolean); return sorted_formatted_drafts; } diff --git a/static/js/filter.js b/static/js/filter.js index d9e651960c..5cdd701c52 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -699,9 +699,7 @@ class Filter { } _fix_redundant_is_private(terms) { - const is_pm_with = (term) => Filter.term_type(term) === "pm-with"; - - if (!terms.some(is_pm_with)) { + if (!terms.some((term) => Filter.term_type(term) === "pm-with")) { return terms; } @@ -736,7 +734,7 @@ class Filter { _build_sorted_term_types() { const terms = this._operators; - const term_types = terms.map(Filter.term_type); + const term_types = terms.map((term) => Filter.term_type(term)); const sorted_terms = Filter.sorted_term_types(term_types); return sorted_terms; } diff --git a/static/js/list_render.js b/static/js/list_render.js index f0cffbc2b4..b6f1a305bb 100644 --- a/static/js/list_render.js +++ b/static/js/list_render.js @@ -35,14 +35,17 @@ exports.get_filtered_items = (value, list, opts) => { if (!opts.filter) { if (get_item) { - return list.map(get_item); + return list.map((key) => get_item(key)); } return [...list]; } if (opts.filter.filterer) { if (get_item) { - return opts.filter.filterer(list.map(get_item), value); + return opts.filter.filterer( + list.map((key) => get_item(key)), + value, + ); } return opts.filter.filterer(list, value); } @@ -62,7 +65,7 @@ exports.get_filtered_items = (value, list, opts) => { return result; } - return list.filter(predicate); + return list.filter((item) => predicate(item)); }; exports.alphabetic_sort = (prop) => diff --git a/static/js/message_events.js b/static/js/message_events.js index 6dfeb0815c..7583c25dee 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -41,7 +41,9 @@ function maybe_add_narrowed_messages(messages, msg_list) { // edited in between when they sent the message and when // we hear back from the server and can echo the new // message. Arguably, it's counterproductive complexity. - new_messages = new_messages.map(message_store.add_message_metadata); + new_messages = new_messages.map((message) => + message_store.add_message_metadata(message), + ); message_util.add_new_messages(new_messages, msg_list); unread_ops.process_visible(); @@ -61,7 +63,7 @@ function maybe_add_narrowed_messages(messages, msg_list) { } exports.insert_new_messages = function insert_new_messages(messages, sent_by_this_client) { - messages = messages.map(message_store.add_message_metadata); + messages = messages.map((message) => message_store.add_message_metadata(message)); unread.process_loaded_messages(messages); huddle_data.process_loaded_messages(messages); diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js index 9c7a86a800..2bc44becac 100644 --- a/static/js/message_list_data.js +++ b/static/js/message_list_data.js @@ -167,7 +167,7 @@ class MessageListData { filter_incoming(messages) { const predicate = this._get_predicate(); - return messages.filter(predicate); + return messages.filter((message) => predicate(message)); } unmuted_messages(messages) { @@ -304,10 +304,9 @@ class MessageListData { this._local_only.delete(id); } - const remove_messages = (msg) => !msg_ids_to_remove.has(msg.id); - this._items = this._items.filter(remove_messages); + this._items = this._items.filter((msg) => !msg_ids_to_remove.has(msg.id)); if (this.muting_enabled) { - this._all_items = this._all_items.filter(remove_messages); + this._all_items = this._all_items.filter((msg) => !msg_ids_to_remove.has(msg.id)); } } diff --git a/static/js/message_store.js b/static/js/message_store.js index 452cd075cc..a36827bf81 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -49,33 +49,33 @@ exports.each = function (f) { }; exports.get_pm_emails = function (message) { - function email(user_id) { - const person = people.get_by_user_id(user_id); - if (!person) { - blueslip.error("Unknown user id " + user_id); - return "?"; - } - return person.email; - } - const user_ids = people.pm_with_user_ids(message); - const emails = user_ids.map(email).sort(); + const emails = user_ids + .map((user_id) => { + const person = people.get_by_user_id(user_id); + if (!person) { + blueslip.error("Unknown user id " + user_id); + return "?"; + } + return person.email; + }) + .sort(); return emails.join(", "); }; exports.get_pm_full_names = function (message) { - function name(user_id) { - const person = people.get_by_user_id(user_id); - if (!person) { - blueslip.error("Unknown user id " + user_id); - return "?"; - } - return person.full_name; - } - const user_ids = people.pm_with_user_ids(message); - const names = user_ids.map(name).sort(); + const names = user_ids + .map((user_id) => { + const person = people.get_by_user_id(user_id); + if (!person) { + blueslip.error("Unknown user id " + user_id); + return "?"; + } + return person.full_name; + }) + .sort(); return names.join(", "); }; diff --git a/static/js/message_util.js b/static/js/message_util.js index 4f879b3d1b..b563df06d8 100644 --- a/static/js/message_util.js +++ b/static/js/message_util.js @@ -24,7 +24,7 @@ function add_messages(messages, msg_list, opts) { // one needs an outer element wrapping an object to use this // construction. function is_element_in_message_content(message, element_selector) { - return $(`
${message.content}
`).find(element_selector).length > 0; + return $(`
${message.content}
`).find(`${element_selector}`).length > 0; } exports.message_has_link = function (message) { diff --git a/static/js/people.js b/static/js/people.js index 5a166c249c..b8b29ec972 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -153,11 +153,9 @@ export function huddle_string(message) { let user_ids = message.display_recipient.map((recip) => recip.id); - function is_huddle_recip(user_id) { - return user_id && people_by_user_id_dict.has(user_id) && !is_my_user_id(user_id); - } - - user_ids = user_ids.filter(is_huddle_recip); + user_ids = user_ids.filter( + (user_id) => user_id && people_by_user_id_dict.has(user_id) && !is_my_user_id(user_id), + ); if (user_ids.length <= 1) { return undefined; @@ -302,7 +300,7 @@ export function get_recipients(user_ids_string) { return my_full_name(); } - const names = other_ids.map(get_full_name).sort(); + const names = other_ids.map((user_id) => get_full_name(user_id)).sort(); return names.join(", "); } @@ -873,7 +871,7 @@ export function get_people_for_search_bar(query) { const message_people = get_message_people(); - const small_results = message_people.filter(pred); + const small_results = message_people.filter((item) => pred(item)); if (small_results.length >= 5) { return small_results; @@ -903,7 +901,7 @@ export function build_person_matcher(query) { query = query.trim(); const termlets = query.toLowerCase().split(/\s+/); - const termlet_matchers = termlets.map(build_termlet_matcher); + const termlet_matchers = termlets.map((termlet) => build_termlet_matcher(termlet)); return function (user) { const email = user.email.toLowerCase(); diff --git a/static/js/pm_list_dom.js b/static/js/pm_list_dom.js index bf0afde78f..7323c6d5ce 100644 --- a/static/js/pm_list_dom.js +++ b/static/js/pm_list_dom.js @@ -26,7 +26,7 @@ exports.pm_ul = (convos) => { ]; return vdom.ul({ attrs, - keyed_nodes: convos.map(exports.keyed_pm_li), + keyed_nodes: convos.map((convo) => exports.keyed_pm_li(convo)), }); }; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index d91a95452d..b0ab076dd3 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -582,7 +582,9 @@ exports.save_discard_widget_status_handler = (subsection) => { subsection.find(".subsection-failed-status p").hide(); subsection.find(".save-button").show(); const properties_elements = get_subsection_property_elements(subsection); - const show_change_process_button = properties_elements.some(check_property_changed); + const show_change_process_button = properties_elements.some((elem) => + check_property_changed(elem), + ); const save_btn_controls = subsection.find(".subsection-header .save-button-controls"); const button_state = show_change_process_button ? "unsaved" : "discarded"; diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js index 03e38d2c09..ebcd1b3759 100644 --- a/static/js/settings_panel_menu.js +++ b/static/js/settings_panel_menu.js @@ -76,8 +76,7 @@ class SettingsPanelMenu { enter_panel() { const panel = this.get_panel(); - const sel = "input:visible,button:visible,select:visible"; - const panel_elem = panel.find(sel).first(); + const panel_elem = panel.find("input:visible,button:visible,select:visible").first(); panel_elem.trigger("focus"); return true; diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index a06e77f4af..0196b10c65 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -24,7 +24,7 @@ exports.build_default_stream_table = function () { const table = $("#admin_default_streams_table").expectOne(); const stream_ids = stream_data.get_default_stream_ids(); - const subs = stream_ids.map(stream_data.get_sub_by_id); + const subs = stream_ids.map((stream_id) => stream_data.get_sub_by_id(stream_id)); list_render.create(table, subs, { name: "default_streams_list", diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index d8e4a1fa6d..9760f506e4 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -228,9 +228,11 @@ function submit_add_subscriber_form(e) { function invite_success(data) { exports.pill_widget.clear(); - const subscribed_users = Object.keys(data.subscribed).map(people.get_by_email); - const already_subscribed_users = Object.keys(data.already_subscribed).map( - people.get_by_email, + const subscribed_users = Object.keys(data.subscribed).map((email) => + people.get_by_email(email), + ); + const already_subscribed_users = Object.keys(data.already_subscribed).map((email) => + people.get_by_email(email), ); const html = render_stream_subscription_info({subscribed_users, already_subscribed_users}); diff --git a/static/js/topic_list.js b/static/js/topic_list.js index c2f5762279..122a6c28ec 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -128,7 +128,7 @@ class TopicListWidget { const attrs = [["class", "topic-list"]]; - const nodes = list_info.items.map(exports.keyed_topic_li); + const nodes = list_info.items.map((convo) => exports.keyed_topic_li(convo)); if (spinner) { nodes.push(exports.spinner_li()); diff --git a/static/js/typing_events.js b/static/js/typing_events.js index 84ca441d04..f916d5a193 100644 --- a/static/js/typing_events.js +++ b/static/js/typing_events.js @@ -46,7 +46,7 @@ function get_users_typing_for_narrow() { exports.render_notifications_for_narrow = function () { const user_ids = get_users_typing_for_narrow(); - const users_typing = user_ids.map(people.get_by_user_id); + const users_typing = user_ids.map((user_id) => people.get_by_user_id(user_id)); if (users_typing.length === 0) { $("#typing_notifications").hide(); } else { diff --git a/static/js/util.js b/static/js/util.js index 29818ab12e..89dcdd2d42 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -218,14 +218,10 @@ exports.is_mobile = function () { return new RegExp(regex, "i").test(window.navigator.userAgent); }; -function to_int(s) { - return Number.parseInt(s, 10); -} - exports.sorted_ids = function (ids) { // This mapping makes sure we are using ints, and // it also makes sure we don't mutate the list. - let id_list = ids.map(to_int); + let id_list = ids.map((s) => Number.parseInt(s, 10)); id_list.sort((a, b) => a - b); id_list = _.sortedUniq(id_list); diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js index 999fba9fe2..6c607c7a71 100644 --- a/static/shared/js/typeahead.js +++ b/static/shared/js/typeahead.js @@ -160,7 +160,7 @@ export function sort_emojis(objs, query) { return popular_set.has(obj.emoji_code) && decent_match(obj.emoji_name); } - const popular_emoji_matches = objs.filter(is_popular); + const popular_emoji_matches = objs.filter((obj) => is_popular(obj)); const others = objs.filter((obj) => !is_popular(obj)); const triage_results = triage(query, others, (x) => x.emoji_name);