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/no-computed-property-existence-check.

Anders Kaseorg11646015a65c
diff --git a/web/debug-require-webpack-plugin.ts b/web/debug-require-webpack-plugin.ts
index 3da5d873c97..7a6588784c2 100644
--- a/web/debug-require-webpack-plugin.ts
+++ b/web/debug-require-webpack-plugin.ts
@@ -19,7 +19,7 @@ export default class DebugRequirePlugin implements webpack.WebpackPluginInstance
.for("normal")
.tap("DebugRequirePlugin", (resolver) => {
resolver.getHook("beforeRawModule").tap("DebugRequirePlugin", (req) => {
- if (!(nameSymbol in req)) {
+ if (!Object.hasOwn(req, nameSymbol)) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
(req as NamedRequest)[nameSymbol] = req.request;
}
@@ -29,7 +29,7 @@ export default class DebugRequirePlugin implements webpack.WebpackPluginInstance
resolver.getHook("beforeRelative").tap("DebugRequirePlugin", (req) => {
if (req.path !== false) {
const inPath = path.relative(compiler.context, req.path);
- if (!inPath.startsWith("../") && !(nameSymbol in req)) {
+ if (!inPath.startsWith("../") && !Object.hasOwn(req, nameSymbol)) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
(req as NamedRequest)[nameSymbol] = "./" + inPath;
}
diff --git a/web/src/hotkey.ts b/web/src/hotkey.ts
index 1720e598ab9..b2177f94866 100644
--- a/web/src/hotkey.ts
+++ b/web/src/hotkey.ts
@@ -360,7 +360,7 @@ export function get_keydown_hotkey(e: JQuery.KeyDownEvent): Hotkey | Hotkey[] |
let key = e.key;
if (!use_event_key) {
const code = `${e.shiftKey ? "Shift+" : ""}${e.code}`;
- if (CODE_TO_QWERTY_CHAR[code]) {
+ if (CODE_TO_QWERTY_CHAR[code] !== undefined) {
key = CODE_TO_QWERTY_CHAR[code];
} else {
return undefined;
diff --git a/web/src/portico/team.ts b/web/src/portico/team.ts
index 2bf39182146..7077bb6bf10 100644
--- a/web/src/portico/team.ts
+++ b/web/src/portico/team.ts
@@ -116,7 +116,7 @@ function get_profile_url(contributor: Contributor, tab_name?: string): string |
}
for (const repo_name of all_repository_names) {
- if (repo_name in contributor) {
+ if (Object.hasOwn(contributor, repo_name)) {
return `https://github.com/zulip/${repo_name}/commits?author=${email}`;
}
}
diff --git a/web/src/settings_profile_fields.ts b/web/src/settings_profile_fields.ts
index 9b2663496ef..7c46830f8ad 100644
--- a/web/src/settings_profile_fields.ts
+++ b/web/src/settings_profile_fields.ts
@@ -448,18 +448,18 @@ function delete_choice_row_for_edit(
function show_modal_for_deleting_options(
field: CustomProfileField,
- deleted_values: Record<string, string>,
+ deleted_values: Map<string, string>,
update_profile_field: () => void,
): void {
const active_user_ids = people.get_active_user_ids();
let users_count_with_deleted_option_selected = 0;
for (const user_id of active_user_ids) {
const field_value = people.get_custom_profile_data(user_id, field.id);
- if (field_value !== undefined && deleted_values[field_value.value]) {
+ if (field_value !== undefined && deleted_values.has(field_value.value)) {
users_count_with_deleted_option_selected += 1;
}
}
- const deleted_options_count = Object.keys(deleted_values).length;
+ const deleted_options_count = deleted_values.size;
const modal_content_html = render_confirm_delete_profile_field_option({
count: users_count_with_deleted_option_selected,
field_name: field.name,
@@ -737,16 +737,16 @@ function open_custom_profile_field_edit_form_modal(this: HTMLElement): void {
),
),
);
- const deleted_values: Record<string, string> = {};
+ const deleted_values = new Map<string, string>();
const custom_profile_field_choices =
settings_components.custom_profile_field_choices_schema.parse(field_data);
for (const [value, option] of Object.entries(custom_profile_field_choices)) {
if (!new_values.has(value)) {
- deleted_values[value] = option.text;
+ deleted_values.set(value, option.text);
}
}
- if (Object.keys(deleted_values).length > 0) {
+ if (deleted_values.size > 0) {
const edit_custom_profile_field_modal_callback = (): void => {
show_modal_for_deleting_options(field, deleted_values, update_profile_field);
};
diff --git a/web/src/stream_edit.ts b/web/src/stream_edit.ts
index 91c68d04a23..d6e611e730f 100644
--- a/web/src/stream_edit.ts
+++ b/web/src/stream_edit.ts
@@ -328,7 +328,7 @@ export function stream_settings(sub: StreamSubscription): StreamSetting[] {
stream_data.receives_notifications(sub.stream_id, notification_setting.data) &&
!realm_setting;
} else {
- is_checked = Boolean(sub[setting]) && !realm_setting;
+ is_checked = (sub[setting] ?? false) && !realm_setting;
}
return {
name: setting,
diff --git a/web/src/todo_data.ts b/web/src/todo_data.ts
index 1615716dfaa..4c2d4737972 100644
--- a/web/src/todo_data.ts
+++ b/web/src/todo_data.ts
@@ -293,11 +293,6 @@ export class TaskData {
}
const {data} = parsed;
- const type = data.type;
- if (this.handle[type]) {
- this.handle[type].inbound(sender_id, data);
- } else {
- blueslip.warn(`todo widget: unknown inbound type: ${type}`);
- }
+ this.handle[data.type].inbound(sender_id, data);
}
}
diff --git a/web/src/ui_util.ts b/web/src/ui_util.ts
index d78ae1445a1..8d10d6e2100 100644
--- a/web/src/ui_util.ts
+++ b/web/src/ui_util.ts
@@ -144,8 +144,8 @@ export function potentially_collapse_quotes($element: JQuery): boolean {
}
for (const [index, element] of [...$children].entries()) {
- if (collapsible_status[index]) {
- if (index > 0 && collapsible_status[index - 1]) {
+ if (collapsible_status[index] ?? false) {
+ if (index > 0 && (collapsible_status[index - 1] ?? false)) {
// If the previous element was also collapsible, remove its text
// to have a single collapsed block instead of multiple in a row.
$(element).text("");
diff --git a/web/tests/lib/namespace.cjs b/web/tests/lib/namespace.cjs
index 29e7bcbb9a1..f7e777724ac 100644
--- a/web/tests/lib/namespace.cjs
+++ b/web/tests/lib/namespace.cjs
@@ -144,7 +144,7 @@ exports.mock_cjs = (module_path, obj, {callsite = callsites()[1]} = {}) => {
assert.ok(!module_mocks.has(filename), `You already set up a mock for ${filename}`);
assert.ok(
- !(filename in require.cache),
+ !Object.hasOwn(require.cache, filename),
`It is too late to mock ${filename}; call this earlier.`,
);
@@ -204,8 +204,8 @@ exports.unmock_module = (module_path, {callsite = callsites()[1]} = {}) => {
exports.set_global = function (name, val) {
assert.notEqual(val, null, `We try to avoid using null in our codebase.`);
- if (!(name in old_globals)) {
- if (!(name in global)) {
+ if (!Object.hasOwn(old_globals, name)) {
+ if (!Object.hasOwn(global, name)) {
new_globals.add(name);
}
old_globals[name] = global[name];
@@ -376,7 +376,7 @@ exports.with_overrides = function (test_function) {
const rewire_prop = `rewire_${prop}`;
/* istanbul ignore if */
- if (!(rewire_prop in obj)) {
+ if (!Object.hasOwn(obj, rewire_prop)) {
assert.fail(`You must define ${rewire_prop} to use override_rewire on ${prop}.`);
}
obj[rewire_prop](new_value);
diff --git a/web/tests/lib/zblueslip.cjs b/web/tests/lib/zblueslip.cjs
index b2d70e3e216..7c3d9752963 100644
--- a/web/tests/lib/zblueslip.cjs
+++ b/web/tests/lib/zblueslip.cjs
@@ -49,7 +49,7 @@ function make_zblueslip() {
if (i === -1) {
// Only throw this for message types we want to explicitly track.
// For example, we do not want to throw here for debug messages.
- if (opts[name]) {
+ if (opts[name] ?? false) {
throw new Error(`Unexpected '${name}' message: ${message}`);
}
continue;
@@ -83,7 +83,7 @@ function make_zblueslip() {
// Create logging functions
for (const name of names) {
- if (!opts[name]) {
+ if (!(opts[name] ?? false)) {
// should just log the message.
lib[name] = function (message, more_info, cause) {
lib.test_logs[name].push({message, more_info, cause});
diff --git a/web/tests/lib/zjquery_element.cjs b/web/tests/lib/zjquery_element.cjs
index 4aab9a6c741..aa81fa54a1f 100644
--- a/web/tests/lib/zjquery_element.cjs
+++ b/web/tests/lib/zjquery_element.cjs
@@ -12,13 +12,13 @@ const ignore_missing = Symbol("ignore_missing");
const reject_missing_handler = {
has(target, property) {
- if (!(property in target || target[ignore_missing]?.(property))) {
+ if (!(Reflect.has(target, property) || target[ignore_missing]?.(property))) {
throw new TypeError(`unknown property ${property} of mock ${target.constructor.name}`);
}
return Reflect.has(target, property);
},
get(target, property, receiver) {
- if (!(property in target || target[ignore_missing]?.(property))) {
+ if (!(Reflect.has(target, property) || target[ignore_missing]?.(property))) {
throw new TypeError(`unknown property ${property} of mock ${target.constructor.name}`);
}
return Reflect.get(target, property, receiver);
diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjs
index 11f86982cbc..79567340bfe 100644
--- a/web/tests/people.test.cjs
+++ b/web/tests/people.test.cjs
@@ -769,7 +769,7 @@ run_test("set_custom_profile_field_data", () => {
assert.equal(person.profile_data[field.id].rendered_value, "<p>Field value</p>");
people.set_custom_profile_field_data(person.user_id, {id: 3, value: null});
- assert.ok(!(field.id in person.profile_data));
+ assert.ok(!Object.hasOwn(person.profile_data, field.id));
});
run_test("is_current_user_only_owner", ({override}) => {
diff --git a/web/tests/recent_view.test.cjs b/web/tests/recent_view.test.cjs
index e53fccb7c22..33f51d08639 100644
--- a/web/tests/recent_view.test.cjs
+++ b/web/tests/recent_view.test.cjs
@@ -790,7 +790,7 @@ test("test_filter_participated", ({mock_template}) => {
mock_template("recent_view_row.hbs", false, (data) => {
// All the row will be processed.
- if (row_data[i]) {
+ if (row_data[i] !== undefined) {
assert.deepEqual(data, row_data[i]);
i += 1;
}
diff --git a/web/tests/scheduled_messages.test.cjs b/web/tests/scheduled_messages.test.cjs
index 14809291f79..129e7112c0a 100644
--- a/web/tests/scheduled_messages.test.cjs
+++ b/web/tests/scheduled_messages.test.cjs
@@ -106,7 +106,7 @@ function get_expected_send_opts(day, expecteds) {
// 'monday_nine_am'
for (const expect of expecteds) {
const day = expect.split("_", 1)[0]; // "today", "monday"
- if (!modal_opts[`possible_send_later_${day}`]) {
+ if (modal_opts[`possible_send_later_${day}`] === false) {
modal_opts[`possible_send_later_${day}`] = {};
}
modal_opts[`possible_send_later_${day}`][expect] =