From c16837a6643efdda5f8ec47a1fac2ffce4208d5c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 21 Dec 2023 17:03:12 -0800 Subject: [PATCH] eslint: Fix @typescript-eslint/prefer-string-starts-ends-with. Signed-off-by: Anders Kaseorg --- web/src/browser_history.ts | 4 ++-- web/src/channel.ts | 2 +- web/src/hash_util.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/src/browser_history.ts b/web/src/browser_history.ts index 16d90a9e56..23245d60de 100644 --- a/web/src/browser_history.ts +++ b/web/src/browser_history.ts @@ -107,7 +107,7 @@ export function return_to_web_public_hash(): void { export function get_full_url(hash: string): string { const location = window.location; - if (hash.charAt(0) !== "#" && hash !== "") { + if (!hash.startsWith("#") && hash !== "") { hash = "#" + hash; } @@ -115,7 +115,7 @@ export function get_full_url(hash: string): string { let pathname = location.pathname; if (pathname === undefined) { pathname = "/"; - } else if (pathname === "" || pathname.charAt(0) !== "/") { + } else if (pathname === "" || !pathname.startsWith("/")) { pathname = "/" + pathname; } diff --git a/web/src/channel.ts b/web/src/channel.ts index b961bce490..40e4a70c2f 100644 --- a/web/src/channel.ts +++ b/web/src/channel.ts @@ -210,7 +210,7 @@ export function patch( } export function xhr_error_message(message: string, xhr: JQuery.jqXHR): string { - if (xhr.status.toString().charAt(0) === "4" && xhr.responseJSON?.msg) { + if (xhr.status >= 400 && xhr.status < 500 && xhr.responseJSON?.msg) { // Only display the error response for 4XX, where we've crafted // a nice response. const server_response_html = _.escape(xhr.responseJSON.msg); diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts index 1d1bd9c6cb..da753a1f87 100644 --- a/web/src/hash_util.ts +++ b/web/src/hash_util.ts @@ -11,7 +11,7 @@ type Operator = {operator: string; operand: string; negated?: boolean}; export function build_reload_url(): string { let hash = window.location.hash; - if (hash.length !== 0 && hash[0] === "#") { + if (hash.length !== 0 && hash.startsWith("#")) { hash = hash.slice(1); } return "+oldhash=" + encodeURIComponent(hash); @@ -177,7 +177,7 @@ export function parse_narrow(hash: string): Operator[] | undefined { } let negated = false; - if (operator[0] === "-") { + if (operator.startsWith("-")) { negated = true; operator = operator.slice(1); }