eslint: Fix @typescript-eslint/prefer-nullish-coalescing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-12-21 16:46:30 -08:00
committed by Tim Abbott
parent 9ec4c6d852
commit 3d55e7ef10
9 changed files with 14 additions and 13 deletions

View File

@@ -89,7 +89,7 @@ export function warn(msg: string, more_info?: unknown): void {
export function error(msg: string, more_info?: object | undefined, original_error?: unknown): void {
// Log the Sentry error before the console warning, so we don't
// end up with a doubled message in the Sentry logs.
Sentry.setContext("more_info", more_info === undefined ? null : more_info);
Sentry.setContext("more_info", more_info ?? null);
// Note that original_error could be of any type, because you can "raise"
// any type -- something we do see in practice with the error

View File

@@ -82,6 +82,7 @@ export function update(new_hash: string): void {
export function exit_overlay(): void {
if (hash_parser.is_overlay_hash(window.location.hash) && !state.changing_hash) {
ui_util.blur_active_element();
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const new_hash = state.hash_before_overlay || `#${user_settings.web_home_view}`;
update(new_hash);
}

View File

@@ -35,7 +35,7 @@ export function compute_show_audio_chat_button(): boolean {
const available_providers = page_params.realm_available_video_chat_providers;
if (
(available_providers.jitsi_meet &&
get_jitsi_server_url() &&
get_jitsi_server_url() !== null &&
page_params.realm_video_chat_provider === available_providers.jitsi_meet.id) ||
(available_providers.zoom &&
page_params.realm_video_chat_provider === available_providers.zoom.id)

View File

@@ -104,7 +104,7 @@ export function stream_id(): number | undefined {
export function stream_name(): string {
const stream_id = selected_recipient_id;
if (typeof stream_id === "number") {
return sub_store.maybe_get_stream_name(stream_id) || "";
return sub_store.maybe_get_stream_name(stream_id) ?? "";
}
return "";
}

View File

@@ -194,7 +194,7 @@ export function get_pm_full_names(message: Message): string {
}
export function set_message_booleans(message: Message): void {
const flags = message.flags || [];
const flags = message.flags ?? [];
function convert_flag(flag_name: string): boolean {
return flags.includes(flag_name);

View File

@@ -81,7 +81,7 @@ export function open_overlay(opts: OverlayOptions): void {
return;
}
if (active_overlay || open_overlay_name) {
if (active_overlay !== undefined || open_overlay_name) {
blueslip.error("Programming error - trying to open overlay before closing other", {
name: opts.name,
open_overlay_name,

View File

@@ -190,7 +190,7 @@ export function get_bot_owner_user(user: User & {is_bot: true}): User | undefine
export function can_admin_user(user: User): boolean {
return (
(user.is_bot && user.bot_owner_id && user.bot_owner_id === page_params.user_id) ||
(user.is_bot && user.bot_owner_id !== null && user.bot_owner_id === page_params.user_id) ||
is_my_user_id(user.user_id)
);
}

View File

@@ -75,8 +75,8 @@ export function status_from_raw(raw: RawPresence): PresenceStatus {
/* Mark users as offline after this many seconds since their last checkin, */
const offline_threshold_secs = page_params.server_presence_offline_threshold_seconds;
function age(timestamp?: number): number {
return raw.server_timestamp - (timestamp || 0);
function age(timestamp = 0): number {
return raw.server_timestamp - timestamp;
}
const active_timestamp = raw.active_timestamp;
@@ -84,7 +84,7 @@ export function status_from_raw(raw: RawPresence): PresenceStatus {
let last_active: number | undefined;
if (active_timestamp !== undefined || idle_timestamp !== undefined) {
last_active = Math.max(active_timestamp || 0, idle_timestamp || 0);
last_active = Math.max(active_timestamp ?? 0, idle_timestamp ?? 0);
}
/*
@@ -141,18 +141,18 @@ export function update_info_from_event(
server_timestamp: 1585745140
}
*/
const raw = raw_info.get(user_id) || {
const raw = raw_info.get(user_id) ?? {
server_timestamp: 0,
};
raw.server_timestamp = server_timestamp;
for (const rec of Object.values(info)) {
if (rec.status === "active" && rec.timestamp > (raw.active_timestamp || 0)) {
if (rec.status === "active" && rec.timestamp > (raw.active_timestamp ?? 0)) {
raw.active_timestamp = rec.timestamp;
}
if (rec.status === "idle" && rec.timestamp > (raw.idle_timestamp || 0)) {
if (rec.status === "idle" && rec.timestamp > (raw.idle_timestamp ?? 0)) {
raw.idle_timestamp = rec.timestamp;
}
}

View File

@@ -130,7 +130,7 @@ export function populate_emoji(): void {
name: item.name,
display_name: item.name.replaceAll("_", " "),
source_url: item.source_url,
author: item.author || "",
author: item.author ?? "",
can_delete_emoji: can_delete_emoji(item),
},
});