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-scoped-selector.

Anders Kaseorg0a7885d3ab40
diff --git a/web/e2e-tests/copy-messages.test.ts b/web/e2e-tests/copy-messages.test.ts
index 4bf615babe7..3d86b7952e8 100644
--- a/web/e2e-tests/copy-messages.test.ts
+++ b/web/e2e-tests/copy-messages.test.ts
@@ -33,7 +33,7 @@ async function copy_messages(
if (partial_selection_config?.select_start_message_partially) {
const offset = partial_selection_config.start_text_node_offset!;
const start_message_text_node =
- get_message_node(start_message).querySelector(".message_content p")?.firstChild;
+ get_message_node(start_message).querySelector("p")?.firstChild;
if (!(start_message_text_node instanceof Text)) {
throw new TypeError("Expected a Text node");
}
@@ -44,7 +44,7 @@ async function copy_messages(
if (partial_selection_config?.select_end_message_partially) {
const offset = partial_selection_config.end_text_node_offset!;
const end_message_text_node =
- get_message_node(end_message).querySelector(".message_content p")?.firstChild;
+ get_message_node(end_message).querySelector("p")?.firstChild;
if (!(end_message_text_node instanceof Text)) {
throw new TypeError("Expected a Text node");
}
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.ts
index de6da929c6e..e75a749f474 100644
--- a/web/src/compose_paste.ts
+++ b/web/src/compose_paste.ts
@@ -422,7 +422,7 @@ export function paste_handler_converter(
let consecutive_empty_display_count = 0;
for (const child of parent.children) {
const annotation_element = child.querySelector(
- '.katex-mathml annotation[encoding="application/x-tex"]',
+ ':scope .katex-mathml annotation[encoding="application/x-tex"]',
);
if (annotation_element?.textContent) {
const katex_source = annotation_element.textContent.trim();
diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts
index 2384d42795f..3fd1af0fafd 100644
--- a/web/src/compose_ui.ts
+++ b/web/src/compose_ui.ts
@@ -758,7 +758,7 @@ export function position_inside_code_block(content: string, position: number): b
content.slice(0, position) + unique_insert + content.slice(position);
const rendered_content = markdown.parse_non_message(unique_insert_content);
const rendered_html = new DOMParser().parseFromString(rendered_content, "text/html");
- const code_blocks = rendered_html.querySelectorAll("pre > code");
+ const code_blocks = rendered_html.querySelectorAll(":scope pre > code");
return [...code_blocks].some((code_block) => code_block?.textContent?.includes(unique_insert));
}
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index 4bdb7602116..2978ff7fecd 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -34,7 +34,9 @@ export function postprocess_content(html: string): string {
// We want to do this processing up front, so that embeds benefit
// from other processing below for links and images
for (const message_embed of template.content.querySelectorAll(".message_embed")) {
- const message_embed_title_link = message_embed.querySelector(".message_embed_title a");
+ const message_embed_title_link = message_embed.querySelector(
+ ":scope .message_embed_title a",
+ );
// Add a class to the anchor tag on embed-title links for easier
// reference from CSS
message_embed_title_link?.classList.add("message-embed-title-link");