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: Disable unicorn/prefer-dom-node-dataset.

Anders Kaseorg22ed67d4eab4
diff --git a/eslint.config.js b/eslint.config.js
index 29477a1e5f8..ebf1bfc902d 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -174,6 +174,7 @@ export default defineConfig(
"unicorn/no-process-exit": "off",
"unicorn/no-useless-undefined": "off",
"unicorn/numeric-separators-style": "off",
+ "unicorn/prefer-dom-node-dataset": "off",
"unicorn/prefer-global-this": "off",
"unicorn/prefer-string-raw": "off",
"unicorn/prefer-ternary": "off",
diff --git a/starlight_help/src/scripts/client/adjust_mac_kbd_tags.ts b/starlight_help/src/scripts/client/adjust_mac_kbd_tags.ts
index 51034c83702..cbf9740dc53 100644
--- a/starlight_help/src/scripts/client/adjust_mac_kbd_tags.ts
+++ b/starlight_help/src/scripts/client/adjust_mac_kbd_tags.ts
@@ -38,7 +38,7 @@ function adjust_mac_kbd_tags(): void {
// - The "Ctrl" + "[" shortcuts (which match the Vim keybinding behavior
// of mapping to "Esc") need to display "Ctrl" for all users, so we
// use this attribute to override "⌘" with "Ctrl".
- const replace_key: string | undefined = element.dataset.macKey ?? keys_map.get(key_text);
+ const replace_key = element.getAttribute("data-mac-key") ?? keys_map.get(key_text);
if (replace_key !== undefined) {
key_text = replace_key;
}
@@ -49,8 +49,8 @@ function adjust_mac_kbd_tags(): void {
// we use data-mac-following-key attribute to append the extra key to the
// previous key. Currently, this is used to append Opt to Cmd for the Paste
// as plain text shortcut.
- const following_key: string | undefined = element.dataset.macFollowingKey;
- if (following_key !== undefined) {
+ const following_key = element.getAttribute("data-mac-following-key");
+ if (following_key !== null) {
const kbd_elem: HTMLElement = document.createElement("kbd");
kbd_elem.textContent = following_key;
element.after(kbd_elem);
diff --git a/web/src/base_page_params.ts b/web/src/base_page_params.ts
index 8c8a8cf8fbc..64c63190ea0 100644
--- a/web/src/base_page_params.ts
+++ b/web/src/base_page_params.ts
@@ -114,11 +114,12 @@ function take_params(): string {
if (page_params_div === null) {
throw new Error("Missing #page-params");
}
- if (page_params_div.dataset.params === undefined) {
+ const params = page_params_div.getAttribute("data-params");
+ if (params === null) {
throw new Error("Missing #page_params[data-params]");
}
page_params_div.remove();
- return page_params_div.dataset.params;
+ return params;
}
export const page_params = page_params_schema.parse(JSON.parse(take_params()));
diff --git a/web/src/billing/sponsorship.ts b/web/src/billing/sponsorship.ts
index 53b9eb3378d..c15133160ba 100644
--- a/web/src/billing/sponsorship.ts
+++ b/web/src/billing/sponsorship.ts
@@ -109,8 +109,9 @@ export function initialize(): void {
function update_discount_details(): void {
const selected_org_type =
- the($<HTMLSelectElement>("select#organization-type")).selectedOptions[0]?.dataset
- .stringValue ?? "";
+ the($<HTMLSelectElement>("select#organization-type")).selectedOptions[0]?.getAttribute(
+ "data-string-value",
+ ) ?? "";
helpers.update_discount_details(selected_org_type, is_remotely_hosted);
}
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.ts
index 80b875d8db7..9540046d781 100644
--- a/web/src/compose_paste.ts
+++ b/web/src/compose_paste.ts
@@ -223,7 +223,6 @@ function get_code_block_language(
if (parent_contains_lang_metadata) {
const codehilite_element = pre_element.closest<HTMLElement>(".codehilite");
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
language = codehilite_element?.getAttribute("data-code-language") ?? "";
} else {
language = (/language-(\S+)/.exec(code_element_class_name) ?? [null, ""])[1];
diff --git a/web/src/compose_send_menu_popover.ts b/web/src/compose_send_menu_popover.ts
index a9779fdd497..d21b8e5bca9 100644
--- a/web/src/compose_send_menu_popover.ts
+++ b/web/src/compose_send_menu_popover.ts
@@ -25,8 +25,9 @@ const ENTER_SENDS_SELECTION_DELAY = 600;
let send_later_popover_keyboard_toggle = false;
function set_compose_box_schedule(element: HTMLElement): number {
- assert(element.dataset.sendStamp !== undefined);
- const selected_send_at_time = Number.parseInt(element.dataset.sendStamp, 10) / 1000;
+ const send_stamp = element.getAttribute("data-send-stamp");
+ assert(send_stamp !== null);
+ const selected_send_at_time = Number.parseInt(send_stamp, 10) / 1000;
return selected_send_at_time;
}
diff --git a/web/src/compose_setup.ts b/web/src/compose_setup.ts
index a8624ce3559..59cbfc9b790 100644
--- a/web/src/compose_setup.ts
+++ b/web/src/compose_setup.ts
@@ -151,7 +151,7 @@ export function initialize(): void {
compose_validate.set_user_acknowledged_stream_wildcard_flag(true);
if (is_edit_input) {
void message_edit.save_message_row_edit($row);
- } else if (event.target.dataset.validationTrigger === "schedule") {
+ } else if (event.target.getAttribute("data-validation-trigger") === "schedule") {
compose_send_menu_popover.open_schedule_message_menu(
undefined,
util.the($("#send_later i")),
diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts
index 5e949e1755d..ef229e4c248 100644
--- a/web/src/compose_ui.ts
+++ b/web/src/compose_ui.ts
@@ -175,10 +175,6 @@ export function maybe_show_scrolling_formatting_buttons(container_selector: stri
// Set these values as data attributes for ready access by
// other scrolling logic
- //
- // TODO: Modify eslint config, if we wish to avoid dataset
- //
- /* eslint unicorn/prefer-dom-node-dataset: "off" */
button_container.setAttribute("data-button-container-width", button_container_width.toString());
button_container.setAttribute("data-button-bar-width", button_bar_width.toString());
button_container.setAttribute(
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.ts
index 16485d754d5..7cd672d10c4 100644
--- a/web/src/message_list_view.ts
+++ b/web/src/message_list_view.ts
@@ -2182,7 +2182,6 @@ export class MessageListView {
show_messages_as_unread(message_ids: number[]): void {
const $rows_to_show_as_unread = this.$list.find(".message_row").filter((_index, $row) => {
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
const message_id = Number.parseFloat($row.getAttribute("data-message-id")!);
return message_ids.includes(message_id);
});
diff --git a/web/src/popover_menus.ts b/web/src/popover_menus.ts
index 22bae7bb01e..9ce707a5bd7 100644
--- a/web/src/popover_menus.ts
+++ b/web/src/popover_menus.ts
@@ -223,12 +223,8 @@ export const default_popover_props: Partial<tippy.Props> = {
const instance = (state.elements.popper as tippy.PopperElement)._tippy!;
const $popover = $(state.elements.popper);
const $tippy_box = $popover.find(".tippy-box");
- // $tippy_box[0].hasAttribute("data-reference-hidden"); is the real check
- // but linter wants us to write it like this.
- const is_reference_outside_window = Object.hasOwn(
- util.the($tippy_box).dataset,
- "referenceHidden",
- );
+ const is_reference_outside_window =
+ $tippy_box.attr("data-reference-hidden") !== undefined;
if ($tippy_box.hasClass("show-when-reference-hidden")) {
// Show user card popover as an overlay if we are not sure about position of the
diff --git a/web/src/portico/help.ts b/web/src/portico/help.ts
index cff95f4556c..14f1b39713f 100644
--- a/web/src/portico/help.ts
+++ b/web/src/portico/help.ts
@@ -14,7 +14,7 @@ function register_tabbed_section($tabbed_section: JQuery): void {
const $blocks = $tabbed_section.find(".blocks div");
$li.on("click", function () {
- const tab_key = this.dataset.tabKey;
+ const tab_key = this.getAttribute("data-tab-key");
$li.removeClass("active");
$li.filter("[data-tab-key=" + tab_key + "]").addClass("active");
diff --git a/web/src/portico/landing-page.ts b/web/src/portico/landing-page.ts
index 26138730635..36d0b40c710 100644
--- a/web/src/portico/landing-page.ts
+++ b/web/src/portico/landing-page.ts
@@ -3,7 +3,6 @@ import assert from "minimalistic-assert";
import * as z from "zod/mini";
import {page_params} from "../base_page_params.ts";
-import * as util from "../util.ts";
import type {UserOS} from "./tabbed-instructions.ts";
import {detect_user_os} from "./tabbed-instructions.ts";
@@ -284,7 +283,7 @@ $(document).on("click", ".comparison-tab", function (this: HTMLElement, _event:
const tab_label = z
.enum(["tab-cloud", "tab-hosted", "tab-all"])
- .parse(util.the($(this)).dataset.label);
+ .parse(this.getAttribute("data-label"));
const plans_columns_count = plans_columns_counts[tab_label];
const visible_plans_id = `showing-${tab_label}`;
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index 6f757781a78..cd2e039c61f 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -180,7 +180,6 @@ export function postprocess_content(html: string): string {
image_url.pathname.startsWith("/user_uploads/thumbnail/")
) {
let thumbnail_name = thumbnail.preferred_format.name;
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
if (message_media_image.getAttribute("data-animated") === "true") {
if (
user_settings.web_animate_image_previews === "always" ||
@@ -211,7 +210,6 @@ export function postprocess_content(html: string): string {
// set those values as `height` and `width` attributes on the
// image source.
if (message_media_image?.hasAttribute("data-original-dimensions")) {
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
const original_dimensions_attribute = message_media_image.getAttribute(
"data-original-dimensions",
);
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index abffb383ec7..5a461fb90c6 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -1913,18 +1913,17 @@ export function initialize({
$("body").on("keydown", ".on_hover_topic_read", ui_util.convert_enter_to_click);
- $("body").on("click", ".button-recent-filters", (e) => {
+ $("body").on("click", ".button-recent-filters", function (this: HTMLElement, e) {
e.stopPropagation();
if (page_params.is_spectator) {
// Filter buttons are disabled for spectator.
return;
}
- assert(e.target instanceof HTMLElement);
- change_focused_element($(e.target), "click");
- assert(e.currentTarget instanceof HTMLElement);
- assert(e.currentTarget.dataset.filter !== undefined);
- set_filter(e.currentTarget.dataset.filter);
+ change_focused_element($(this), "click");
+ const filter = this.getAttribute("data-filter");
+ assert(filter !== null);
+ set_filter(filter);
update_filters_view();
revive_current_focus();
});
diff --git a/web/src/scroll_util.ts b/web/src/scroll_util.ts
index 17df10f274a..7443104c014 100644
--- a/web/src/scroll_util.ts
+++ b/web/src/scroll_util.ts
@@ -25,7 +25,7 @@ export function get_scroll_element($element: JQueryOrZJQuery): JQuery {
const sb = SimpleBar.instances.get(element);
if (sb) {
return $(sb.getScrollElement()!);
- } else if ("simplebar" in element.dataset) {
+ } else if (element.hasAttribute("data-simplebar")) {
// The SimpleBar mutation observer hasn’t processed this element yet.
// Create the SimpleBar early in case we need to add event listeners.
return $(new SimpleBar(element, {tabIndex: -1}).getScrollElement()!);
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 8f137623c87..b0563ba144b 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -1348,7 +1348,7 @@ export function set_event_handlers({
$("#stream_filters").on("click", ".channel-new-topic-button", function (this: HTMLElement, e) {
e.stopPropagation();
e.preventDefault();
- const stream_id = Number.parseInt(this.dataset.streamId!, 10);
+ const stream_id = Number.parseInt(this.getAttribute("data-stream-id")!, 10);
compose_actions.start({
message_type: "stream",
stream_id,
diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.ts
index 94292080158..a73c95c100f 100644
--- a/web/src/tippyjs.ts
+++ b/web/src/tippyjs.ts
@@ -23,9 +23,13 @@ import * as util from "./util.ts";
// For tooltips without data-tippy-content, we use the HTML content of
// a <template> whose id is given by data-tooltip-template-id.
export function get_tooltip_content(reference: Element): string | Element | DocumentFragment {
- if (reference instanceof HTMLElement && reference.dataset.tooltipTemplateId !== undefined) {
+ let template_id;
+ if (
+ reference instanceof HTMLElement &&
+ (template_id = reference.getAttribute("data-tooltip-template-id")) !== null
+ ) {
const template = document.querySelector<HTMLTemplateElement>(
- `template#${CSS.escape(reference.dataset.tooltipTemplateId)}`,
+ `template#${CSS.escape(template_id)}`,
);
if (template !== null) {
const fragment = template.content.cloneNode(true);
diff --git a/web/tests/buddy_list.test.cjs b/web/tests/buddy_list.test.cjs
index df04323b68b..3a776f11b5d 100644
--- a/web/tests/buddy_list.test.cjs
+++ b/web/tests/buddy_list.test.cjs
@@ -31,7 +31,6 @@ initialize_user_settings({user_settings: {}});
function init_simulated_scrolling() {
const elem = {
- dataset: {},
scrollTop: 0,
scrollHeight: 0,
};
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index aa6e4f19799..2128dc8b255 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -401,10 +401,6 @@ test_ui("zoom_in_and_zoom_out", ({mock_template}) => {
children: [elem($stream_li1), elem($stream_li2)],
});
- $("#stream-filters-container")[0] = {
- dataset: {},
- };
-
mock_template("filter_topics.hbs", false, () => "<filter-topics-stub>");
let filter_topics_appended = false;
$stream_li1.children = () => ({