Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

eslint: Fix unicorn/prefer-unicode-code-point-escapes.

Anders Kaseorg63d02db2d4fb
diff --git a/tools/check-openapi.ts b/tools/check-openapi.ts
index e83d8def4e6..719122f3a4d 100755
--- a/tools/check-openapi.ts
+++ b/tools/check-openapi.ts
@@ -129,17 +129,17 @@ async function checkFile(file: string): Promise<void> {
let diff = "";
for (const part of Diff.diffLines(description, formatted)) {
const prefix = part.added
- ? "\u001B[32m+"
+ ? "\u{1B}[32m+"
: part.removed
- ? "\u001B[31m-"
- : "\u001B[34m ";
+ ? "\u{1B}[31m-"
+ : "\u{1B}[34m ";
diff += prefix;
diff += part.value
.replace(/\n$/, "")
.replaceAll("\n", "\n" + prefix);
diff += "\n";
}
- diff += "\u001B[0m";
+ diff += "\u{1B}[0m";
console.error(diff);
}
}
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index c63f4cee703..7e6a3f761fd 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -995,7 +995,7 @@ export function get_candidates(
// already-completed object.
// We will likely want to extend this list to be more i18n-friendly.
- const terminal_symbols = ",.;?!()[]> \u00A0\"'\n\t";
+ const terminal_symbols = ",.;?!()[]> \u{A0}\"'\n\t";
if (rest !== "" && !terminal_symbols.includes(rest[0]!)) {
return [];
}
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 51f42029b8f..a9bbc6d8c71 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -356,7 +356,7 @@ export class Filter {
// phrase search behavior, however. So, we replace all instances of
// curly quotes with regular quotes when doing a search. This is
// unlikely to cause any problems and is probably what the user wants.
- narrow_term.operand = narrow_term.operand.replaceAll(/[\u201C\u201D]/g, '"');
+ narrow_term.operand = narrow_term.operand.replaceAll(/[\u{201C}\u{201D}]/gu, '"');
break;
case "date":
break;
diff --git a/web/src/markdown.ts b/web/src/markdown.ts
index c14917ae07f..3a51a0f8e13 100644
--- a/web/src/markdown.ts
+++ b/web/src/markdown.ts
@@ -490,13 +490,13 @@ function handleUnicodeEmoji(
// in boxes) into qualified emoji (images).
// More specifically, we skip anything with text in the second column of
// this table https://unicode.org/Public/emoji/1.0/emoji-data.txt
- if (/^\P{Emoji_Presentation}\u20E3?$/u.test(unicode_emoji)) {
+ if (/^\P{Emoji_Presentation}\u{20E3}?$/u.test(unicode_emoji)) {
return unicode_emoji;
}
// This unqualifies qualified emoji, which helps us make sure we
// can match both versions.
- const unqualified_unicode_emoji = unicode_emoji.replace(/\uFE0F/, "");
+ const unqualified_unicode_emoji = unicode_emoji.replace(/\u{FE0F}/u, "");
const codepoint = [...unqualified_unicode_emoji]
.map((char) => (char.codePointAt(0)?.toString(16) ?? "").padStart(4, "0"))
diff --git a/web/src/pill_typeahead.ts b/web/src/pill_typeahead.ts
index 1bf5d5e6c58..7653c78e5f7 100644
--- a/web/src/pill_typeahead.ts
+++ b/web/src/pill_typeahead.ts
@@ -106,7 +106,7 @@ export function set_up_stream(
},
matcher(query: string): (item: StreamPillData) => boolean {
query = query.toLowerCase();
- query = query.replaceAll("\u00A0", " ");
+ query = query.replaceAll("\u{A0}", " ");
query = query.trim();
if (query.startsWith("#")) {
query = query.slice(1);
diff --git a/web/src/typeahead.ts b/web/src/typeahead.ts
index f0b0dd5693b..972e1c9ba24 100644
--- a/web/src/typeahead.ts
+++ b/web/src/typeahead.ts
@@ -215,7 +215,7 @@ function clean_query(query: string, should_remove_diacritics: boolean): string {
// direct message 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.replaceAll("\u00A0", " ");
+ query = query.replaceAll("\u{A0}", " ");
return query;
}
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index 95602217303..d0549f69bee 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -1698,7 +1698,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
// Adds a `no break-space` at the end. This should fail
// if there wasn't any logic replacing `no break-space`
// with normal space.
- query = "cordelia, lear's\u00A0";
+ query = "cordelia, lear's\u{A0}";
assert.equal(matcher(query, cordelia_item), true);
assert.equal(matcher(query, othello_item), false);
@@ -2776,7 +2776,7 @@ test("begins_typeahead", ({override, override_rewire}) => {
assert_typeahead_equals(":test", "ing", []);
assert_typeahead_equals("```test", "ing", []);
assert_typeahead_equals("~~~test", "ing", []);
- const terminal_symbols = ",.;?!()[]> \u00A0\"'\n\t";
+ const terminal_symbols = ",.;?!()[]> \u{A0}\"'\n\t";
for (const symbol of terminal_symbols.split()) {
assert_typeahead_equals(
"@othello",
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 3e6d50864bb..b9cb1f0e6e9 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -1899,7 +1899,7 @@ test("unparse", () => {
string = `channel:${foo_stream_id} topic:Bar`;
assert.deepEqual(Filter.unparse(terms), string);
- terms = [{operator: "topic", operand: '\t "%+.\u00A0'}];
+ terms = [{operator: "topic", operand: '\t "%+.\u{A0}'}];
string = "topic:%09+%22%25%2B.%C2%A0";
assert.equal(Filter.unparse(terms), string);
assert_same_terms(Filter.parse(string), terms);
diff --git a/web/tests/lib/mdiff.cjs b/web/tests/lib/mdiff.cjs
index 7f8df585e6b..158206cfb3f 100644
--- a/web/tests/lib/mdiff.cjs
+++ b/web/tests/lib/mdiff.cjs
@@ -21,9 +21,9 @@ function apply_color(input_string, changes) {
input_string = input_string.slice(2);
const formatter = new Map([
- ["delete", (string) => "\u001B[31m" + string + "\u001B[0m"],
- ["insert", (string) => "\u001B[32m" + string + "\u001B[0m"],
- ["replace", (string) => "\u001B[33m" + string + "\u001B[0m"],
+ ["delete", (string) => "\u{1B}[31m" + string + "\u{1B}[0m"],
+ ["insert", (string) => "\u{1B}[32m" + string + "\u{1B}[0m"],
+ ["replace", (string) => "\u{1B}[33m" + string + "\u{1B}[0m"],
]);
for (const change of changes) {
if (formatter.has(change.tag)) {
@@ -116,7 +116,7 @@ function diff_strings(string_0, string_1) {
}
output_lines = output_lines.map(
- (string) => "\u001B[34m" + string.slice(0, 1) + "\u001B[0m" + string.slice(1),
+ (string) => "\u{1B}[34m" + string.slice(0, 1) + "\u{1B}[0m" + string.slice(1),
);
return output_lines.join("\n");
diff --git a/web/tests/markdown.test.cjs b/web/tests/markdown.test.cjs
index 43ca696988c..bd13e1b0f67 100644
--- a/web/tests/markdown.test.cjs
+++ b/web/tests/markdown.test.cjs
@@ -464,7 +464,7 @@ test("marked", ({override}) => {
'<p>This is an <span aria-label="poop" class="emoji emoji-1f4a9" role="img" title="poop">:poop:</span> message</p>',
},
{
- input: "\uD83D\uDCA9",
+ input: "\u{1F4A9}",
expected:
'<p><span aria-label="poop" class="emoji emoji-1f4a9" role="img" title="poop">:poop:</span></p>',
},
diff --git a/web/tests/markdown_parse.test.cjs b/web/tests/markdown_parse.test.cjs
index 65b162138a0..f46d937ce46 100644
--- a/web/tests/markdown_parse.test.cjs
+++ b/web/tests/markdown_parse.test.cjs
@@ -217,7 +217,7 @@ run_test("emojis", () => {
'<p>I <img alt=":heart:" class="emoji" src="/images/emoji/heart.bmp" title="heart"> JavaScript</p>',
);
assert_parse(
- "Mars Attacks! \uD83D\uDC7D",
+ "Mars Attacks! \u{1F47D}",
'<p>Mars Attacks! <span aria-label="alien" class="emoji emoji-1f47d" role="img" title="alien">:alien:</span></p>',
);
});
diff --git a/web/tests/rtl.test.cjs b/web/tests/rtl.test.cjs
index 9ada3cbbd00..f1223f3a14d 100644
--- a/web/tests/rtl.test.cjs
+++ b/web/tests/rtl.test.cjs
@@ -23,8 +23,8 @@ run_test("get_direction", () => {
assert.equal(rtl.get_direction("۱۲۳"), "ltr");
assert.equal(rtl.get_direction("1234"), "ltr");
- const supp_plane_ltr_char = "\uD800\uDFA0";
- const supp_plane_rtl_char = "\uD802\uDC40";
+ const supp_plane_ltr_char = "\u{103A0}";
+ const supp_plane_rtl_char = "\u{10840}";
assert.equal(rtl.get_direction(supp_plane_ltr_char), "ltr");
assert.equal(rtl.get_direction(supp_plane_rtl_char), "rtl");
@@ -41,8 +41,8 @@ run_test("get_direction", () => {
assert.equal(rtl.get_direction("b" + supp_plane_ltr_char + "." + supp_plane_rtl_char), "ltr");
assert.equal(rtl.get_direction("b" + supp_plane_rtl_char + "." + supp_plane_ltr_char), "ltr");
- const unmatched_surrogate_1 = "\uD800";
- const unmatched_surrogate_2 = "\uDF00";
+ const unmatched_surrogate_1 = "\u{D800}";
+ const unmatched_surrogate_2 = "\u{DF00}";
assert.equal(rtl.get_direction(unmatched_surrogate_1 + " "), "ltr");
assert.equal(rtl.get_direction(unmatched_surrogate_2 + " "), "ltr");
@@ -60,8 +60,8 @@ run_test("get_direction", () => {
assert.equal(rtl.get_direction(supp_plane_rtl_char + unmatched_surrogate_2), "rtl");
// Testing with some isolate initiators and PDIs.
- const i_chars = "\u2066\u2067\u2068";
- const pdi = "\u2069";
+ const i_chars = "\u{2066}\u{2067}\u{2068}";
+ const pdi = "\u{2069}";
assert.equal(rtl.get_direction("aa" + i_chars.charAt(0) + "bb" + pdi + "cc"), "ltr");
assert.equal(rtl.get_direction("دد" + i_chars.charAt(0) + "bb" + pdi + "cc"), "rtl");