eslint: Fix unicorn/prefer-string-replace-all.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-05-11 12:49:10 -07:00
committed by Tim Abbott
parent fe54df0b01
commit 54f90e41c0
16 changed files with 42 additions and 37 deletions

View File

@@ -68,7 +68,7 @@ export function wrap_code(code: string, lang?: string): string {
}
// Trim trailing \n until there's just one left
// 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 {

View File

@@ -9,7 +9,9 @@ const hashReplacements = new Map([
// window.location.hash. So we hide our URI-encoding
// by replacing % with . (like MediaWiki).
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) {
@@ -18,7 +20,7 @@ export function decodeHashComponent(str) {
// of such characters when encoding. This can also,
// fail independent of our fault.
// 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) {
@@ -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
// browsers that don't have it.
name = name.replace(/ /g, "-");
name = name.replaceAll(" ", "-");
return stream_id + "-" + name;
}

View File

@@ -45,7 +45,7 @@ type UnicodeEmoji = {
};
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.
@@ -79,7 +79,7 @@ function clean_query(query: string): string {
// contenteditable widget such as the composebox PM section, the
// space at the end was a `no break-space (U+00A0)` instead of
// `space (U+0020)`, which lead to no matches in those cases.
query = query.replace(/\u00A0/g, " ");
query = query.replaceAll("\u00A0", " ");
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 {
// replace spaces with underscores for emoji matching
query = query.replace(/ /g, "_");
query = query.replaceAll(" ", "_");
query = clean_query_lowercase(query);
return function (emoji) {
@@ -166,7 +166,7 @@ export function triage<T>(
export function sort_emojis<T extends Emoji>(objs: T[], query: string): T[] {
// replace spaces with underscores for emoji matching
query = query.replace(/ /g, "_");
query = query.replaceAll(" ", "_");
query = query.toLowerCase();
function decent_match(name: string): boolean {