From 80a2d5bc59f65eb7c2e4f16db9599345f0f60a61 Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Wed, 6 Jun 2018 22:20:09 +0530 Subject: [PATCH] eslint: Enable `conditionalAssign` config of no-trailing-spaces rule. --- .eslintrc.json | 7 +------ frontend_tests/casper_lib/common.js | 2 +- frontend_tests/zjsunit/zjquery.js | 16 ++++++++-------- static/js/activity.js | 2 +- static/js/attachments_ui.js | 4 ++-- static/js/click_handlers.js | 4 ++-- static/js/colorspace.js | 4 ++-- static/js/common.js | 2 +- static/js/compose_actions.js | 22 +++++++++++----------- static/js/compose_ui.js | 2 +- static/js/composebox_typeahead.js | 4 ++-- static/js/drafts.js | 10 +++++----- static/js/emoji_picker.js | 10 +++++----- static/js/filter.js | 8 ++++---- static/js/floating_recipient_bar.js | 2 +- static/js/hash_util.js | 4 ++-- static/js/hashchange.js | 4 ++-- static/js/hotkey.js | 2 +- static/js/hotspots.js | 8 ++++---- static/js/invite.js | 4 ++-- static/js/lightbox_canvas.js | 16 ++++++++-------- static/js/message_edit.js | 8 ++++---- static/js/message_fetch.js | 2 +- static/js/message_list.js | 8 ++++---- static/js/message_list_data.js | 10 +++++----- static/js/message_list_view.js | 12 ++++++------ static/js/message_viewport.js | 14 +++++++------- static/js/narrow.js | 10 +++++----- static/js/narrow_state.js | 2 +- static/js/navigate.js | 2 +- static/js/notifications.js | 12 ++++++------ static/js/pm_list.js | 4 ++-- static/js/popovers.js | 10 +++++----- static/js/presence.js | 2 +- static/js/reactions.js | 10 +++++----- static/js/scroll_bar.js | 14 +++++++------- static/js/search_suggestion.js | 10 +++++----- static/js/sent_messages.js | 4 ++-- static/js/server_events.js | 8 ++++---- static/js/settings_ui.js | 4 ++-- static/js/settings_user_groups.js | 2 +- static/js/stats/stats.js | 2 +- static/js/stream_edit.js | 4 ++-- static/js/stream_popover.js | 2 +- static/js/subs.js | 4 ++-- static/js/tictactoe_widget.js | 4 ++-- static/js/timerender.js | 4 ++-- static/js/top_left_corner.js | 4 ++-- static/js/topic_list.js | 6 +++--- static/js/ui_init.js | 6 +++--- static/js/unread_ui.js | 6 +++--- static/js/util.js | 10 +++++----- 52 files changed, 166 insertions(+), 171 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9f4342696e..6c422fcf29 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -280,12 +280,7 @@ "no-eq-null": 2, "no-eval": 2, "no-ex-assign": 2, - "no-extra-parens": ["error", "all", - { - "conditionalAssign": false, - "nestedBinaryExpressions": false - } - ], + "no-extra-parens": ["error", "all"], "no-extra-semi": 2, "no-fallthrough": 2, "no-floating-decimal": 2, diff --git a/frontend_tests/casper_lib/common.js b/frontend_tests/casper_lib/common.js index 12ee09e92c..b8569200b2 100644 --- a/frontend_tests/casper_lib/common.js +++ b/frontend_tests/casper_lib/common.js @@ -319,7 +319,7 @@ exports.then_send_many = function (msgs) { exports.wait_for_receive = function (step) { // Wait until the last send or get_events result was more than 1000 ms ago. casper.waitFor(function () { - return (timestamp() - last_send_or_update) > 1000; + return timestamp() - last_send_or_update > 1000; }, step); }; diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index fba996dd11..84911729bd 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -401,15 +401,15 @@ exports.make_zjquery = function (opts) { } var valid_selector = - ('<#.'.indexOf(selector[0]) >= 0) || - (selector === 'window-stub') || - (selector === 'document-stub') || - (selector === 'body') || - (selector === 'html') || + '<#.'.indexOf(selector[0]) >= 0 || + selector === 'window-stub' || + selector === 'document-stub' || + selector === 'body' || + selector === 'html' || selector.location || - (selector.indexOf('#') >= 0) || - (selector.indexOf('.') >= 0) || - (selector.indexOf('[') >= 0 && selector.indexOf(']') >= selector.indexOf('[')); + selector.indexOf('#') >= 0 || + selector.indexOf('.') >= 0 || + selector.indexOf('[') >= 0 && selector.indexOf(']') >= selector.indexOf('['); assert(valid_selector, 'Invalid selector: ' + selector + diff --git a/static/js/activity.js b/static/js/activity.js index 0d0b346914..4b3c0c93f4 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -122,7 +122,7 @@ exports.process_loaded_messages = function (messages) { if (huddle_string) { var old_timestamp = huddle_timestamps.get(huddle_string); - if (!old_timestamp || (old_timestamp < message.timestamp)) { + if (!old_timestamp || old_timestamp < message.timestamp) { huddle_timestamps.set(huddle_string, message.timestamp); need_resize = true; } diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js index de2d548e4e..87da2b3e55 100644 --- a/static/js/attachments_ui.js +++ b/static/js/attachments_ui.js @@ -29,8 +29,8 @@ function bytes_to_size(bytes, kb_with_1024_bytes) { } var i = parseInt(Math.floor(Math.log(bytes) / Math.log(kb_size)), 10); var size = Math.round(bytes / Math.pow(kb_size, i)); - if ((i > 0) && (size < 10)) { - size = Math.round((bytes / Math.pow(kb_size, i)) * 10) / 10; + if (i > 0 && size < 10) { + size = Math.round(bytes / Math.pow(kb_size, i) * 10) / 10; } return size + ' ' + sizes[i]; } diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index ffbe28caf7..48b6bffbcc 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -58,7 +58,7 @@ exports.initialize = function () { return target.is("a") || target.is("img.message_inline_image") || target.is("img.twitter-avatar") || target.is("div.message_length_controller") || target.is("textarea") || target.is("input") || target.is("i.edit_content_button") || - (target.is(".highlight") && target.parent().is("a")); + target.is(".highlight") && target.parent().is("a"); } function initialize_long_tap() { @@ -121,7 +121,7 @@ exports.initialize = function () { // work nearly perfectly. Once we no longer need to support // older browsers, we may be able to use the window.selection // API instead. - if ((drag.val < 5 && drag.time < 150) || drag.val < 2) { + if (drag.val < 5 && drag.time < 150 || drag.val < 2) { var row = $(this).closest(".message_row"); var id = rows.id(row); diff --git a/static/js/colorspace.js b/static/js/colorspace.js index fa212ad591..fc538388ba 100644 --- a/static/js/colorspace.js +++ b/static/js/colorspace.js @@ -26,8 +26,8 @@ exports.rgb_luminance = function (channel) { // http://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation exports.luminance_to_lightness = function (luminance) { var v; - if (luminance <= (216 / 24389)) { - v = (841 / 108) * luminance + (4 / 29); + if (luminance <= 216 / 24389) { + v = 841 / 108 * luminance + 4 / 29; } else { v = Math.pow(luminance, 1 / 3); } diff --git a/static/js/common.js b/static/js/common.js index c379d6b7b9..21fdd81414 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -48,7 +48,7 @@ exports.password_quality = function (password, bar, password_field) { // The bar bottoms out at 10% so there's always something // for the user to see. - bar.width(((90 * bar_progress) + 10) + '%') + bar.width(90 * bar_progress + 10 + '%') .removeClass('bar-success bar-danger') .addClass(acceptable ? 'bar-success' : 'bar-danger'); } diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index b500938bef..a7ecb0d519 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -33,8 +33,8 @@ function get_focus_area(msg_type, opts) { // Set focus to "Topic" when narrowed to a stream+topic and "New topic" button clicked. if (msg_type === 'stream' && opts.stream && !opts.subject) { return 'subject'; - } else if ((msg_type === 'stream' && opts.stream) - || (msg_type === 'private' && opts.private_message_recipient)) { + } else if (msg_type === 'stream' && opts.stream + || msg_type === 'private' && opts.private_message_recipient) { if (opts.trigger === "new topic button") { return 'subject'; } @@ -181,12 +181,12 @@ function fill_in_opts_from_current_narrowed_view(msg_type, opts) { } function same_recipient_as_before(msg_type, opts) { - return (compose_state.get_message_type() === msg_type) && - ((msg_type === "stream" && + return compose_state.get_message_type() === msg_type && + (msg_type === "stream" && opts.stream === compose_state.stream_name() && - opts.subject === compose_state.subject()) || - (msg_type === "private" && - opts.private_message_recipient === compose_state.recipient())); + opts.subject === compose_state.subject() || + msg_type === "private" && + opts.private_message_recipient === compose_state.recipient()); } exports.start = function (msg_type, opts) { @@ -202,9 +202,9 @@ exports.start = function (msg_type, opts) { // If we are invoked by a compose hotkey (c or x) or new topic button // or sidebar stream actions (in stream popover), do not assume that we know what // the message's topic or PM recipient should be. - if ((opts.trigger === "compose_hotkey") || - (opts.trigger === "new topic button") || - (opts.trigger === "sidebar stream actions")) { + if (opts.trigger === "compose_hotkey" || + opts.trigger === "new topic button" || + opts.trigger === "sidebar stream actions") { opts.subject = ''; opts.private_message_recipient = ''; } @@ -280,7 +280,7 @@ exports.respond_to_message = function (opts) { var first_operator = first_term.operator; var first_operand = first_term.operand; - if ((first_operator === "stream") && !stream_data.is_subscribed(first_operand)) { + if (first_operator === "stream" && !stream_data.is_subscribed(first_operand)) { compose.nonexistent_stream_reply_error(); return; } diff --git a/static/js/compose_ui.js b/static/js/compose_ui.js index 8451c5fe85..f1511e06f6 100644 --- a/static/js/compose_ui.js +++ b/static/js/compose_ui.js @@ -8,7 +8,7 @@ exports.autosize_textarea = function () { exports.smart_insert = function (textarea, syntax) { function is_space(c) { - return (c === ' ') || (c === '\t') || (c === '\n'); + return c === ' ' || c === '\t' || c === '\n'; } var pos = textarea.caret(); diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 27ceca8f99..12fc234929 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -114,7 +114,7 @@ var nextFocus = false; function handle_keydown(e) { var code = e.keyCode || e.which; - if (code === 13 || (code === 9 && !e.shiftKey)) { // Enter key or tab key + if (code === 13 || code === 9 && !e.shiftKey) { // Enter key or tab key if (e.target.id === "stream" || e.target.id === "subject" || e.target.id === "private_message_recipient") { // For enter, prevent the form from submitting // For tab, prevent the focus from changing again @@ -228,7 +228,7 @@ function handle_keydown(e) { function handle_keyup(e) { var code = e.keyCode || e.which; - if (code === 13 || (code === 9 && !e.shiftKey)) { // Enter key or tab key + if (code === 13 || code === 9 && !e.shiftKey) { // Enter key or tab key if (nextFocus) { ui_util.focus_on(nextFocus); nextFocus = false; diff --git a/static/js/drafts.js b/static/js/drafts.js index f18c4d7c06..5786ab4232 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -64,7 +64,7 @@ var draft_model = (function () { exports.draft_model = draft_model; exports.snapshot_message = function () { - if (!compose_state.composing() || (compose_state.message_content() === "")) { + if (!compose_state.composing() || compose_state.message_content() === "") { // If you aren't in the middle of composing the body of a // message, don't try to snapshot. return; @@ -126,11 +126,11 @@ exports.restore_draft = function (draft_id) { } var draft_copy = _.extend({}, draft); - if ((draft_copy.type === "stream" && + if (draft_copy.type === "stream" && draft_copy.stream.length > 0 && - draft_copy.subject.length > 0) || - (draft_copy.type === "private" && - draft_copy.reply_to.length > 0)) { + draft_copy.subject.length > 0 || + draft_copy.type === "private" && + draft_copy.reply_to.length > 0) { draft_copy = _.extend({replying_to_message: draft_copy}, draft_copy); } diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index df38f76fd4..76ec17e08c 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -274,7 +274,7 @@ function get_alias_to_be_used(message_id, emoji_name) { } var user_id = page_params.user_id; var reaction = _.find(message.reactions, function (reaction) { - return (reaction.user.id === user_id) && _.contains(aliases, reaction.emoji_name); + return reaction.user.id === user_id && _.contains(aliases, reaction.emoji_name); }); if (reaction) { return reaction.emoji_name; @@ -322,7 +322,7 @@ exports.toggle_selected_emoji = function () { }; function round_off_to_previous_multiple(number_to_round, multiple) { - return number_to_round - (number_to_round % multiple); + return number_to_round - number_to_round % multiple; } function reset_emoji_showcase() { @@ -445,7 +445,7 @@ exports.navigate = function (event_name) { var filter_text = $(".emoji-popover-filter").val(); var is_cursor_at_end = $(".emoji-popover-filter").caret() === filter_text.length; if (event_name === "down_arrow" || - (is_cursor_at_end && event_name === "right_arrow")) { + is_cursor_at_end && event_name === "right_arrow") { selected_emoji.focus(); if (current_section === 0 && current_index < 6) { $(".emoji-popover-emoji-map").scrollTop(0); @@ -459,8 +459,8 @@ exports.navigate = function (event_name) { return true; } return false; - } else if ((current_section === 0 && current_index < 6 && event_name === 'up_arrow') || - (current_section === 0 && current_index === 0 && event_name === 'left_arrow')) { + } else if (current_section === 0 && current_index < 6 && event_name === 'up_arrow' || + current_section === 0 && current_index === 0 && event_name === 'left_arrow') { if (selected_emoji) { // In this case, we're move up into the reaction // filter. Here, we override the default browser diff --git a/static/js/filter.js b/static/js/filter.js index 6444066f48..a339e92885 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -36,8 +36,8 @@ function zephyr_topic_name_match(message, operand) { function message_in_home(message) { if (message.type === "private" || message.mentioned || - (page_params.narrow_stream !== undefined && - message.stream.toLowerCase() === page_params.narrow_stream.toLowerCase())) { + page_params.narrow_stream !== undefined && + message.stream.toLowerCase() === page_params.narrow_stream.toLowerCase()) { return true; } @@ -347,7 +347,7 @@ Filter.prototype = { operands: function (operator) { return _.chain(this._operators) - .filter(function (elem) { return !elem.negated && (elem.operator === operator); }) + .filter(function (elem) { return !elem.negated && elem.operator === operator; }) .map(function (elem) { return elem.operand; }) .value(); }, @@ -606,7 +606,7 @@ function describe_unescaped(operators) { if (operators.length >= 2) { var is = function (term, expected) { - return (term.operator === expected) && !term.negated; + return term.operator === expected && !term.negated; }; if (is(operators[0], 'stream') && is(operators[1], 'topic')) { diff --git a/static/js/floating_recipient_bar.js b/static/js/floating_recipient_bar.js index 4da2b19f7f..faa458dd41 100644 --- a/static/js/floating_recipient_bar.js +++ b/static/js/floating_recipient_bar.js @@ -93,7 +93,7 @@ exports.update = function () { // covering up a label that already exists). var header_height = $(current_label).find('.message_header').safeOuterHeight(); if (floating_recipient_bar_bottom <= - (current_label.offset().top + header_height)) { + current_label.offset().top + header_height) { // hide floating_recipient_bar and use .temp-show-date to force display // of the recipient_row_date belonging to the current recipient_bar $('.recipient_row_date', current_label).addClass('temp-show-date'); diff --git a/static/js/hash_util.js b/static/js/hash_util.js index ec0932a13e..be018386e6 100644 --- a/static/js/hash_util.js +++ b/static/js/hash_util.js @@ -12,7 +12,7 @@ exports.encodeHashComponent = function (str) { }; exports.encode_operand = function (operator, operand) { - if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) { + if (operator === 'group-pm-with' || operator === 'pm-with' || operator === 'sender') { var slug = people.emails_to_slug(operand); if (slug) { return slug; @@ -39,7 +39,7 @@ exports.decodeHashComponent = function (str) { }; exports.decode_operand = function (operator, operand) { - if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) { + if (operator === 'group-pm-with' || operator === 'pm-with' || operator === 'sender') { var emails = people.slug_to_emails(operand); if (emails) { return emails; diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 2d8581ea1b..342775d1b4 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -112,9 +112,9 @@ function do_hashchange(from_reload) { // The second case is for handling the fact that some browsers // automatically convert '#' to '' when you change the hash to '#'. if (window.location.hash === expected_hash || - (expected_hash !== undefined && + expected_hash !== undefined && window.location.hash.replace(/^#/, '') === '' && - expected_hash.replace(/^#/, '') === '')) { + expected_hash.replace(/^#/, '') === '') { return false; } diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 8c767b8f6d..d97d2b930a 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -519,7 +519,7 @@ exports.process_hotkey = function (e, hotkey) { } } - if ((actions_dropdown_hotkeys.indexOf(event_name) !== -1) && popovers.actions_popped()) { + if (actions_dropdown_hotkeys.indexOf(event_name) !== -1 && popovers.actions_popped()) { popovers.actions_menu_handle_keyboard(event_name); return true; } diff --git a/static/js/hotspots.js b/static/js/hotspots.js index 73aeac8470..93890d8f5c 100644 --- a/static/js/hotspots.js +++ b/static/js/hotspots.js @@ -97,14 +97,14 @@ function place_popover(hotspot) { case TOP: popover_offset = { top: -(popover_height + arrow_offset), - left: (el_width / 2) - (popover_width / 2), + left: el_width / 2 - popover_width / 2, }; arrow_placement = 'bottom'; break; case LEFT: popover_offset = { - top: (el_height / 2) - (popover_height / 2), + top: el_height / 2 - popover_height / 2, left: -(popover_width + arrow_offset), }; arrow_placement = 'right'; @@ -113,14 +113,14 @@ function place_popover(hotspot) { case BOTTOM: popover_offset = { top: el_height + arrow_offset, - left: (el_width / 2) - (popover_width / 2), + left: el_width / 2 - popover_width / 2, }; arrow_placement = 'top'; break; case RIGHT: popover_offset = { - top: (el_height / 2) - (popover_height / 2), + top: el_height / 2 - popover_height / 2, left: el_width + arrow_offset, }; arrow_placement = 'left'; diff --git a/static/js/invite.js b/static/js/invite.js index cc2abf6cfb..c6aaf0f376 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -11,9 +11,9 @@ function update_subscription_checkboxes() { _.each(stream_data.invite_streams(), function (value) { var is_notifications_stream = value === page_params.notifications_stream; - if ((stream_data.subscribed_streams().length === 1) || + if (stream_data.subscribed_streams().length === 1 || !is_notifications_stream || - (is_notifications_stream && stream_data.get_invite_only(value))) { + is_notifications_stream && stream_data.get_invite_only(value)) { // You can't actually elect not to invite someone to the // notifications stream. We won't even show it as a choice unless // it's the only stream you have, or if you've made it private. diff --git a/static/js/lightbox_canvas.js b/static/js/lightbox_canvas.js index c610c635e2..f90fc6d80e 100644 --- a/static/js/lightbox_canvas.js +++ b/static/js/lightbox_canvas.js @@ -66,8 +66,8 @@ var LightboxCanvas = (function () { // where the last `layerX` and `layerY` movements since the last // `mousemove` event in this `mousedown` event were registered. var polyfillMouseMovement = function (e) { - e.movementX = (e.layerX - lastPosition.x) || 0; - e.movementY = (e.layerY - lastPosition.y) || 0; + e.movementX = e.layerX - lastPosition.x || 0; + e.movementY = e.layerY - lastPosition.y || 0; lastPosition = { x: e.layerX, @@ -103,7 +103,7 @@ var LightboxCanvas = (function () { // normalizedDelta = delta * (1 / 20) * 1 = 0.4 // zoom = zoom * (0.4 / 100) + 1 var zoom = meta.zoom * ( - (meta.speed * meta.internalSpeedMultiplier * delta / 100) + 1 + meta.speed * meta.internalSpeedMultiplier * delta / 100 + 1 ); funcs.setZoom(meta, zoom); @@ -201,18 +201,18 @@ var LightboxCanvas = (function () { displayImage: function (canvas, context, meta) { meta.coords.x = Math.max(1 / (meta.zoom * 2), meta.coords.x); - meta.coords.x = Math.min(1 - (1 / (meta.zoom * 2)), meta.coords.x); + meta.coords.x = Math.min(1 - 1 / (meta.zoom * 2), meta.coords.x); meta.coords.y = Math.max(1 / (meta.zoom * 2), meta.coords.y); - meta.coords.y = Math.min(1 - (1 / (meta.zoom * 2)), meta.coords.y); + meta.coords.y = Math.min(1 - 1 / (meta.zoom * 2), meta.coords.y); var c = { x: meta.coords.x - 1, y: meta.coords.y - 1, }; - var x = (meta.zoom * c.x * canvas.width) + canvas.width / 2; - var y = (meta.zoom * c.y * canvas.height) + canvas.height / 2; + var x = meta.zoom * c.x * canvas.width + canvas.width / 2; + var y = meta.zoom * c.y * canvas.height + canvas.height / 2; var w = canvas.width * meta.zoom; var h = canvas.height * meta.zoom; @@ -244,7 +244,7 @@ var LightboxCanvas = (function () { canvas.style.width = parent.width + "px"; - canvas.height = (parent.width / meta.ratio) * 2; + canvas.height = parent.width / meta.ratio * 2; canvas.style.height = parent.width / meta.ratio + "px"; } else { canvas.height = parent.height * 2; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 285aba958b..25a7bdb057 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -21,8 +21,8 @@ function is_topic_editable(message, edit_limit_seconds_buffer) { edit_limit_seconds_buffer = edit_limit_seconds_buffer || 0; // TODO: Change hardcoded value (24 hrs) to be realm setting - return message.sent_by_me || (page_params.realm_allow_community_topic_editing - && (86400 + edit_limit_seconds_buffer + now.diffSeconds(message.timestamp * 1000) > 0)); + return message.sent_by_me || page_params.realm_allow_community_topic_editing + && 86400 + edit_limit_seconds_buffer + now.diffSeconds(message.timestamp * 1000) > 0; } function get_editability(message, edit_limit_seconds_buffer) { @@ -57,8 +57,8 @@ function get_editability(message, edit_limit_seconds_buffer) { } var now = new XDate(); - if ((page_params.realm_message_content_edit_limit_seconds + edit_limit_seconds_buffer + - now.diffSeconds(message.timestamp * 1000) > 0) && message.sent_by_me) { + if (page_params.realm_message_content_edit_limit_seconds + edit_limit_seconds_buffer + + now.diffSeconds(message.timestamp * 1000) > 0 && message.sent_by_me) { return editability_types.FULL; } diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index 5e11b8db69..2110c30990 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -20,7 +20,7 @@ function process_result(data, opts) { $('#connection-error').removeClass("show"); - if ((messages.length === 0) && (current_msg_list === message_list.narrowed) && + if (messages.length === 0 && current_msg_list === message_list.narrowed && message_list.narrowed.empty()) { // Even after trying to load more messages, we have no // messages to display in this narrow. diff --git a/static/js/message_list.js b/static/js/message_list.js index e1d38a7ad8..faa7a96538 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -57,15 +57,15 @@ exports.MessageList.prototype = { self.append_to_view(bottom_messages, opts); } - if ((self === exports.narrowed) && !self.empty()) { + if (self === exports.narrowed && !self.empty()) { // If adding some new messages to the message tables caused // our current narrow to no longer be empty, hide the empty // feed placeholder text. narrow.hide_empty_narrow_message(); } - if ((self === exports.narrowed) && !self.empty() && - (self.selected_id() === -1)) { + if (self === exports.narrowed && !self.empty() && + self.selected_id() === -1) { // And also select the newly arrived message. self.select_id(self.selected_id(), {then_scroll: true, use_closest: true}); } @@ -318,7 +318,7 @@ exports.MessageList.prototype = { show_message_as_read: function (message, options) { var row = this.get_row(message.id); - if ((options.from === 'pointer' && feature_flags.mark_read_at_bottom) || + if (options.from === 'pointer' && feature_flags.mark_read_at_bottom || options.from === "server") { row.find('.unread_marker').addClass('fast_fade'); } else { diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js index 0bb991cfb1..73eb7d4cf0 100644 --- a/static/js/message_list_data.js +++ b/static/js/message_list_data.js @@ -193,7 +193,7 @@ MessageListData.prototype = { update_user_full_name: function (user_id, full_name) { _.each(this._items, function (item) { - if (item.sender_id && (item.sender_id === user_id)) { + if (item.sender_id && item.sender_id === user_id) { item.sender_full_name = full_name; } }); @@ -205,7 +205,7 @@ MessageListData.prototype = { // especially if we want to optimize this with some kind of // hash that maps sender_id -> messages. _.each(this._items, function (item) { - if (item.sender_id && (item.sender_id === user_id)) { + if (item.sender_id && item.sender_id === user_id) { item.small_avatar_url = avatar_url; } }); @@ -213,7 +213,7 @@ MessageListData.prototype = { update_stream_name: function (stream_id, new_stream_name) { _.each(this._items, function (item) { - if (item.stream_id && (item.stream_id === stream_id)) { + if (item.stream_id && item.stream_id === stream_id) { item.display_recipient = new_stream_name; item.stream = new_stream_name; } @@ -545,8 +545,8 @@ MessageListData.prototype = { var prev = self._next_nonlocal_message(self._items, index, function (idx) { return idx - 1; }); - if ((next !== undefined && current_message.id > next.id) || - (prev !== undefined && current_message.id < prev.id)) { + if (next !== undefined && current_message.id > next.id || + prev !== undefined && current_message.id < prev.id) { blueslip.debug("Changed message ID from server caused out-of-order list, reordering"); self._items.sort(message_sort_func); if (self.muting_enabled) { diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index f79e569d6a..41f5fd02d0 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -18,7 +18,7 @@ function MessageListView(list, table_name, collapse_messages) { function mention_button_refers_to_me(elem) { var user_id = $(elem).attr('data-user-id'); - if ((user_id === '*') || people.is_my_user_id(user_id)) { + if (user_id === '*' || people.is_my_user_id(user_id)) { return true; } @@ -688,7 +688,7 @@ MessageListView.prototype = { var last_visible = rows.last_visible(); // Make sure we have a selected row and last visible row. (defensive) - if (!(selected_row && (selected_row.length > 0) && last_visible)) { + if (!(selected_row && selected_row.length > 0 && last_visible)) { return; } @@ -791,10 +791,10 @@ MessageListView.prototype = { // of the bottom of the currently rendered window and the // bottom of the window does not abut the end of the // message list - if (!(((selected_idx - this._render_win_start < this._RENDER_THRESHOLD) - && (this._render_win_start !== 0)) || - ((this._render_win_end - selected_idx <= this._RENDER_THRESHOLD) - && (this._render_win_end !== this.list.num_items())))) { + if (!(selected_idx - this._render_win_start < this._RENDER_THRESHOLD + && this._render_win_start !== 0 || + this._render_win_end - selected_idx <= this._RENDER_THRESHOLD + && this._render_win_end !== this.list.num_items())) { return false; } diff --git a/static/js/message_viewport.js b/static/js/message_viewport.js index 9ad734aa80..fc931150d5 100644 --- a/static/js/message_viewport.js +++ b/static/js/message_viewport.js @@ -106,10 +106,10 @@ exports.set_message_position = function (message_top, message_height, viewport_i function in_viewport_or_tall(rect, top_of_feed, bottom_of_feed, require_fully_visible) { if (require_fully_visible) { - return (rect.top > top_of_feed) && // Message top is in view and - ((rect.bottom < bottom_of_feed) || // message is fully in view or - ((rect.height > bottom_of_feed - top_of_feed) && - (rect.top < bottom_of_feed))); // message is tall. + return rect.top > top_of_feed && // Message top is in view and + (rect.bottom < bottom_of_feed || // message is fully in view or + rect.height > bottom_of_feed - top_of_feed && + rect.top < bottom_of_feed); // message is tall. } return rect.bottom > top_of_feed && rect.top < bottom_of_feed; } @@ -334,8 +334,8 @@ exports.keep_pointer_in_view = function () { } var info = message_viewport.message_viewport_info(); - var top_threshold = info.visible_top + (1 / 10 * info.visible_height); - var bottom_threshold = info.visible_top + (9 / 10 * info.visible_height); + var top_threshold = info.visible_top + 1 / 10 * info.visible_height; + var bottom_threshold = info.visible_top + 9 / 10 * info.visible_height; function message_is_far_enough_down() { if (message_viewport.at_top()) { @@ -365,7 +365,7 @@ exports.keep_pointer_in_view = function () { function message_is_far_enough_up() { return message_viewport.at_bottom() || - (next_row.offset().top <= bottom_threshold); + next_row.offset().top <= bottom_threshold; } function adjust(in_view, get_next_row) { diff --git a/static/js/narrow.js b/static/js/narrow.js index b9c0ae95c2..ac0081a399 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -411,8 +411,8 @@ exports.update_selection = function (opts) { } var preserve_pre_narrowing_screen_position = - (message_list.narrowed.get(msg_id) !== undefined) && - (select_offset !== undefined); + message_list.narrowed.get(msg_id) !== undefined && + select_offset !== undefined; var then_scroll = !preserve_pre_narrowing_screen_position; @@ -620,8 +620,8 @@ exports.deactivate = function () { if (current_msg_list.selected_id() !== -1) { var preserve_pre_narrowing_screen_position = - (current_msg_list.selected_row().length > 0) && - (current_msg_list.pre_narrow_offset !== undefined); + current_msg_list.selected_row().length > 0 && + current_msg_list.pre_narrow_offset !== undefined; var message_id_to_select; var select_opts = { then_scroll: true, @@ -711,7 +711,7 @@ function pick_empty_narrow_banner() { // You have no unread messages. return $("#no_unread_narrow_message"); } - } else if ((first_operator === "stream") && !stream_data.is_subscribed(first_operand)) { + } else if (first_operator === "stream" && !stream_data.is_subscribed(first_operand)) { // You are narrowed to a stream which does not exist or is a private stream // in which you were never subscribed. var stream_sub = stream_data.get_sub(narrow_state.stream()); diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js index c0e9faf1cb..c833e4c9ec 100644 --- a/static/js/narrow_state.js +++ b/static/js/narrow_state.js @@ -334,7 +334,7 @@ exports.narrowed_to_topic = function () { }; exports.narrowed_to_search = function () { - return (current_filter !== undefined) && current_filter.is_search(); + return current_filter !== undefined && current_filter.is_search(); }; exports.muting_enabled = function () { diff --git a/static/js/navigate.js b/static/js/navigate.js index 10ab21e082..0c39cc5577 100644 --- a/static/js/navigate.js +++ b/static/js/navigate.js @@ -122,7 +122,7 @@ exports.page_down = function () { exports.scroll_to_selected = function () { var selected_row = current_msg_list.selected_row(); - if (selected_row && (selected_row.length !== 0)) { + if (selected_row && selected_row.length !== 0) { message_viewport.recenter_view(selected_row); } }; diff --git a/static/js/notifications.js b/static/js/notifications.js index 14755850eb..f8b35306fb 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -393,12 +393,12 @@ exports.message_is_notifiable = function (message) { // Messages to muted streams that don't mention us specifically // are not notifiable. - if ((message.type === "stream") && + if (message.type === "stream" && !stream_data.in_home_view(message.stream_id)) { return false; } - if ((message.type === "stream") && + if (message.type === "stream" && muting.is_topic_muted(message.stream, message.subject)) { return false; } @@ -411,14 +411,14 @@ exports.message_is_notifiable = function (message) { function should_send_desktop_notification(message) { // For streams, send if desktop notifications are enabled for this // stream. - if ((message.type === "stream") && + if (message.type === "stream" && stream_data.receives_desktop_notifications(message.stream)) { return true; } // For PMs and @-mentions, send if desktop notifications are // enabled. - if ((message.type === "private") && + if (message.type === "private" && page_params.enable_desktop_notifications) { return true; } @@ -440,13 +440,13 @@ function should_send_desktop_notification(message) { function should_send_audible_notification(message) { // For streams, ding if sounds are enabled for this stream. - if ((message.type === "stream") && + if (message.type === "stream" && stream_data.receives_audible_notifications(message.stream)) { return true; } // For PMs and @-mentions, ding if sounds are enabled. - if ((message.type === "private") && page_params.enable_sounds) { + if (message.type === "private" && page_params.enable_sounds) { return true; } diff --git a/static/js/pm_list.js b/static/js/pm_list.js index 42b1a591d9..7a3161f2c1 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -96,8 +96,8 @@ exports._build_private_messages_list = function (active_conversation, max_privat var num_unread = unread.num_unread_for_person(user_ids_string); - var always_visible = (idx < max_private_messages) || (num_unread > 0) - || (user_ids_string === active_conversation); + var always_visible = idx < max_private_messages || num_unread > 0 + || user_ids_string === active_conversation; if (!always_visible) { if (!zoomed_in) { diff --git a/static/js/popovers.js b/static/js/popovers.js index 84fc460198..9d09f1c8fa 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -101,9 +101,9 @@ function user_last_seen_time_status(user_id) { function calculate_info_popover_placement(size, elt) { var ypos = elt.offset().top; - if (!((ypos + (size / 2) < message_viewport.height()) && - (ypos > (size / 2)))) { - if ((ypos + size) < message_viewport.height()) { + if (!(ypos + size / 2 < message_viewport.height() && + ypos > size / 2)) { + if (ypos + size < message_viewport.height()) { return 'bottom'; } else if (ypos > size) { return 'top'; @@ -345,7 +345,7 @@ exports.toggle_actions_popover = function (element, id) { var ypos = elt.offset().top; elt.popover({ // Popover height with 7 items in it is ~190 px - placement: (message_viewport.height() - ypos) < 220 ? 'top' : 'bottom', + placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom', title: "", content: templates.render('actions_popover_content', args), trigger: "manual", @@ -368,7 +368,7 @@ exports.render_actions_remind_popover = function (element, id) { var ypos = elt.offset().top; elt.popover({ // Popover height with 7 items in it is ~190 px - placement: (message_viewport.height() - ypos) < 220 ? 'top' : 'bottom', + placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom', title: "", content: templates.render('remind_me_popover_content', args), trigger: "manual", diff --git a/static/js/presence.js b/static/js/presence.js index 65a5ca3de1..4730d348f0 100644 --- a/static/js/presence.js +++ b/static/js/presence.js @@ -25,7 +25,7 @@ exports.is_active = function (user_id) { if (presence_info[user_id]) { var status = presence_info[user_id].status; - if (status && (status === "active")) { + if (status && status === "active") { return true; } } diff --git a/static/js/reactions.js b/static/js/reactions.js index 2bf3d3836e..ab1d9b0259 100644 --- a/static/js/reactions.js +++ b/static/js/reactions.js @@ -33,9 +33,9 @@ exports.open_reactions_popover = function () { exports.current_user_has_reacted_to_emoji = function (message, emoji_code, type) { var user_id = page_params.user_id; return _.any(message.reactions, function (r) { - return (r.user.id === user_id) && - (r.reaction_type === type) && - (r.emoji_code === emoji_code); + return r.user.id === user_id && + r.reaction_type === type && + r.emoji_code === emoji_code; }); }; @@ -206,7 +206,7 @@ exports.add_reaction = function (event) { var reacted = exports.current_user_has_reacted_to_emoji(message, event.emoji_code, event.reaction_type); - if (reacted && (event.user.user_id === page_params.user_id)) { + if (reacted && event.user.user_id === page_params.user_id) { return; } @@ -317,7 +317,7 @@ exports.remove_reaction = function (event) { var not_reacted = !exports.current_user_has_reacted_to_emoji(message, emoji_code, reaction_type); - if (not_reacted && (event.user.user_id === page_params.user_id)) { + if (not_reacted && event.user.user_id === page_params.user_id) { return; } diff --git a/static/js/scroll_bar.js b/static/js/scroll_bar.js index efe2ece0d6..47d9d85f3a 100644 --- a/static/js/scroll_bar.js +++ b/static/js/scroll_bar.js @@ -37,21 +37,21 @@ $(function () { if (sbWidth > 0) { $(".header").css("left", "-" + sbWidth + "px"); $(".header-main").css("left", sbWidth + "px"); - $(".header-main").css("max-width", (1400 + sbWidth) + "px"); - $(".header-main .column-middle").css("margin-right", (250 + sbWidth) + "px"); + $(".header-main").css("max-width", 1400 + sbWidth + "px"); + $(".header-main .column-middle").css("margin-right", 250 + sbWidth + "px"); $(".fixed-app").css("left", "-" + sbWidth + "px"); - $(".fixed-app .app-main").css("max-width", (1400 + sbWidth) + "px"); - $(".fixed-app .column-middle").css("margin-left", (250 + sbWidth) + "px"); + $(".fixed-app .app-main").css("max-width", 1400 + sbWidth + "px"); + $(".fixed-app .column-middle").css("margin-left", 250 + sbWidth + "px"); $(".column-right").css("right", sbWidth + "px"); $(".app-main .right-sidebar").css({"margin-left": sbWidth + "px", - width: (250 - sbWidth) + "px"}); + width: 250 - sbWidth + "px"}); $("#compose").css("left", "-" + sbWidth + "px"); $(".compose-content").css({left: sbWidth + "px", - "margin-right": (250 + sbWidth) + "px"}); - $("#compose-container").css("max-width", (1400 + sbWidth) + "px"); + "margin-right": 250 + sbWidth + "px"}); + $("#compose-container").css("max-width", 1400 + sbWidth + "px"); $('#sidebar-keyboard-shortcuts #keyboard-icon').css({right: sbWidth + 13 + "px"}); $("head").append("