diff --git a/docs/subsystems/input-pills.md b/docs/subsystems/input-pills.md index edf3e0feac..be9c870cba 100644 --- a/docs/subsystems/input-pills.md +++ b/docs/subsystems/input-pills.md @@ -57,7 +57,7 @@ exports.typeahead_source = function (pill_widget) { exports.filter_taken_users = function (items, pill_widget) { const taken_user_ids = exports.get_user_ids(pill_widget); items = _.filter(items, function (item) { - return taken_user_ids.indexOf(item.user_id) === -1; + return !taken_user_ids.includes(item.user_id); }); return items; }; diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index e27a5eac59..44a8c27ae8 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -432,8 +432,8 @@ run_test('topic_links', () => { message = {type: 'stream', topic: "New ZBUG_123 with #456 link here"}; markdown.add_topic_links(message); assert.equal(util.get_topic_links(message).length, 2); - assert(util.get_topic_links(message).indexOf("https://trac2.zulip.net/ticket/123") !== -1); - assert(util.get_topic_links(message).indexOf("https://trac.zulip.net/ticket/456") !== -1); + assert(util.get_topic_links(message).includes("https://trac2.zulip.net/ticket/123")); + assert(util.get_topic_links(message).includes("https://trac.zulip.net/ticket/456")); message = {type: 'stream', topic: "One ZGROUP_123:45 link here"}; markdown.add_topic_links(message); @@ -448,9 +448,9 @@ run_test('topic_links', () => { message = {type: 'stream', topic: "#456 https://google.com https://github.com"}; markdown.add_topic_links(message); assert.equal(util.get_topic_links(message).length, 3); - assert(util.get_topic_links(message).indexOf("https://google.com") !== -1); - assert(util.get_topic_links(message).indexOf("https://github.com") !== -1); - assert(util.get_topic_links(message).indexOf("https://trac.zulip.net/ticket/456") !== -1); + assert(util.get_topic_links(message).includes("https://google.com")); + assert(util.get_topic_links(message).includes("https://github.com")); + assert(util.get_topic_links(message).includes("https://trac.zulip.net/ticket/456")); message = {type: "not-stream"}; markdown.add_topic_links(message); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 71dd4ee666..06ccf23f6a 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -121,7 +121,7 @@ run_test('blueslip', () => { }; blueslip.set_test_data('error', 'Unknown user id in message: 42'); const reply_to = people.pm_reply_to(message); - assert(reply_to.indexOf('?') > -1); + assert(reply_to.includes('?')); assert.equal(blueslip.get_test_logs('error').length, 1); blueslip.clear_test_data(); diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 156808a556..a2b103147e 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -714,7 +714,7 @@ run_test('sent_by_me_suggestions', () => { let query = ''; let suggestions = get_suggestions('', query); - assert(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1); + assert(suggestions.strings.includes('sender:bob@zulip.com')); assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description, 'Sent by me'); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index d4d4520c69..7ff98c99da 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -683,7 +683,7 @@ run_test('sent_by_me_suggestions', () => { let query = ''; let suggestions = search.get_suggestions_legacy(query); - assert(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1); + assert(suggestions.strings.includes('sender:bob@zulip.com')); assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description, 'Sent by me'); diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index 1aea469714..a92f3d2258 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -797,9 +797,9 @@ run_test('initialize', () => { assert(!stream_data.is_filtering_inactives()); const stream_names = stream_data.get_streams_for_admin().map(elem => elem.name); - assert(stream_names.indexOf('subscriptions') !== -1); - assert(stream_names.indexOf('unsubscribed') !== -1); - assert(stream_names.indexOf('never_subscribed') !== -1); + assert(stream_names.includes('subscriptions')); + assert(stream_names.includes('unsubscribed')); + assert(stream_names.includes('never_subscribed')); assert(!page_params.subscriptions); assert(!page_params.unsubscribed); assert(!page_params.never_subscribed); diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index 93e11bb8b8..8340953763 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -1754,8 +1754,8 @@ run_test('recipient_row', () => { ], }; const html = render('recipient_row', data); - assert(html.indexOf('') === -1); - assert(html.indexOf('<script>alert("Hello")</script>') !== -1); + assert(!html.includes('')); + assert(html.includes('<script>alert("Hello")</script>')); }); run_test('invitation_failed_error', () => { diff --git a/frontend_tests/zjsunit/finder.js b/frontend_tests/zjsunit/finder.js index c604961161..366d1d57dd 100644 --- a/frontend_tests/zjsunit/finder.js +++ b/frontend_tests/zjsunit/finder.js @@ -23,7 +23,7 @@ exports.find_files_to_run = function () { if (oneFileFilter.length > 0) { tests = tests.filter(function (filename) { - return oneFileFilter.indexOf(filename) !== -1; + return oneFileFilter.includes(filename); }); testsDifference = _.difference(oneFileFilter, tests); } diff --git a/frontend_tests/zjsunit/zblueslip.js b/frontend_tests/zjsunit/zblueslip.js index 1bbecf01d5..a8ab8bd8d9 100644 --- a/frontend_tests/zjsunit/zblueslip.js +++ b/frontend_tests/zjsunit/zblueslip.js @@ -63,8 +63,8 @@ exports.make_zblueslip = function () { } lib[name] = function (message, more_info, stack) { lib.test_logs[name].push({message, more_info, stack}); - const exact_match_fail = lib.test_data[name].indexOf(message) === -1; - const string_match_fail = lib.test_data[name].indexOf(message.toString()) === -1; + const exact_match_fail = !lib.test_data[name].includes(message); + const string_match_fail = !lib.test_data[name].includes(message.toString()); if (exact_match_fail && string_match_fail) { const error = Error(`Invalid ${name} message: "${message}".`); error.blueslip = true; diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 66f1b55766..0095ee83f4 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -168,7 +168,7 @@ exports.make_new_elem = function (selector, opts) { closest: function (selector) { const elem = self; const search = selector.startsWith('.') || selector.startsWith('#') ? selector.substring(1) : selector; - if (elem.selector.indexOf(search) > -1) { + if (elem.selector.includes(search)) { return elem; } else if (parents_result.get(selector)) { return parents_result.get(selector); @@ -486,15 +486,15 @@ exports.make_zjquery = function (opts) { } const valid_selector = - '<#.'.indexOf(selector[0]) >= 0 || + '<#.'.includes(selector[0]) || selector === 'window-stub' || selector === 'document-stub' || selector === 'body' || selector === 'html' || selector.location || - selector.indexOf('#') >= 0 || - selector.indexOf('.') >= 0 || - selector.indexOf('[') >= 0 && selector.indexOf(']') >= selector.indexOf('['); + selector.includes('#') || + selector.includes('.') || + selector.includes('[') && selector.indexOf(']') >= selector.indexOf('['); assert(valid_selector, 'Invalid selector: ' + selector + diff --git a/static/js/activity.js b/static/js/activity.js index c690fcfcd8..ffb93ecc88 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -87,7 +87,7 @@ exports.update_dom_with_unread_counts = function (counts) { for (const [user_ids_string, count] of counts.pm_count) { // TODO: just use user_ids_string in our markup - const is_pm = user_ids_string.indexOf(',') < 0; + const is_pm = !user_ids_string.includes(','); if (is_pm) { set_pm_count(user_ids_string, count); } else { diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js index c74fca822a..ec9933c7d4 100644 --- a/static/js/alert_words_ui.js +++ b/static/js/alert_words_ui.js @@ -40,7 +40,7 @@ function add_alert_word(alert_word) { if (alert_word === '') { update_alert_word_status(i18n.t("Alert word can't be empty!"), true); return; - } else if (alert_words.words.indexOf(alert_word) !== -1) { + } else if (alert_words.words.includes(alert_word)) { update_alert_word_status(i18n.t("Alert word already exists!"), true); return; } diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js index a87ca4f672..87a1b4f281 100644 --- a/static/js/attachments_ui.js +++ b/static/js/attachments_ui.js @@ -69,7 +69,7 @@ function render_attachments_ui() { filter: { element: $search_input, predicate: function (item, value) { - return item.name.toLocaleLowerCase().indexOf(value) >= 0; + return item.name.toLocaleLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(uploaded_files_table.closest(".progressive-table-wrapper")); diff --git a/static/js/common.js b/static/js/common.js index b655213454..cb8b4056a8 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -119,7 +119,7 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) { let key_text = $(this).text(); const keys = key_text.match(/[^\s\+]+/g); - if (key_text.indexOf('Ctrl') > -1 && require_cmd_style) { + if (key_text.includes('Ctrl') && require_cmd_style) { $(this).addClass("mac-cmd-key"); } diff --git a/static/js/compose.js b/static/js/compose.js index 900ab4da2e..4b9c99cdff 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -891,7 +891,7 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) { return $(user_row).data('useremail'); }); - if (existing_invites.indexOf(email) === -1) { + if (!existing_invites.includes(email)) { const context = { email: email, name: mentioned.full_name, diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index e3a6220871..17997885e9 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -50,7 +50,7 @@ exports.topics_seen_for = function (stream_name) { function get_language_matcher(query) { query = query.toLowerCase(); return function (lang) { - return lang.indexOf(query) !== -1; + return lang.includes(query); }; } @@ -557,7 +557,7 @@ exports.get_candidates = function (query) { // We will likely want to extend this list to be more i18n-friendly. const terminal_symbols = ',.;?!()[] "\'\n\t'; - if (rest !== '' && terminal_symbols.indexOf(rest[0]) === -1) { + if (rest !== '' && !terminal_symbols.includes(rest[0])) { return false; } @@ -974,7 +974,7 @@ exports.initialize = function () { }, sorter: function (items) { const sorted = typeahead_helper.sorter(this.query, items, function (x) {return x;}); - if (sorted.length > 0 && sorted.indexOf(this.query) === -1) { + if (sorted.length > 0 && !sorted.includes(this.query)) { sorted.unshift(this.query); } return sorted; @@ -1002,7 +1002,7 @@ exports.initialize = function () { // filter out inserted users and current user from pill insertion const inserted_users = user_pill.get_user_ids(compose_pm_pill.widget); const current_user = people.is_current_user(user.email); - if (inserted_users.indexOf(user.user_id) === -1 && !current_user) { + if (!inserted_users.includes(user.user_id) && !current_user) { compose_pm_pill.set_from_typeahead(user); } } diff --git a/static/js/emoji.js b/static/js/emoji.js index cbe0d05c5f..04b1264db5 100644 --- a/static/js/emoji.js +++ b/static/js/emoji.js @@ -152,10 +152,10 @@ exports.translate_emoticons_to_names = function translate_emoticons_to_names(tex const prev_char = str[offset - 1]; const next_char = str[offset + match.length]; - const symbol_at_start = terminal_symbols.indexOf(prev_char) !== -1; - const symbol_at_end = terminal_symbols.indexOf(next_char) !== -1; - const non_space_at_start = symbols_except_space.indexOf(prev_char) !== -1; - const non_space_at_end = symbols_except_space.indexOf(next_char) !== -1; + const symbol_at_start = terminal_symbols.includes(prev_char); + const symbol_at_end = terminal_symbols.includes(next_char); + const non_space_at_start = symbols_except_space.includes(prev_char); + const non_space_at_end = symbols_except_space.includes(next_char); const valid_start = symbol_at_start || offset === 0; const valid_end = symbol_at_end || offset === str.length - match.length; diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index ffdea9a90a..4414e21ace 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -218,7 +218,7 @@ function filter_emojis() { for (const emoji_dict of emojis) { for (const alias of emoji_dict.aliases) { const match = _.every(search_terms, function (search_term) { - return alias.indexOf(search_term) >= 0; + return alias.includes(search_term); }); if (match) { search_results.push(_.extend({}, emoji_dict, {name: alias})); diff --git a/static/js/filter.js b/static/js/filter.js index 2822c2dec7..fdd1a876fa 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -121,7 +121,7 @@ function message_matches_search_term(message, operator, operand) { if (!user_ids) { return false; } - return user_ids.indexOf(operand_ids[0]) !== -1; + return user_ids.includes(operand_ids[0]); // We should also check if the current user is in the recipient list (user_ids) of the // message, but it is implicit by the fact that the current user has access to the message. } @@ -682,7 +682,7 @@ function describe_is_operator(operator) { const verb = operator.negated ? 'exclude ' : ''; const operand = operator.operand; const operand_list = ['private', 'starred', 'alerted', 'unread']; - if (operand_list.indexOf(operand) !== -1) { + if (operand_list.includes(operand)) { return verb + operand + ' messages'; } else if (operand === 'mentioned') { return verb + '@-mentions'; @@ -722,7 +722,7 @@ function describe_unescaped(operators) { // search_suggestion.get_suggestions takes care that this message will // only be shown if the `has` operator is not at the last. const valid_has_operands = ['image', 'images', 'link', 'links', 'attachment', 'attachments']; - if (valid_has_operands.indexOf(operand) === -1) { + if (!valid_has_operands.includes(operand)) { return 'invalid ' + operand + ' operand for has operator'; } } diff --git a/static/js/hashchange.js b/static/js/hashchange.js index b1403bafa0..fa4b507194 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -66,7 +66,7 @@ function is_overlay_hash(hash) { const overlay_list = ["streams", "drafts", "settings", "organization", "invite"]; const main_hash = hash_util.get_hash_category(hash); - return overlay_list.indexOf(main_hash) > -1; + return overlay_list.includes(main_hash); } // Returns true if this function performed a narrow diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 2e71c5cbb8..201322f488 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -535,7 +535,7 @@ exports.process_hotkey = function (e, hotkey) { } } - if (menu_dropdown_hotkeys.indexOf(event_name) !== -1) { + if (menu_dropdown_hotkeys.includes(event_name)) { if (popovers.actions_popped()) { popovers.actions_menu_handle_keyboard(event_name); return true; diff --git a/static/js/markdown.js b/static/js/markdown.js index d2052ba560..a2dd55c976 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -285,7 +285,7 @@ function python_to_js_filter(pattern, url) { const py_flags = match[1].split(""); for (const flag of py_flags) { - if ("im".indexOf(flag) !== -1) { + if ("im".includes(flag)) { js_flags += flag; } } diff --git a/static/js/message_events.js b/static/js/message_events.js index a14b68c5de..caf6811cb5 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -142,7 +142,7 @@ exports.update_messages = function update_messages(events) { // where the user initiated the edit. topic_edited = true; - const going_forward_change = ['change_later', 'change_all'].indexOf(event.propagate_mode) >= 0; + const going_forward_change = ['change_later', 'change_all'].includes(event.propagate_mode); const stream_name = stream_data.get_sub_by_id(event.stream_id).name; const compose_stream_name = compose_state.stream_name(); @@ -161,7 +161,7 @@ exports.update_messages = function update_messages(events) { const current_filter = narrow_state.filter(); if (going_forward_change) { const current_id = current_msg_list.selected_id(); - const selection_changed_topic = event.message_ids.indexOf(current_id) >= 0; + const selection_changed_topic = event.message_ids.includes(current_id); if (selection_changed_topic) { if (current_filter && stream_name) { if (current_filter.has_topic(stream_name, orig_topic)) { diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index f5103674df..0e5dde2009 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -119,11 +119,11 @@ function handle_operators_supporting_id_based_api(data) { data.narrow = JSON.parse(data.narrow); data.narrow = _.map(data.narrow, function (filter) { - if (operators_supporting_ids.indexOf(filter.operator) !== -1) { + if (operators_supporting_ids.includes(filter.operator)) { filter.operand = people.emails_strings_to_user_ids_array(filter.operand); } - if (operators_supporting_id.indexOf(filter.operator) !== -1) { + if (operators_supporting_id.includes(filter.operator)) { if (filter.operator === 'stream') { const stream_id = stream_data.get_stream_id(filter.operand); if (stream_id !== undefined) { diff --git a/static/js/message_flags.js b/static/js/message_flags.js index 3a021fc1a3..e1b5207e72 100644 --- a/static/js/message_flags.js +++ b/static/js/message_flags.js @@ -51,7 +51,7 @@ exports.send_read = (function () { } queue = _.filter(queue, function (message) { - return data.messages.indexOf(message.id) === -1; + return !data.messages.includes(message.id); }); if (queue.length > 0) { diff --git a/static/js/message_store.js b/static/js/message_store.js index 7417fc650e..8d1476f33b 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -78,7 +78,7 @@ exports.set_message_booleans = function (message) { const flags = message.flags || []; function convert_flag(flag_name) { - return flags.indexOf(flag_name) >= 0; + return flags.includes(flag_name); } message.unread = !convert_flag('read'); @@ -115,7 +115,7 @@ exports.update_booleans = function (message, flags) { // we are vulnerable to race conditions, so only update flags // that are driven by message content. function convert_flag(flag_name) { - return flags.indexOf(flag_name) >= 0; + return flags.includes(flag_name); } message.mentioned = convert_flag('mentioned') || convert_flag('wildcard_mentioned'); diff --git a/static/js/narrow.js b/static/js/narrow.js index ed2110c4d5..46724cad79 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -83,7 +83,7 @@ function update_narrow_title(filter) { exports.narrow_title = names + " and others"; } } else { - if (emails.indexOf(',') > -1) { + if (emails.includes(',')) { exports.narrow_title = "Invalid users"; } else { exports.narrow_title = "Invalid user"; @@ -725,7 +725,7 @@ exports.to_compose_target = function () { const topics = topic_data.get_recent_names(stream_id); const operators = [{operator: 'stream', operand: stream_name}]; const topic = compose_state.topic(); - if (topics.indexOf(topic) !== -1) { + if (topics.includes(topic)) { operators.push({operator: 'topic', operand: topic}); } exports.activate(operators, opts); @@ -978,12 +978,12 @@ function pick_empty_narrow_banner() { return $("#empty_search_narrow_message"); } else if (first_operator === "pm-with") { if (!people.is_valid_bulk_emails_for_compose(first_operand.split(','))) { - if (first_operand.indexOf(',') === -1) { + if (!first_operand.includes(',')) { return $("#non_existing_user"); } return $("#non_existing_users"); } - if (first_operand.indexOf(',') === -1) { + if (!first_operand.includes(',')) { // You have no private messages with this person if (people.is_current_user(first_operand)) { return $("#empty_narrow_self_private_message"); diff --git a/static/js/notifications.js b/static/js/notifications.js index c4187dc13e..a7bffa30cc 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -753,12 +753,15 @@ exports.handle_global_notification_updates = function (notification_name, settin // Update the global settings checked when determining if we should notify // for a given message. These settings do not affect whether or not a // particular stream should receive notifications. - if (settings_notifications.all_notification_settings_labels.indexOf(notification_name) !== -1) { + if (settings_notifications.all_notification_settings_labels.includes(notification_name)) { page_params[notification_name] = setting; } - if (settings_notifications.all_notifications.settings.stream_notification_settings.indexOf( - notification_name) !== -1) { + if ( + settings_notifications.all_notifications.settings.stream_notification_settings.includes( + notification_name + ) + ) { notification_name = notification_name.replace("enable_stream_", ""); stream_ui_updates.update_notification_setting_checkbox(notification_name); } diff --git a/static/js/people.js b/static/js/people.js index f4e5983cf2..4f40692350 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -1050,10 +1050,8 @@ function safe_lower(s) { exports.matches_user_settings_search = function (person, value) { const email = exports.email_for_user_settings(person); - return ( - safe_lower(person.full_name).indexOf(value) >= 0 || - safe_lower(email).indexOf(value) >= 0 - ); + return safe_lower(person.full_name).includes(value) || + safe_lower(email).includes(value); }; exports.filter_for_user_settings_search = function (persons, query) { diff --git a/static/js/pm_list.js b/static/js/pm_list.js index 1c96076e09..7ebe24f2e7 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -64,7 +64,7 @@ exports._get_convos = function () { const num_unread = unread.num_unread_for_person(user_ids_string); - const is_group = user_ids_string.indexOf(',') >= 0; + const is_group = user_ids_string.includes(','); const is_active = user_ids_string === active_user_ids_string; diff --git a/static/js/portico/integrations.js b/static/js/portico/integrations.js index ab4e164a5f..89fbeab176 100644 --- a/static/js/portico/integrations.js +++ b/static/js/portico/integrations.js @@ -115,7 +115,7 @@ const update_integrations = _.debounce(function () { const display_name = INTEGRATIONS[$integration.data('name')]; const display = common.phrase_match(state.query, display_name) && - ($integration.data('categories').indexOf(CATEGORIES[state.category]) !== -1 || + ($integration.data('categories').includes(CATEGORIES[state.category]) || state.category === 'all'); if (display) { diff --git a/static/js/portico/landing-page.js b/static/js/portico/landing-page.js index 6243e36e18..146d5ac24f 100644 --- a/static/js/portico/landing-page.js +++ b/static/js/portico/landing-page.js @@ -73,7 +73,7 @@ const apps_events = function () { const parts = path_parts(); Object.keys(info).forEach(function (version) { - if (parts.indexOf(version) !== -1) { + if (parts.includes(version)) { result = version; } }); @@ -160,11 +160,11 @@ const events = function () { e.stopPropagation(); }); - if (path_parts().indexOf("apps") !== -1) { + if (path_parts().includes("apps")) { apps_events(); } - if (path_parts().indexOf('hello') !== -1) { + if (path_parts().includes('hello')) { hello_events(); } }; diff --git a/static/js/portico/tabbed-instructions.js b/static/js/portico/tabbed-instructions.js index 3340de385b..f33c50abfa 100644 --- a/static/js/portico/tabbed-instructions.js +++ b/static/js/portico/tabbed-instructions.js @@ -30,7 +30,7 @@ export function activate_correct_tab($codeSection) { $(this).addClass("active"); } - if (desktop_os.indexOf(user_os) !== -1 && language === "desktop-web") { + if (desktop_os.includes(user_os) && language === "desktop-web") { $(this).addClass("active"); } }); @@ -42,7 +42,7 @@ export function activate_correct_tab($codeSection) { $(this).addClass("active"); } - if (desktop_os.indexOf(user_os) !== -1 && language === "desktop-web") { + if (desktop_os.includes(user_os) && language === "desktop-web") { $(this).addClass("active"); } }); diff --git a/static/js/reactions.js b/static/js/reactions.js index 82e8ad2863..c204cb9f68 100644 --- a/static/js/reactions.js +++ b/static/js/reactions.js @@ -432,7 +432,7 @@ exports.get_message_reactions = function (message) { reaction.is_realm_emoji = true; reaction.url = emoji.all_realm_emojis.get(reaction.emoji_code).emoji_url; } - if (reaction.user_ids.indexOf(page_params.user_id) !== -1) { + if (reaction.user_ids.includes(page_params.user_id)) { reaction.class = "message_reaction reacted"; } else { reaction.class = "message_reaction"; diff --git a/static/js/rtl.js b/static/js/rtl.js index c19877b897..0392d75cf8 100644 --- a/static/js/rtl.js +++ b/static/js/rtl.js @@ -65,10 +65,10 @@ const lr_ranges = convert_from_raw(digits, 2, '0$0}151u1<1<1|1|2222282u2w2!2#7Q7 * @returns {'I' | 'PDI' | 'R' | 'L' | 'Other'} */ function get_bidi_class(ch) { - if (i_chars.indexOf(ch) !== -1) { + if (i_chars.includes(ch)) { return 'I'; // LRI, RLI, FSI } - if (pdi_chars.indexOf(ch) !== -1) { + if (pdi_chars.includes(ch)) { return 'PDI'; } let i = util.lower_bound(rl_ranges, ch); diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index 3829c5d786..6f5e1c8cf0 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -28,7 +28,7 @@ function match_criteria(operators, criteria) { function check_validity(last, operators, valid, invalid) { // valid: list of strings valid for the last operator // invalid: list of operators invalid for any previous operators except last. - if (valid.indexOf(last.operator) === -1) { + if (!valid.includes(last.operator)) { return false; } if (match_criteria(operators, invalid)) { @@ -658,7 +658,7 @@ exports.get_search_result = function (base_query, query) { // will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}. if (query_operators_len > 1 && last.operator === 'search' && - person_suggestion_ops.indexOf(query_operators[query_operators_len - 2].operator) !== -1) { + person_suggestion_ops.includes(query_operators[query_operators_len - 2].operator)) { const person_op = query_operators[query_operators_len - 2]; if (!people.reply_to_to_user_ids_string(person_op.operand)) { last = { @@ -749,7 +749,7 @@ exports.get_search_result_legacy = function (query) { // will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}. if (operators_len > 1 && last.operator === 'search' && - person_suggestion_ops.indexOf(operators[operators_len - 2].operator) !== -1) { + person_suggestion_ops.includes(operators[operators_len - 2].operator)) { const person_op = operators[operators_len - 2]; if (!people.reply_to_to_user_ids_string(person_op.operand)) { last = { diff --git a/static/js/search_util.js b/static/js/search_util.js index 6ebd410e0f..0bb732d030 100644 --- a/static/js/search_util.js +++ b/static/js/search_util.js @@ -18,7 +18,7 @@ exports.vanilla_match = function (opts) { */ const val = opts.val.toLowerCase(); return _.any(opts.search_terms, function (term) { - if (val.indexOf(term) !== -1) { + if (val.includes(term)) { return true; } }); diff --git a/static/js/settings_display.js b/static/js/settings_display.js index 3e6b4f2f44..4f2e212b84 100644 --- a/static/js/settings_display.js +++ b/static/js/settings_display.js @@ -82,7 +82,7 @@ exports.set_up = function () { const data = {}; data[setting] = JSON.stringify($(this).prop('checked')); - if (["left_side_userlist"].indexOf(setting) > -1) { + if (["left_side_userlist"].includes(setting)) { change_display_setting( data, "#display-settings-status", diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index aea3bfcc0b..d6f7113bc0 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -77,7 +77,7 @@ exports.populate_emoji = function (emoji_data) { filter: { element: emoji_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - return item.name.toLowerCase().indexOf(value) >= 0; + return item.name.toLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(emoji_table); diff --git a/static/js/settings_exports.js b/static/js/settings_exports.js index 67ad99c5ad..1dcca37106 100644 --- a/static/js/settings_exports.js +++ b/static/js/settings_exports.js @@ -47,7 +47,7 @@ exports.populate_exports_table = function (exports) { filter: { element: exports_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - return people.get_full_name(item.acting_user_id).toLowerCase().indexOf(value) >= 0; + return people.get_full_name(item.acting_user_id).toLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(exports_table); diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js index e4884ceb09..31ea5a26f6 100644 --- a/static/js/settings_invites.js +++ b/static/js/settings_invites.js @@ -64,11 +64,11 @@ function populate_invites(invites_data) { filter: { element: invites_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - const referrer_email_matched = item.ref.toLowerCase().indexOf(value) >= 0; + const referrer_email_matched = item.ref.toLowerCase().includes(value); if (item.is_multiuse) { return referrer_email_matched; } - const invitee_email_matched = item.email.toLowerCase().indexOf(value) >= 0; + const invitee_email_matched = item.email.toLowerCase().includes(value); return referrer_email_matched || invitee_email_matched; }, }, diff --git a/static/js/settings_linkifiers.js b/static/js/settings_linkifiers.js index 9506615a83..909c4754d2 100644 --- a/static/js/settings_linkifiers.js +++ b/static/js/settings_linkifiers.js @@ -38,10 +38,8 @@ exports.populate_filters = function (filters_data) { filter: { element: filters_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - return ( - item[0].toLowerCase().indexOf(value) >= 0 || - item[1].toLowerCase().indexOf(value) >= 0 - ); + return item[0].toLowerCase().includes(value) || + item[1].toLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(filters_table); diff --git a/static/js/settings_org.js b/static/js/settings_org.js index ba0c58bc2a..744233d2d6 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -463,7 +463,7 @@ exports.populate_notifications_stream_dropdown = function (stream_list) { filter: { element: search_input, predicate: function (item, value) { - return item.name.toLowerCase().indexOf(value) >= 0; + return item.name.toLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(dropdown_list_body); @@ -492,7 +492,7 @@ exports.populate_signup_notifications_stream_dropdown = function (stream_list) { filter: { element: search_input, predicate: function (item, value) { - return item.name.toLowerCase().indexOf(value) >= 0; + return item.name.toLowerCase().includes(value); }, }, }).init(); @@ -507,7 +507,7 @@ exports.populate_signup_notifications_stream_dropdown = function (stream_list) { }; function update_dependent_subsettings(property_name) { - if (simple_dropdown_properties.indexOf(property_name) !== -1) { + if (simple_dropdown_properties.includes(property_name)) { set_property_dropdown_value(property_name); } else if (property_name === 'realm_waiting_period_threshold') { set_realm_waiting_period_dropdown(); diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index f1e6576b29..940fab56e9 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -38,7 +38,7 @@ exports.build_default_stream_table = function (streams_data) { filter: { element: table.closest(".settings-section").find(".search"), predicate: function (item, value) { - return item.name.toLowerCase().indexOf(value) >= 0; + return item.name.toLowerCase().includes(value); }, onupdate: function () { ui.reset_scrollbar(table); diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 1991cc81a2..077f839443 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -174,10 +174,8 @@ function populate_users(realm_people_data) { filter: { element: $bots_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - return ( - item.full_name.toLowerCase().indexOf(value) >= 0 || - item.email.toLowerCase().indexOf(value) >= 0 - ); + return item.full_name.toLowerCase().includes(value) || + item.email.toLowerCase().includes(value); }, onupdate: reset_scrollbar($bots_table), }, diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 5ad48184ad..e8d1251617 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -127,7 +127,7 @@ function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_onl }, error: function (xhr) { const msg = JSON.parse(xhr.responseText).msg; - if (msg.indexOf('access') >= 0) { + if (msg.includes('access')) { // If we can't access the stream, we can safely assume it's // a duplicate stream that we are not invited to. stream_name_error.report_already_exists(stream_name); @@ -210,7 +210,7 @@ function create_stream() { // Even though we already check to make sure that while typing the user cannot enter // newline characters (by pressing the enter key) it would still be possible to copy // and paste over a description with newline characters in it. Prevent that. - if (description.indexOf('\n') !== -1) { + if (description.includes('\n')) { ui_report.message(i18n.t("The stream description cannot contain newline characters."), $(".stream_create_info"), 'alert-error'); return; } @@ -409,7 +409,7 @@ exports.set_up_handlers = function () { stream_subscription_error.report_no_subs_to_stream(); return; } - if (principals.indexOf(people.my_current_user_id()) < 0 && !page_params.is_admin) { + if (!principals.includes(people.my_current_user_id()) && !page_params.is_admin) { stream_subscription_error.cant_create_stream_without_susbscribing(); return; } diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index dd012cc4cd..8ed07d1b5d 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -141,7 +141,7 @@ exports.sort_but_pin_current_user_on_top = function (emails) { return; } // Set current user top of subscription list, if subscribed. - if (emails.indexOf(people.my_current_email()) > -1) { + if (emails.includes(people.my_current_email())) { emails.splice(emails.indexOf(people.my_current_email()), 1); emails.sort(); emails.unshift(people.my_current_email()); @@ -187,7 +187,7 @@ function show_subscription_settings(sub_row) { const email = person.email.toLocaleLowerCase(); const full_name = person.full_name.toLowerCase(); - return email.indexOf(value) > -1 || full_name.indexOf(value) > -1; + return email.includes(value) || full_name.includes(value); } }, }, @@ -205,8 +205,8 @@ function show_subscription_settings(sub_row) { return false; } // Case-insensitive. - const item_matches = item.email.toLowerCase().indexOf(query) !== -1 || - item.full_name.toLowerCase().indexOf(query) !== -1; + const item_matches = item.email.toLowerCase().includes(query) || + item.full_name.toLowerCase().includes(query); const is_subscribed = stream_data.is_user_subscribed(sub.name, item.user_id); return item_matches && !is_subscribed; }, @@ -222,9 +222,9 @@ function show_subscription_settings(sub_row) { } exports.is_notification_setting = function (setting_label) { - if (setting_label.indexOf("_notifications") > -1) { + if (setting_label.includes("_notifications")) { return true; - } else if (setting_label.indexOf("_notify") > -1) { + } else if (setting_label.includes("_notify")) { return true; } return false; diff --git a/static/js/ui.js b/static/js/ui.js index 0f28ad953e..9477ab4b1e 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -165,7 +165,7 @@ exports.maybe_show_deprecation_notice = function (key) { } } - if (shown_deprecation_notices.indexOf(key) === -1) { + if (!shown_deprecation_notices.includes(key)) { $('#deprecation-notice-modal').modal('show'); $('#deprecation-notice-message').text(message); $('#close-deprecation-notice').focus(); diff --git a/static/js/upload_widget.js b/static/js/upload_widget.js index a082eaca3e..956bc3c848 100644 --- a/static/js/upload_widget.js +++ b/static/js/upload_widget.js @@ -12,7 +12,7 @@ function is_image_format(file) { if (!type) { return false; } - return supported_types.indexOf(type) >= 0; + return supported_types.includes(type); } exports.build_widget = function ( diff --git a/static/js/user_pill.js b/static/js/user_pill.js index 7025408706..88cf95cfcf 100644 --- a/static/js/user_pill.js +++ b/static/js/user_pill.js @@ -9,7 +9,7 @@ exports.create_item_from_email = function (email, current_items) { if (page_params.realm_is_zephyr_mirror_realm) { const existing_emails = _.pluck(current_items, 'email'); - if (existing_emails.indexOf(email) >= 0) { + if (existing_emails.includes(email)) { return; } @@ -28,7 +28,7 @@ exports.create_item_from_email = function (email, current_items) { const existing_ids = _.pluck(current_items, 'user_id'); - if (existing_ids.indexOf(user.user_id) >= 0) { + if (existing_ids.includes(user.user_id)) { return; } @@ -95,7 +95,7 @@ exports.typeahead_source = function (pill_widget) { exports.filter_taken_users = function (items, pill_widget) { const taken_user_ids = exports.get_user_ids(pill_widget); items = _.filter(items, function (item) { - return taken_user_ids.indexOf(item.user_id) === -1; + return !taken_user_ids.includes(item.user_id); }); return items; }; @@ -134,8 +134,8 @@ exports.set_up_typeahead_on_pills = function (input, pills, update_func) { matcher: function (item) { let query = this.query.toLowerCase(); query = query.replace(/\u00A0/g, String.fromCharCode(32)); - return item.email.toLowerCase().indexOf(query) !== -1 - || item.full_name.toLowerCase().indexOf(query) !== -1; + return item.email.toLowerCase().includes(query) + || item.full_name.toLowerCase().includes(query); }, sorter: function (matches) { return typeahead_helper.sort_recipientbox_typeahead( diff --git a/static/js/util.js b/static/js/util.js index e84f227603..eb33aca8d8 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -67,7 +67,7 @@ exports.same_stream_and_topic = function util_same_stream_and_topic(a, b) { exports.is_pm_recipient = function (email, message) { const recipients = message.reply_to.toLowerCase().split(','); - return recipients.indexOf(email.toLowerCase()) !== -1; + return recipients.includes(email.toLowerCase()); }; exports.extract_pm_recipients = function (recipients) { diff --git a/static/js/zcommand.js b/static/js/zcommand.js index fe1e137839..3af04bbdf0 100644 --- a/static/js/zcommand.js +++ b/static/js/zcommand.js @@ -111,13 +111,13 @@ exports.process = function (message_content) { } const day_commands = ['/day', '/light']; - if (day_commands.indexOf(content) >= 0) { + if (day_commands.includes(content)) { exports.enter_day_mode(); return true; } const night_commands = ['/night', '/dark']; - if (night_commands.indexOf(content) >= 0) { + if (night_commands.includes(content)) { exports.enter_night_mode(); return true; } diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js index b0f20d9f49..0f71b1fb04 100644 --- a/static/shared/js/typeahead.js +++ b/static/shared/js/typeahead.js @@ -64,7 +64,7 @@ function query_matches_string(query, source_str, split_char) { } // For a single token, the match can be anywhere in the string. - return source_str.indexOf(query) !== -1; + return source_str.includes(query); } // This function attempts to match a query with source's attributes. diff --git a/tools/check-openapi b/tools/check-openapi index b2ae6d77c5..ee4ee01401 100755 --- a/tools/check-openapi +++ b/tools/check-openapi @@ -9,7 +9,7 @@ function check_duplicate_operationids(file, api) { for (const value of endpoint) { const operation_id = value.operationId; if (operation_id !== undefined) { - if (operation_ids.indexOf(operation_id) >= 0) { + if (operation_ids.includes(operation_id)) { console.error('In', file + ':'); console.error('Duplicate operationId:', operation_id); process.exitCode = 1; diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index e2f09b2d68..20441a9cd1 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -132,9 +132,6 @@ js_rules = RuleList( 'description': 'Do not concatenate i18n strings'}, {'pattern': r'\+.*i18n\.t\(.+\)', 'description': 'Do not concatenate i18n strings'}, - {'pattern': '[.]includes[(]', - 'exclude': {'frontend_tests/'}, - 'description': '.includes() is incompatible with Internet Explorer. Use .indexOf() !== -1 instead.'}, {'pattern': '[.]html[(]', 'exclude_pattern': r'''[.]html[(]("|'|render_|html|message.content|sub.rendered_description|i18n.t|rendered_|$|[)]|error_text|widget_elem|[$]error|[$][(]"
"[)])''', 'exclude': {'static/js/portico', 'static/js/lightbox.js', 'static/js/ui_report.js',