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-location-assign.

Anders Kaseorg4a9ac4e64919
diff --git a/web/src/billing/helpers.ts b/web/src/billing/helpers.ts
index 8d234f59897..0bac66264db 100644
--- a/web/src/billing/helpers.ts
+++ b/web/src/billing/helpers.ts
@@ -113,7 +113,7 @@ export function create_ajax_request(
// User session timed out, we need to login again.
const parsed = z.object({login_url: z.string()}).safeParse(xhr.responseJSON);
if (parsed.success) {
- window.location.href = parsed.data.login_url;
+ window.location.assign(parsed.data.login_url);
}
}
},
diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.ts
index 5a3494e5fad..dbec4b619f8 100644
--- a/web/src/click_handlers.ts
+++ b/web/src/click_handlers.ts
@@ -227,7 +227,7 @@ export function initialize(): void {
// This might happen for locally echoed messages, for example.
return;
}
- window.location.href = hash_util.by_conversation_and_time_url(message);
+ window.location.assign(hash_util.by_conversation_and_time_url(message));
return;
}
@@ -308,7 +308,7 @@ export function initialize(): void {
browser_history.go_to_location(hash_util.channel_url_by_user_setting(stream_id));
return;
}
- window.location.href = this.href;
+ window.location.assign(this.href);
});
$("body").on("click", ".not-subscribed-banner .load-newer-messages-button", (e) => {
diff --git a/web/src/compose_setup.ts b/web/src/compose_setup.ts
index 8035ba931e1..88acd389fd4 100644
--- a/web/src/compose_setup.ts
+++ b/web/src/compose_setup.ts
@@ -312,7 +312,7 @@ export function initialize(): void {
onboarding_steps.post_onboarding_step_as_read("visibility_policy_banner");
return;
}
- window.location.href = "/#settings/notifications";
+ window.location.assign("/#settings/notifications");
},
);
diff --git a/web/src/demo_organizations_ui.ts b/web/src/demo_organizations_ui.ts
index 9e6cc1963f9..7960c8163f1 100644
--- a/web/src/demo_organizations_ui.ts
+++ b/web/src/demo_organizations_ui.ts
@@ -86,7 +86,7 @@ export function show_configure_email_banner(): void {
$configure_email_banner_container.on("click", ".demo-organization-add-email", (e) => {
e.preventDefault();
- window.location.href = "/#settings/account-and-privacy";
+ window.location.assign("/#settings/account-and-privacy");
});
}
@@ -132,7 +132,7 @@ export function show_convert_demo_organization_modal(): void {
const opts: RequestOpts = {
success_continuation(raw_data) {
const data = z.object({realm_url: z.string()}).parse(raw_data);
- window.location.href = data.realm_url;
+ window.location.assign(data.realm_url);
},
};
dialog_widget.submit_api_request(channel.patch, "/json/realm", data, opts);
diff --git a/web/src/hotkey.ts b/web/src/hotkey.ts
index 0855ea900cb..1720e598ab9 100644
--- a/web/src/hotkey.ts
+++ b/web/src/hotkey.ts
@@ -763,7 +763,7 @@ function process_enter_key(e: JQuery.KeyDownEvent): boolean {
return false;
}
- window.location.href = hash_util.by_conversation_and_time_url(message);
+ window.location.assign(hash_util.by_conversation_and_time_url(message));
return true;
}
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts
index 0ad42a2a27c..1696a5ba1f7 100644
--- a/web/src/inbox_ui.ts
+++ b/web/src/inbox_ui.ts
@@ -2475,7 +2475,7 @@ export function initialize({hide_other_views}: {hide_other_views: () => void}):
const href = $elt.find("a").attr("href");
col_focus = COLUMNS.FULL_ROW;
if (href !== undefined) {
- window.location.href = href;
+ window.location.assign(href);
} else {
$elt = $elt.closest(".inbox-header");
collapse_or_expand($elt.attr("id")!);
diff --git a/web/src/portico/desktop-login.ts b/web/src/portico/desktop-login.ts
index f931c6a8ac2..0c5b9fe9123 100644
--- a/web/src/portico/desktop-login.ts
+++ b/web/src/portico/desktop-login.ts
@@ -59,5 +59,5 @@ void (async () => {
const token = await pasted;
document.querySelector<HTMLFormElement>("form#form")!.hidden = true;
document.querySelector<HTMLParagraphElement>("p#done")!.hidden = false;
- window.location.href = "/accounts/login/subdomain/" + encodeURIComponent(token);
+ window.location.assign("/accounts/login/subdomain/" + encodeURIComponent(token));
})();
diff --git a/web/src/portico/signup.ts b/web/src/portico/signup.ts
index c8c807e4f15..58542919bd0 100644
--- a/web/src/portico/signup.ts
+++ b/web/src/portico/signup.ts
@@ -433,7 +433,7 @@ $(() => {
$countdown_elt.text((current_countdown - 1).toString());
} else {
const new_org_url = $deactivated_org_auto_redirect.attr("href")!;
- window.location.href = new_org_url;
+ window.location.assign(new_org_url);
clearInterval(interval_id);
}
}, 1000);
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index 32ca5866990..8e2ebed7fd2 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -2451,7 +2451,7 @@ export function initialize({
// Focus topic on channel click since we don't have
// separate column for channel and topic.
focus_clicked_element(topic_row_index, COLUMNS.topic);
- window.location.href = $(e.currentTarget).find("a").attr("href")!;
+ window.location.assign($(e.currentTarget).find("a").attr("href")!);
});
$("body").on("click", "td.recent_topic_name", (e) => {
@@ -2468,7 +2468,7 @@ export function initialize({
const topic_key = topic_id.slice("recent_conversation:".length);
const topic_row_index = $topic_row.index();
focus_clicked_element(topic_row_index, COLUMNS.topic, topic_key);
- window.location.href = $(e.currentTarget).find("a").attr("href")!;
+ window.location.assign($(e.currentTarget).find("a").attr("href")!);
});
$("body").on("click", "#recent-view-content-table .change_visibility_policy", (e) => {
diff --git a/web/src/search.ts b/web/src/search.ts
index fa86014214c..e436e756525 100644
--- a/web/src/search.ts
+++ b/web/src/search.ts
@@ -430,7 +430,7 @@ export let exit_search = (opts: {keep_search_narrow_open: boolean}): void => {
// we just keep the search bar open and don't do anything.
return;
} else {
- window.location.href = filter.generate_redirect_url();
+ window.location.assign(filter.generate_redirect_url());
}
$("#search_query").trigger("blur");
$(".app").trigger("focus");
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js
index 5235ea0f998..023e437197d 100644
--- a/web/src/server_events_dispatch.js
+++ b/web/src/server_events_dispatch.js
@@ -506,7 +506,7 @@ export function dispatch_normal_event(event) {
// with this code, if they didn't have an active
// longpoll waiting at the moment the realm was
// deactivated.
- window.location.href = "/accounts/deactivated/";
+ window.location.assign("/accounts/deactivated/");
break;
}
if (current_user.is_admin) {
diff --git a/web/src/settings_account.ts b/web/src/settings_account.ts
index 176d0581184..0c7b9e33bbf 100644
--- a/web/src/settings_account.ts
+++ b/web/src/settings_account.ts
@@ -866,7 +866,7 @@ export function set_up(): void {
success() {
dialog_widget.hide_dialog_spinner();
dialog_widget.close();
- window.location.href = "/login/";
+ window.location.assign("/login/");
},
error(xhr) {
const error_last_owner = $t_html({
diff --git a/web/src/settings_org.ts b/web/src/settings_org.ts
index 7a1553e3a4b..56462cb06d8 100644
--- a/web/src/settings_org.ts
+++ b/web/src/settings_org.ts
@@ -526,7 +526,7 @@ function update_view_welcome_bot_custom_message_button_status(
assert(message_id !== undefined);
$view_message_button.on("click", (e) => {
e.preventDefault();
- window.location.href = `#narrow/dm/${people.WELCOME_BOT.user_id}/near/${message_id}`;
+ window.location.assign(`#narrow/dm/${people.WELCOME_BOT.user_id}/near/${message_id}`);
});
}
diff --git a/web/src/settings_toggle.ts b/web/src/settings_toggle.ts
index 3c345151ca5..31fbdbef0d8 100644
--- a/web/src/settings_toggle.ts
+++ b/web/src/settings_toggle.ts
@@ -63,6 +63,6 @@ export function toggle_org_setting_collapse(): void {
// If current tab is about to be collapsed, go to default tab.
const $current_tab = $(".org-settings-list .active");
if ($current_tab.hasClass("hide-org-settings")) {
- window.location.href = "/#organization/organization-profile";
+ window.location.assign("/#organization/organization-profile");
}
}
diff --git a/web/src/settings_users.ts b/web/src/settings_users.ts
index b2a30f953b8..5645a27af65 100644
--- a/web/src/settings_users.ts
+++ b/web/src/settings_users.ts
@@ -664,7 +664,7 @@ function handle_deactivation($tbody: JQuery): void {
if (user_id === current_user.user_id) {
dialog_widget.submit_api_request(channel.del, url, data, {
success_continuation() {
- window.location.href = "/login/";
+ window.location.assign("/login/");
},
});
} else {
diff --git a/web/src/sidebar_ui.ts b/web/src/sidebar_ui.ts
index b5d65542107..48e51bb249e 100644
--- a/web/src/sidebar_ui.ts
+++ b/web/src/sidebar_ui.ts
@@ -207,14 +207,14 @@ export function initialize(): void {
$("body").on("click", ".login_button", (e) => {
e.preventDefault();
e.stopPropagation();
- window.location.href = spectators.build_login_link();
+ window.location.assign(spectators.build_login_link());
});
$("body").on("keydown", ".login_button", (e) => {
if (e.key === "Enter") {
e.preventDefault();
e.stopPropagation();
- window.location.href = spectators.build_login_link();
+ window.location.assign(spectators.build_login_link());
}
});
diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.ts
index fc524e3f21e..93f28c72f36 100644
--- a/web/src/stream_settings_ui.ts
+++ b/web/src/stream_settings_ui.ts
@@ -1381,6 +1381,6 @@ export function initialize(): void {
$("#channels_overlay_container").on("click", "#preview-stream-button", () => {
const stream_id = Number.parseInt($(".stream-title-buttons").attr("data-stream-id")!, 10);
- window.location.href = hash_util.channel_url_by_user_setting(stream_id);
+ window.location.assign(hash_util.channel_url_by_user_setting(stream_id));
});
}
diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjs
index 263fc1c34fa..68a748208b9 100644
--- a/web/tests/dispatch.test.cjs
+++ b/web/tests/dispatch.test.cjs
@@ -841,7 +841,11 @@ run_test("realm settings", ({override}) => {
assert_same(realm.realm_night_logo_source, "U");
event = event_fixtures.realm__deactivated;
- set_global("location", {});
+ set_global("location", {
+ assign(href) {
+ this.href = href;
+ },
+ });
dispatch(event);
assert_same(window.location.href, "/accounts/deactivated/");
});