mirror of https://github.com/zulip/zulip.git
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer. import * as babelParser from "recast/parsers/babel"; import * as recast from "recast"; import * as tsParser from "recast/parsers/typescript"; import { builders as b, namedTypes as n } from "ast-types"; import K from "ast-types/gen/kinds"; import fs from "fs"; import path from "path"; import process from "process"; const checkExpression = (node: n.Node): node is K.ExpressionKind => n.Expression.check(node); for (const file of process.argv.slice(2)) { console.log("Parsing", file); const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), { parser: path.extname(file) === ".ts" ? tsParser : babelParser, }); let changed = false; recast.visit(ast, { visitBinaryExpression(path) { const { operator, left, right } = path.node; if ( n.CallExpression.check(left) && n.MemberExpression.check(left.callee) && !left.callee.computed && n.Identifier.check(left.callee.property) && left.callee.property.name === "indexOf" && left.arguments.length === 1 && checkExpression(left.arguments[0]) && ((["===", "!==", "==", "!=", ">", "<="].includes(operator) && n.UnaryExpression.check(right) && right.operator == "-" && n.Literal.check(right.argument) && right.argument.value === 1) || ([">=", "<"].includes(operator) && n.Literal.check(right) && right.value === 0)) ) { const test = b.callExpression( b.memberExpression(left.callee.object, b.identifier("includes")), [left.arguments[0]] ); path.replace( ["!==", "!=", ">", ">="].includes(operator) ? test : b.unaryExpression("!", test) ); changed = true; } this.traverse(path); }, }); if (changed) { console.log("Writing", file); fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" }); } } Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
788c5afbcf
commit
719546641f
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1754,8 +1754,8 @@ run_test('recipient_row', () => {
|
|||
],
|
||||
};
|
||||
const html = render('recipient_row', data);
|
||||
assert(html.indexOf('<script>alert("Hello")</script>') === -1);
|
||||
assert(html.indexOf('<script>alert("Hello")</script>') !== -1);
|
||||
assert(!html.includes('<script>alert("Hello")</script>'));
|
||||
assert(html.includes('<script>alert("Hello")</script>'));
|
||||
});
|
||||
|
||||
run_test('invitation_failed_error', () => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 +
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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}));
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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|[$][(]"<p>"[)])''',
|
||||
'exclude': {'static/js/portico', 'static/js/lightbox.js', 'static/js/ui_report.js',
|
||||
|
|
Loading…
Reference in New Issue