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 @typescript-eslint/no-unnecessary-type-conversion.

Anders Kaseorg5d13749d26cf
diff --git a/web/src/attachments_ui.ts b/web/src/attachments_ui.ts
index d0a906af053..50b47726269 100644
--- a/web/src/attachments_ui.ts
+++ b/web/src/attachments_ui.ts
@@ -266,8 +266,7 @@ export function suggest_delete_detached_attachments(attachments_list: ServerAtta
function do_delete_attachments(): void {
dialog_widget.show_dialog_spinner();
- for (const [key, attachment] of attachments_map.entries()) {
- const id = Number(key);
+ for (const [id, attachment] of attachments_map.entries()) {
void channel.del({
url: "/json/attachments/" + attachment.id,
success() {
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 888a749b70f..f434b4e3e81 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -368,13 +368,13 @@ export class Filter {
break;
case "sender":
case "dm":
- operand = operand.toString().toLowerCase();
+ operand = operand.toLowerCase();
if (operand === "me") {
operand = people.my_current_email();
}
break;
case "dm-including":
- operand = operand.toString().toLowerCase();
+ operand = operand.toLowerCase();
break;
case "search":
// The mac app automatically substitutes regular quotes with curly
@@ -382,10 +382,10 @@ export class Filter {
// phrase search behavior, however. So, we replace all instances of
// curly quotes with regular quotes when doing a search. This is
// unlikely to cause any problems and is probably what the user wants.
- operand = operand.toString().replaceAll(/[\u201C\u201D]/g, '"');
+ operand = operand.replaceAll(/[\u201C\u201D]/g, '"');
break;
default:
- operand = operand.toString().toLowerCase();
+ operand = operand.toLowerCase();
}
// We may want to consider allowing mixed-case operators at some point
@@ -530,11 +530,7 @@ export class Filter {
}
}
- if (
- for_pills &&
- operator === "sender" &&
- operand.toString().toLowerCase() === "me"
- ) {
+ if (for_pills && operator === "sender" && operand.toLowerCase() === "me") {
operand = people.my_current_email();
}
@@ -637,9 +633,7 @@ export class Filter {
return term.operand;
}
const operator = Filter.canonicalize_operator(term.operator);
- return (
- sign + operator + ":" + Filter.encodeOperand(term.operand.toString(), term.operator)
- );
+ return sign + operator + ":" + Filter.encodeOperand(term.operand, term.operator);
});
return term_strings.join(" ");
}
diff --git a/web/src/flatpickr.ts b/web/src/flatpickr.ts
index bed7e3904ad..9d72b062744 100644
--- a/web/src/flatpickr.ts
+++ b/web/src/flatpickr.ts
@@ -8,7 +8,7 @@ import {$t} from "./i18n.ts";
import {user_settings} from "./user_settings.ts";
import * as util from "./util.ts";
-export let flatpickr_instance: flatpickr.Instance;
+export let flatpickr_instance: flatpickr.Instance | undefined;
export function is_open(): boolean {
return Boolean(flatpickr_instance?.isOpen);
@@ -109,8 +109,8 @@ export function show_flatpickr(
}
if (e.key === "Escape") {
- flatpickr_instance.close();
- flatpickr_instance.destroy();
+ flatpickr_instance?.close();
+ flatpickr_instance?.destroy();
}
if (e.key === "Tab") {
@@ -133,8 +133,8 @@ export function show_flatpickr(
const time = $flatpickr_input.val();
assert(typeof time === "string");
callback(time);
- flatpickr_instance.close();
- flatpickr_instance.destroy();
+ flatpickr_instance?.close();
+ flatpickr_instance?.destroy();
});
flatpickr_instance.open();
assert(flatpickr_instance.selectedDateElem !== undefined);
diff --git a/web/src/fold_dict.ts b/web/src/fold_dict.ts
index 8d386f43bd6..d5e6e8f3a09 100644
--- a/web/src/fold_dict.ts
+++ b/web/src/fold_dict.ts
@@ -70,6 +70,6 @@ export class FoldDict<V> {
throw new TypeError("Tried to call a FoldDict method with an undefined key.");
}
- return key.toString().toLowerCase();
+ return key.toLowerCase();
}
}
diff --git a/web/src/mouse_drag.ts b/web/src/mouse_drag.ts
index 58473b1a4eb..dd9dbf417cc 100644
--- a/web/src/mouse_drag.ts
+++ b/web/src/mouse_drag.ts
@@ -18,7 +18,7 @@ export function is_drag(e: JQuery.ClickEvent): boolean {
const drag_distance = Math.abs(e.pageX - start_x) + Math.abs(e.pageY - start_y);
const sel = window.getSelection();
- const has_selection = Boolean(sel?.type === "Range" && sel.toString().length > 0);
+ const has_selection = sel?.type === "Range" && sel.toString().length > 0;
// A very low drag_distance cutoff (2) can prevent a click after
// moving the mouse rapidly from registering.
diff --git a/web/src/portico/header.ts b/web/src/portico/header.ts
index a7f5a3f7c4a..80440479d53 100644
--- a/web/src/portico/header.ts
+++ b/web/src/portico/header.ts
@@ -13,7 +13,7 @@ $(() => {
if (el) {
$("#top-menu-submenu-backdrop").css(
"height",
- Number(el.offsetHeight) + EXTRA_SUBMENU_BOTTOM_PADDING,
+ el.offsetHeight + EXTRA_SUBMENU_BOTTOM_PADDING,
);
} else {
$("#top-menu-submenu-backdrop").css("height", 0);
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index b99f0805cbc..46622498f6c 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -904,10 +904,11 @@ export function filters_should_hide_row(topic_data: ConversationData): boolean {
if (dropdown_filters.has(views_util.FILTERS.UNMUTED_TOPICS) && msg.type === "stream") {
// We want to show the unmuted or followed topics within muted
// streams in Recent Conversations.
- const topic_unmuted_or_followed = Boolean(
- user_topics.is_topic_unmuted_or_followed(msg.stream_id, msg.topic),
+ const topic_unmuted_or_followed = user_topics.is_topic_unmuted_or_followed(
+ msg.stream_id,
+ msg.topic,
);
- const topic_muted = Boolean(user_topics.is_topic_muted(msg.stream_id, msg.topic));
+ const topic_muted = user_topics.is_topic_muted(msg.stream_id, msg.topic);
const stream_muted = stream_data.is_muted(msg.stream_id);
if (topic_muted || (stream_muted && !topic_unmuted_or_followed)) {
return true;
diff --git a/web/src/stream_data.ts b/web/src/stream_data.ts
index 218ce3dbc84..13e7917b7e0 100644
--- a/web/src/stream_data.ts
+++ b/web/src/stream_data.ts
@@ -495,7 +495,7 @@ export function all_subscribed_streams_are_in_home_view(): boolean {
}
export function canonicalized_name(stream_name: string): string {
- return stream_name.toString().toLowerCase();
+ return stream_name.toLowerCase();
}
export function get_color(stream_id: number | undefined): string {
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 993ca8b1195..abe7bdd8e82 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -226,7 +226,7 @@ test("basics", () => {
terms = [
{operator: "channel", operand: foo_stream_id.toString()},
{operator: "topic", operand: "bar"},
- {operator: "near", operand: 17},
+ {operator: "near", operand: "17"},
];
filter = new Filter(terms);
@@ -417,7 +417,7 @@ test("basics", () => {
terms = [
{operator: "dm", operand: "[email protected]"},
- {operator: "near", operand: 17},
+ {operator: "near", operand: "17"},
];
filter = new Filter(terms);
assert.ok(filter.is_non_group_direct_message());
@@ -555,7 +555,7 @@ test("basics", () => {
terms = [
{operator: "channel", operand: foo_stream_id.toString()},
{operator: "topic", operand: "bar"},
- {operator: "with", operand: 17},
+ {operator: "with", operand: "17"},
];
filter = new Filter(terms);
@@ -999,7 +999,7 @@ test("canonicalization", () => {
assert.equal(term.operator, "search");
assert.equal(term.operand, "fOO");
- term = Filter.canonicalize_term({operator: "search", operand: 123});
+ term = Filter.canonicalize_term({operator: "search", operand: "123"});
assert.equal(term.operator, "search");
assert.equal(term.operand, "123");
@@ -1234,15 +1234,15 @@ test("predicate_basics", ({override}) => {
assert.ok(!predicate({stream_id: muted_stream.stream_id, topic: "bar"}));
});
- predicate = get_predicate([["near", 5]]);
+ predicate = get_predicate([["near", "5"]]);
assert.ok(predicate({}));
- predicate = get_predicate([["id", 5]]);
+ predicate = get_predicate([["id", "5"]]);
assert.ok(predicate({id: 5}));
assert.ok(!predicate({id: 6}));
predicate = get_predicate([
- ["id", 5],
+ ["id", "5"],
["topic", "lunch"],
]);
assert.ok(predicate({type: stream_message, id: 5, topic: "lunch"}));
@@ -1488,7 +1488,7 @@ test("predicate_edge_cases", () => {
predicate = get_predicate([["in", "bogus"]]);
assert.ok(!predicate({}));
- predicate = get_predicate([["bogus", 33]]);
+ predicate = get_predicate([["bogus", "33"]]);
assert.ok(predicate({}));
predicate = get_predicate([["is", "bogus"]]);
@@ -1670,11 +1670,11 @@ test("unparse", () => {
string = "-channels:public";
assert.deepEqual(Filter.unparse(terms), string);
- terms = [{operator: "id", operand: 50}];
+ terms = [{operator: "id", operand: "50"}];
string = "id:50";
assert.deepEqual(Filter.unparse(terms), string);
- terms = [{operator: "near", operand: 150}];
+ terms = [{operator: "near", operand: "150"}];
string = "near:150";
assert.deepEqual(Filter.unparse(terms), string);
diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjs
index 79cce80bcb7..5196e4fb4ad 100644
--- a/web/tests/message_view.test.cjs
+++ b/web/tests/message_view.test.cjs
@@ -391,7 +391,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {
override(realm, "realm_direct_message_permission_group", nobody.id);
// prioritize information about invalid user(s) in narrow/search
- current_filter = set_filter([["dm", ["Yo"]]]);
+ current_filter = set_filter([["dm", "Yo"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
@@ -399,7 +399,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {
);
people.add_active_user(alice);
- current_filter = set_filter([["dm", ["[email protected]", "Yo"]]]);
+ current_filter = set_filter([["dm", "[email protected],Yo"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
@@ -500,7 +500,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {
override(realm, "realm_direct_message_permission_group", nobody.id);
// prioritize information about invalid user in narrow/search
- current_filter = set_filter([["dm-including", ["Yo"]]]);
+ current_filter = set_filter([["dm-including", "Yo"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
diff --git a/web/tests/narrow_local.test.cjs b/web/tests/narrow_local.test.cjs
index 587f3f92cc8..ed89f8ef5ed 100644
--- a/web/tests/narrow_local.test.cjs
+++ b/web/tests/narrow_local.test.cjs
@@ -88,7 +88,7 @@ function test_fixture(label, fixture) {
test_fixture("near after unreads", {
// Current near: behavior is to ignore the unreads and take you
// to the target message, with reading disabled.
- filter_terms: [{operator: "near", operand: 42}],
+ filter_terms: [{operator: "near", operand: "42"}],
target_id: 42,
unread_info: {
flavor: "found",
@@ -111,7 +111,7 @@ test_fixture("near after unreads", {
test_fixture("near not in message list", {
// Current behavior is to ignore the unreads and take you
// to the closest messages, with reading disabled.
- filter_terms: [{operator: "near", operand: 42}],
+ filter_terms: [{operator: "near", operand: "42"}],
target_id: 42,
unread_info: {
flavor: "found",
@@ -132,7 +132,7 @@ test_fixture("near not in message list", {
});
test_fixture("near before unreads", {
- filter_terms: [{operator: "near", operand: 42}],
+ filter_terms: [{operator: "near", operand: "42"}],
target_id: 42,
unread_info: {
flavor: "found",
@@ -153,7 +153,7 @@ test_fixture("near before unreads", {
});
test_fixture("near with no unreads", {
- filter_terms: [{operator: "near", operand: 42}],
+ filter_terms: [{operator: "near", operand: "42"}],
target_id: 42,
unread_info: {
flavor: "not_found",
@@ -328,7 +328,7 @@ test_fixture("search", {
test_fixture("search near", {
filter_terms: [
{operator: "search", operand: "whatever"},
- {operator: "near", operand: 22},
+ {operator: "near", operand: "22"},
],
target_id: 22,
unread_info: {
diff --git a/web/tests/narrow_unread.test.cjs b/web/tests/narrow_unread.test.cjs
index 662a50c9877..7e8c2edcc69 100644
--- a/web/tests/narrow_unread.test.cjs
+++ b/web/tests/narrow_unread.test.cjs
@@ -238,7 +238,7 @@ run_test("get_unread_ids", () => {
terms = [
{operator: "channel", operand: sub.stream_id.toString()},
{operator: "topic", operand: "another topic"},
- {operator: "with", operand: stream_msg.id},
+ {operator: "with", operand: stream_msg.id.toString()},
];
set_filter(terms);
unread_ids = candidate_ids();
@@ -247,7 +247,7 @@ run_test("get_unread_ids", () => {
terms = [
{operator: "channel", operand: sub.stream_id.toString()},
{operator: "topic", operand: "another topic"},
- {operator: "with", operand: private_msg.id},
+ {operator: "with", operand: private_msg.id.toString()},
];
set_filter(terms);
unread_ids = candidate_ids();