From 5c8117a426b7ce4627be87e2089572d40dea054a Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 7 Oct 2020 03:54:16 -0700 Subject: [PATCH] eslint: Fix no-implicit-coercion. https://eslint.org/docs/rules/no-implicit-coercion Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 + frontend_tests/node_tests/drafts.js | 2 +- static/js/compose_state.js | 2 +- static/js/lightbox.js | 6 +++--- static/js/notifications.js | 2 +- static/js/overlays.js | 2 +- static/js/recent_topics.js | 4 ++-- static/js/settings_org.js | 4 ++-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 20e0f14c90..cc7e6101d3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -54,6 +54,7 @@ "no-else-return": "error", "no-eq-null": "error", "no-eval": "error", + "no-implicit-coercion": "error", "no-implied-eval": "error", "no-inner-declarations": "off", "no-iterator": "error", diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index 8a2e65b69e..fd86d4f06b 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -145,7 +145,7 @@ run_test("snapshot_message", () => { return draft.type; }; global.compose_state.composing = function () { - return !!draft.type; + return Boolean(draft.type); }; global.compose_state.message_content = function () { return draft.content; diff --git a/static/js/compose_state.js b/static/js/compose_state.js index 50867a1c4e..3483efae47 100644 --- a/static/js/compose_state.js +++ b/static/js/compose_state.js @@ -13,7 +13,7 @@ exports.get_message_type = function () { exports.composing = function () { // This is very similar to get_message_type(), but it returns // a boolean. - return !!message_type; + return Boolean(message_type); }; exports.focus_in_empty_compose = function () { diff --git a/static/js/lightbox.js b/static/js/lightbox.js index 9a70862b10..d00954fbf2 100644 --- a/static/js/lightbox.js +++ b/static/js/lightbox.js @@ -201,9 +201,9 @@ exports.parse_image_data = function (image) { // if wrapped in the .youtube-video class, it will be length = 1, and therefore // cast to true. - const is_youtube_video = !!$image.closest(".youtube-video").length; - const is_vimeo_video = !!$image.closest(".vimeo-video").length; - const is_embed_video = !!$image.closest(".embed-video").length; + const is_youtube_video = Boolean($image.closest(".youtube-video").length); + const is_vimeo_video = Boolean($image.closest(".vimeo-video").length); + const is_embed_video = Boolean($image.closest(".embed-video").length); // check if image is descendent of #preview_content const is_compose_preview_image = $image.closest("#preview_content").length === 1; diff --git a/static/js/notifications.js b/static/js/notifications.js index 55e177c2bb..ab3b7a0d86 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -163,7 +163,7 @@ exports.redraw_title = function () { // Make sure we're working with a number, as a defensive programming // measure. And we don't have images above 99, so display those as // 'infinite'. - n = +new_message_count; + n = Number(new_message_count); if (n > 99) { n = "infinite"; } diff --git a/static/js/overlays.js b/static/js/overlays.js index 933fce0717..b4d951f7a0 100644 --- a/static/js/overlays.js +++ b/static/js/overlays.js @@ -11,7 +11,7 @@ function reset_state() { } exports.is_active = function () { - return !!open_overlay_name; + return Boolean(open_overlay_name); }; exports.is_modal_open = function () { diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 591c933be6..4512aa3a6b 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -175,7 +175,7 @@ function format_topic(topic_data) { // We only supply the data to the topic rows and let jquery // display / hide them according to filters instead of // doing complete re-render. - const topic_muted = !!muting.is_topic_muted(stream_id, topic); + const topic_muted = Boolean(muting.is_topic_muted(stream_id, topic)); const stream_muted = stream_data.is_muted(stream_id); const muted = topic_muted || stream_muted; const unread_count = unread.unread_topic_counter.get(stream_id, topic); @@ -266,7 +266,7 @@ exports.filters_should_hide_topic = function (topic_data) { } if (!filters.has("include_muted")) { - const topic_muted = !!muting.is_topic_muted(msg.stream_id, msg.topic); + const topic_muted = Boolean(muting.is_topic_muted(msg.stream_id, msg.topic)); const stream_muted = stream_data.is_muted(msg.stream_id); if (topic_muted || stream_muted) { return true; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index c15a5f115b..bb515a3395 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -733,7 +733,7 @@ exports.build_page = function () { $("#id_realm_message_content_edit_limit_minutes"), ); // Disable editing if the parsed time limit is 0 seconds - data.allow_message_editing = !!data.message_content_edit_limit_seconds; + data.allow_message_editing = Boolean(data.message_content_edit_limit_seconds); } else { data.allow_message_editing = true; data.message_content_edit_limit_seconds = settings_config.msg_edit_limit_dropdown_values.get( @@ -748,7 +748,7 @@ exports.build_page = function () { $("#id_realm_message_content_delete_limit_minutes"), ); // Disable deleting if the parsed time limit is 0 seconds - data.allow_message_deleting = !!data.message_content_delete_limit_seconds; + data.allow_message_deleting = Boolean(data.message_content_delete_limit_seconds); } else { data.allow_message_deleting = true; data.message_content_delete_limit_seconds = settings_config.msg_delete_limit_dropdown_values.get(