mirror of https://github.com/zulip/zulip.git
eslint: Fix unicorn/prefer-string-replace-all.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
fe54df0b01
commit
54f90e41c0
|
@ -106,7 +106,7 @@ async function checkFile(file) {
|
||||||
diff += prefix;
|
diff += prefix;
|
||||||
diff += part.value
|
diff += part.value
|
||||||
.replace(/\n$/, "")
|
.replace(/\n$/, "")
|
||||||
.replace(/\n/g, "\n" + prefix);
|
.replaceAll("\n", "\n" + prefix);
|
||||||
diff += "\n";
|
diff += "\n";
|
||||||
}
|
}
|
||||||
diff += "\u001B[0m";
|
diff += "\u001B[0m";
|
||||||
|
|
|
@ -68,7 +68,7 @@ export function wrap_code(code: string, lang?: string): string {
|
||||||
}
|
}
|
||||||
// Trim trailing \n until there's just one left
|
// Trim trailing \n until there's just one left
|
||||||
// This mirrors how pygments handles code input
|
// This mirrors how pygments handles code input
|
||||||
return header + _.escape(code.replace(/^\n+|\n+$/g, "")) + "\n</code></pre></div>";
|
return header + _.escape(code.replaceAll(/^\n+|\n+$/g, "")) + "\n</code></pre></div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap_quote(text: string): string {
|
function wrap_quote(text: string): string {
|
||||||
|
|
|
@ -9,7 +9,9 @@ const hashReplacements = new Map([
|
||||||
// window.location.hash. So we hide our URI-encoding
|
// window.location.hash. So we hide our URI-encoding
|
||||||
// by replacing % with . (like MediaWiki).
|
// by replacing % with . (like MediaWiki).
|
||||||
export function encodeHashComponent(str) {
|
export function encodeHashComponent(str) {
|
||||||
return encodeURIComponent(str).replace(/[%().]/g, (matched) => hashReplacements.get(matched));
|
return encodeURIComponent(str).replaceAll(/[%().]/g, (matched) =>
|
||||||
|
hashReplacements.get(matched),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeHashComponent(str) {
|
export function decodeHashComponent(str) {
|
||||||
|
@ -18,7 +20,7 @@ export function decodeHashComponent(str) {
|
||||||
// of such characters when encoding. This can also,
|
// of such characters when encoding. This can also,
|
||||||
// fail independent of our fault.
|
// fail independent of our fault.
|
||||||
// Here we let the calling code handle the exception.
|
// Here we let the calling code handle the exception.
|
||||||
return decodeURIComponent(str.replace(/\./g, "%"));
|
return decodeURIComponent(str.replaceAll(".", "%"));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stream_id_to_slug(stream_id, maybe_get_stream_name) {
|
export function stream_id_to_slug(stream_id, maybe_get_stream_name) {
|
||||||
|
@ -29,7 +31,7 @@ export function stream_id_to_slug(stream_id, maybe_get_stream_name) {
|
||||||
|
|
||||||
// TODO: Convert this to replaceAll once mobile no longer supports
|
// TODO: Convert this to replaceAll once mobile no longer supports
|
||||||
// browsers that don't have it.
|
// browsers that don't have it.
|
||||||
name = name.replace(/ /g, "-");
|
name = name.replaceAll(" ", "-");
|
||||||
|
|
||||||
return stream_id + "-" + name;
|
return stream_id + "-" + name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ type UnicodeEmoji = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function remove_diacritics(s: string): string {
|
export function remove_diacritics(s: string): string {
|
||||||
return s.normalize("NFKD").replace(unicode_marks, "");
|
return s.normalize("NFKD").replaceAll(unicode_marks, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function attempts to match a query with a source text.
|
// This function attempts to match a query with a source text.
|
||||||
|
@ -79,7 +79,7 @@ function clean_query(query: string): string {
|
||||||
// contenteditable widget such as the composebox PM section, the
|
// contenteditable widget such as the composebox PM section, the
|
||||||
// space at the end was a `no break-space (U+00A0)` instead of
|
// space at the end was a `no break-space (U+00A0)` instead of
|
||||||
// `space (U+0020)`, which lead to no matches in those cases.
|
// `space (U+0020)`, which lead to no matches in those cases.
|
||||||
query = query.replace(/\u00A0/g, " ");
|
query = query.replaceAll("\u00A0", " ");
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ export const parse_unicode_emoji_code = (code: string): string =>
|
||||||
|
|
||||||
export function get_emoji_matcher(query: string): (emoji: Emoji) => boolean {
|
export function get_emoji_matcher(query: string): (emoji: Emoji) => boolean {
|
||||||
// replace spaces with underscores for emoji matching
|
// replace spaces with underscores for emoji matching
|
||||||
query = query.replace(/ /g, "_");
|
query = query.replaceAll(" ", "_");
|
||||||
query = clean_query_lowercase(query);
|
query = clean_query_lowercase(query);
|
||||||
|
|
||||||
return function (emoji) {
|
return function (emoji) {
|
||||||
|
@ -166,7 +166,7 @@ export function triage<T>(
|
||||||
|
|
||||||
export function sort_emojis<T extends Emoji>(objs: T[], query: string): T[] {
|
export function sort_emojis<T extends Emoji>(objs: T[], query: string): T[] {
|
||||||
// replace spaces with underscores for emoji matching
|
// replace spaces with underscores for emoji matching
|
||||||
query = query.replace(/ /g, "_");
|
query = query.replaceAll(" ", "_");
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
|
|
||||||
function decent_match(name: string): boolean {
|
function decent_match(name: string): boolean {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export function process_message(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const word of my_alert_words) {
|
for (const word of my_alert_words) {
|
||||||
const clean = _.escapeRegExp(word).replace(/["&'<>]/g, (c) =>
|
const clean = _.escapeRegExp(word).replaceAll(/["&'<>]/g, (c) =>
|
||||||
alert_regex_replacements.get(c),
|
alert_regex_replacements.get(c),
|
||||||
);
|
);
|
||||||
const before_punctuation = "\\s|^|>|[\\(\\\".,';\\[]";
|
const before_punctuation = "\\s|^|>|[\\(\\\".,';\\[]";
|
||||||
|
|
|
@ -224,7 +224,9 @@ export function start(msg_type, opts) {
|
||||||
compose_state.topic(opts.topic);
|
compose_state.topic(opts.topic);
|
||||||
|
|
||||||
// Set the recipients with a space after each comma, so it looks nice.
|
// Set the recipients with a space after each comma, so it looks nice.
|
||||||
compose_state.private_message_recipient(opts.private_message_recipient.replace(/,\s*/g, ", "));
|
compose_state.private_message_recipient(
|
||||||
|
opts.private_message_recipient.replaceAll(/,\s*/g, ", "),
|
||||||
|
);
|
||||||
|
|
||||||
// If the user opens the compose box, types some text, and then clicks on a
|
// If the user opens the compose box, types some text, and then clicks on a
|
||||||
// different stream/topic, we want to keep the text in the compose box
|
// different stream/topic, we want to keep the text in the compose box
|
||||||
|
|
|
@ -43,7 +43,7 @@ function construct_recipient_header($message_row) {
|
||||||
const message_header_content = rows
|
const message_header_content = rows
|
||||||
.get_message_recipient_header($message_row)
|
.get_message_recipient_header($message_row)
|
||||||
.text()
|
.text()
|
||||||
.replace(/\s+/g, " ")
|
.replaceAll(/\s+/g, " ")
|
||||||
.replace(/^\s/, "")
|
.replace(/^\s/, "")
|
||||||
.replace(/\s$/, "");
|
.replace(/\s$/, "");
|
||||||
return $("<p>").append($("<strong>").text(message_header_content));
|
return $("<p>").append($("<strong>").text(message_header_content));
|
||||||
|
@ -322,10 +322,10 @@ export function paste_handler_converter(paste_html) {
|
||||||
let markdown_text = turndownService.turndown(paste_html);
|
let markdown_text = turndownService.turndown(paste_html);
|
||||||
|
|
||||||
// Checks for escaped ordered list syntax.
|
// Checks for escaped ordered list syntax.
|
||||||
markdown_text = markdown_text.replace(/^(\W* {0,3})(\d+)\\\. /gm, "$1$2. ");
|
markdown_text = markdown_text.replaceAll(/^(\W* {0,3})(\d+)\\\. /gm, "$1$2. ");
|
||||||
|
|
||||||
// Removes newlines before the start of a list and between list elements.
|
// Removes newlines before the start of a list and between list elements.
|
||||||
markdown_text = markdown_text.replace(/\n+([*+-])/g, "\n$1");
|
markdown_text = markdown_text.replaceAll(/\n+([*+-])/g, "\n$1");
|
||||||
return markdown_text;
|
return markdown_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ function update_emoji_showcase($focused_emoji) {
|
||||||
|
|
||||||
const emoji_dict = {
|
const emoji_dict = {
|
||||||
...focused_emoji_dict,
|
...focused_emoji_dict,
|
||||||
name: focused_emoji_name.replace(/_/g, " "),
|
name: focused_emoji_name.replaceAll("_", " "),
|
||||||
};
|
};
|
||||||
const rendered_showcase = render_emoji_showcase({
|
const rendered_showcase = render_emoji_showcase({
|
||||||
emoji_dict,
|
emoji_dict,
|
||||||
|
|
|
@ -271,7 +271,7 @@ export class Filter {
|
||||||
operand = operand
|
operand = operand
|
||||||
.toString()
|
.toString()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[\u201C\u201D]/g, '"');
|
.replaceAll(/[\u201C\u201D]/g, '"');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
operand = operand.toString().toLowerCase();
|
operand = operand.toString().toLowerCase();
|
||||||
|
@ -294,20 +294,20 @@ export class Filter {
|
||||||
URI encoding to avoid problematic characters. */
|
URI encoding to avoid problematic characters. */
|
||||||
static encodeOperand(operand) {
|
static encodeOperand(operand) {
|
||||||
return operand
|
return operand
|
||||||
.replace(/%/g, "%25")
|
.replaceAll("%", "%25")
|
||||||
.replace(/\+/g, "%2B")
|
.replaceAll("+", "%2B")
|
||||||
.replace(/ /g, "+")
|
.replaceAll(" ", "+")
|
||||||
.replace(/"/g, "%22");
|
.replaceAll('"', "%22");
|
||||||
}
|
}
|
||||||
|
|
||||||
static decodeOperand(encoded, operator) {
|
static decodeOperand(encoded, operator) {
|
||||||
encoded = encoded.replace(/"/g, "");
|
encoded = encoded.replaceAll('"', "");
|
||||||
if (
|
if (
|
||||||
["dm-including", "dm", "sender", "from", "pm-with", "group-pm-with"].includes(
|
["dm-including", "dm", "sender", "from", "pm-with", "group-pm-with"].includes(
|
||||||
operator,
|
operator,
|
||||||
) === false
|
) === false
|
||||||
) {
|
) {
|
||||||
encoded = encoded.replace(/\+/g, " ");
|
encoded = encoded.replaceAll("+", " ");
|
||||||
}
|
}
|
||||||
return util.robust_url_decode(encoded).trim();
|
return util.robust_url_decode(encoded).trim();
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,13 +232,13 @@ function parse_with_options({raw_content, helper_config, options}) {
|
||||||
},
|
},
|
||||||
silencedMentionHandler(quote) {
|
silencedMentionHandler(quote) {
|
||||||
// Silence quoted mentions.
|
// Silence quoted mentions.
|
||||||
quote = quote.replace(
|
quote = quote.replaceAll(
|
||||||
/(<span class="user-mention)(" data-user-id="(\d+|\*)">)@/g,
|
/(<span class="user-mention)(" data-user-id="(\d+|\*)">)@/g,
|
||||||
"$1 silent$2",
|
"$1 silent$2",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Silence quoted user group mentions.
|
// Silence quoted user group mentions.
|
||||||
quote = quote.replace(
|
quote = quote.replaceAll(
|
||||||
/(<span class="user-group-mention)(" data-user-group-id="\d+">)@/g,
|
/(<span class="user-group-mention)(" data-user-group-id="\d+">)@/g,
|
||||||
"$1 silent$2",
|
"$1 silent$2",
|
||||||
);
|
);
|
||||||
|
@ -375,7 +375,7 @@ function handleUnicodeEmoji({unicode_emoji, get_emoji_name}) {
|
||||||
|
|
||||||
if (emoji_name) {
|
if (emoji_name) {
|
||||||
const alt_text = ":" + emoji_name + ":";
|
const alt_text = ":" + emoji_name + ":";
|
||||||
const title = emoji_name.replace(/_/g, " ");
|
const title = emoji_name.replaceAll("_", " ");
|
||||||
return make_emoji_span(codepoint, title, alt_text);
|
return make_emoji_span(codepoint, title, alt_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ function handleUnicodeEmoji({unicode_emoji, get_emoji_name}) {
|
||||||
|
|
||||||
function handleEmoji({emoji_name, get_realm_emoji_url, get_emoji_codepoint}) {
|
function handleEmoji({emoji_name, get_realm_emoji_url, get_emoji_codepoint}) {
|
||||||
const alt_text = ":" + emoji_name + ":";
|
const alt_text = ":" + emoji_name + ":";
|
||||||
const title = emoji_name.replace(/_/g, " ");
|
const title = emoji_name.replaceAll("_", " ");
|
||||||
|
|
||||||
// Zulip supports both standard/Unicode emoji, served by a
|
// Zulip supports both standard/Unicode emoji, served by a
|
||||||
// spritesheet and custom realm-specific emoji (served by URL).
|
// spritesheet and custom realm-specific emoji (served by URL).
|
||||||
|
|
|
@ -328,7 +328,8 @@ export function process_notification(notification) {
|
||||||
if (content.length + title.length + other_recipients.length > 230) {
|
if (content.length + title.length + other_recipients.length > 230) {
|
||||||
// Then count how many people are in the conversation and summarize
|
// Then count how many people are in the conversation and summarize
|
||||||
// by saying the conversation is with "you and [number] other people"
|
// by saying the conversation is with "you and [number] other people"
|
||||||
other_recipients = other_recipients.replace(/[^,]/g, "").length + " other people";
|
other_recipients =
|
||||||
|
other_recipients.replaceAll(/[^,]/g, "").length + " other people";
|
||||||
}
|
}
|
||||||
|
|
||||||
title += " (to you and " + other_recipients + ")";
|
title += " (to you and " + other_recipients + ")";
|
||||||
|
|
|
@ -530,7 +530,7 @@ export function pm_with_url(message) {
|
||||||
} else {
|
} else {
|
||||||
const person = get_by_user_id(user_ids[0]);
|
const person = get_by_user_id(user_ids[0]);
|
||||||
if (person && person.full_name) {
|
if (person && person.full_name) {
|
||||||
suffix = person.full_name.replace(/[ "%/<>`\p{C}]+/gu, "-");
|
suffix = person.full_name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-");
|
||||||
} else {
|
} else {
|
||||||
blueslip.error("Unknown people in message");
|
blueslip.error("Unknown people in message");
|
||||||
suffix = "unk";
|
suffix = "unk";
|
||||||
|
@ -605,7 +605,7 @@ export function emails_to_slug(emails_string) {
|
||||||
|
|
||||||
if (emails.length === 1) {
|
if (emails.length === 1) {
|
||||||
const name = get_by_email(emails[0]).full_name;
|
const name = get_by_email(emails[0]).full_name;
|
||||||
slug += name.replace(/[ "%/<>`\p{C}]+/gu, "-");
|
slug += name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-");
|
||||||
} else {
|
} else {
|
||||||
slug += "group";
|
slug += "group";
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ export function set_up($input, pills, opts) {
|
||||||
},
|
},
|
||||||
matcher(item) {
|
matcher(item) {
|
||||||
let query = this.query.toLowerCase();
|
let query = this.query.toLowerCase();
|
||||||
query = query.replace(/\u00A0/g, " ");
|
query = query.replaceAll("\u00A0", " ");
|
||||||
|
|
||||||
if (include_streams(query)) {
|
if (include_streams(query)) {
|
||||||
query = query.trim().slice(1);
|
query = query.trim().slice(1);
|
||||||
|
|
|
@ -79,7 +79,7 @@ function sort_author_full_name(a, b) {
|
||||||
function is_default_emoji(emoji_name) {
|
function is_default_emoji(emoji_name) {
|
||||||
// Spaces are replaced with `_` to match how the emoji name will
|
// Spaces are replaced with `_` to match how the emoji name will
|
||||||
// actually be stored in the backend.
|
// actually be stored in the backend.
|
||||||
return emoji_codes.names.includes(emoji_name.replace(/ /g, "_"));
|
return emoji_codes.names.includes(emoji_name.replaceAll(" ", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_custom_emoji(emoji_name) {
|
function is_custom_emoji(emoji_name) {
|
||||||
|
@ -116,7 +116,7 @@ export function populate_emoji() {
|
||||||
return render_admin_emoji_list({
|
return render_admin_emoji_list({
|
||||||
emoji: {
|
emoji: {
|
||||||
name: item.name,
|
name: item.name,
|
||||||
display_name: item.name.replace(/_/g, " "),
|
display_name: item.name.replaceAll("_", " "),
|
||||||
source_url: item.source_url,
|
source_url: item.source_url,
|
||||||
author: item.author || "",
|
author: item.author || "",
|
||||||
can_delete_emoji: can_delete_emoji(item),
|
can_delete_emoji: can_delete_emoji(item),
|
||||||
|
|
|
@ -190,7 +190,7 @@ export function extract_property_name($elem, for_realm_default_settings) {
|
||||||
// "realm_{settings_name}}" because both user and realm default
|
// "realm_{settings_name}}" because both user and realm default
|
||||||
// settings use the same template and each element should have
|
// settings use the same template and each element should have
|
||||||
// unique id.
|
// unique id.
|
||||||
return /^realm_(.*)$/.exec($elem.attr("id").replace(/-/g, "_"))[1];
|
return /^realm_(.*)$/.exec($elem.attr("id").replaceAll("-", "_"))[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($elem.attr("id").startsWith("id_authmethod")) {
|
if ($elem.attr("id").startsWith("id_authmethod")) {
|
||||||
|
@ -203,7 +203,7 @@ export function extract_property_name($elem, for_realm_default_settings) {
|
||||||
return /^id_authmethod[\da-z]+_(.*)$/.exec($elem.attr("id"))[1];
|
return /^id_authmethod[\da-z]+_(.*)$/.exec($elem.attr("id"))[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return /^id_(.*)$/.exec($elem.attr("id").replace(/-/g, "_"))[1];
|
return /^id_(.*)$/.exec($elem.attr("id").replaceAll("-", "_"))[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_subsection_property_elements(subsection) {
|
export function get_subsection_property_elements(subsection) {
|
||||||
|
@ -545,7 +545,7 @@ export function populate_auth_methods(auth_methods) {
|
||||||
// As a result, the only two "incoming" assumptions on the auth method name are:
|
// As a result, the only two "incoming" assumptions on the auth method name are:
|
||||||
// 1) It contains at least one allowed symbol
|
// 1) It contains at least one allowed symbol
|
||||||
// 2) No two auth method names are identical after this allowlist filtering
|
// 2) No two auth method names are identical after this allowlist filtering
|
||||||
prefix: "id_authmethod" + auth_method.toLowerCase().replace(/[^\da-z]/g, "") + "_",
|
prefix: "id_authmethod" + auth_method.toLowerCase().replaceAll(/[^\da-z]/g, "") + "_",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$auth_methods_list.html(rendered_auth_method_rows);
|
$auth_methods_list.html(rendered_auth_method_rows);
|
||||||
|
@ -1230,7 +1230,7 @@ export function register_save_discard_widget_handlers(
|
||||||
// fields that must be submitted together, which is
|
// fields that must be submitted together, which is
|
||||||
// managed by the get_complete_data_for_subsection function.
|
// managed by the get_complete_data_for_subsection function.
|
||||||
const [, subsection_id] = /^org-(.*)$/.exec($subsection_elem.attr("id"));
|
const [, subsection_id] = /^org-(.*)$/.exec($subsection_elem.attr("id"));
|
||||||
const subsection = subsection_id.replace(/-/g, "_");
|
const subsection = subsection_id.replaceAll("-", "_");
|
||||||
extra_data = get_complete_data_for_subsection(subsection);
|
extra_data = get_complete_data_for_subsection(subsection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ export function render_stream(stream) {
|
||||||
export function render_emoji(item) {
|
export function render_emoji(item) {
|
||||||
const args = {
|
const args = {
|
||||||
is_emoji: true,
|
is_emoji: true,
|
||||||
primary: item.emoji_name.replace(/_/g, " "),
|
primary: item.emoji_name.replaceAll("_", " "),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item.emoji_url) {
|
if (item.emoji_url) {
|
||||||
|
|
Loading…
Reference in New Issue