From 4d37dfcf85470831e8bbe2b6900d52d4a088bdb6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 25 Oct 2019 15:11:05 -0700 Subject: [PATCH] js: Convert vars declared separately and assigned once to const. Because of the separate declarations, ESLint would convert them to `let` and then trigger the `prefer-const` error. Signed-off-by: Anders Kaseorg --- frontend_tests/node_tests/hashchange.js | 10 +++------- frontend_tests/zjsunit/zjquery.js | 3 +-- static/js/compose_actions.js | 3 +-- static/js/compose_pm_pill.js | 3 +-- static/js/filter.js | 7 ++----- static/js/message_list_view.js | 3 +-- static/js/reload.js | 3 +-- static/js/resize.js | 3 +-- static/js/search_suggestion.js | 12 ++++-------- static/js/settings_bots.js | 3 +-- static/js/stream_color.js | 3 +-- static/js/ui_init.js | 4 +--- 12 files changed, 18 insertions(+), 39 deletions(-) diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index a9bebe06b7..8f1e65e083 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -77,11 +77,8 @@ run_test('operators_round_trip', () => { }); run_test('operators_trailing_slash', () => { - var hash; - var narrow; - - hash = '#narrow/stream/devel/topic/algol/'; - narrow = hash_util.parse_narrow(hash.split('/')); + const hash = '#narrow/stream/devel/topic/algol/'; + const narrow = hash_util.parse_narrow(hash.split('/')); assert.deepEqual(narrow, [ {operator: 'stream', operand: 'devel', negated: false}, {operator: 'topic', operand: 'algol', negated: false}, @@ -91,7 +88,6 @@ run_test('operators_trailing_slash', () => { run_test('people_slugs', () => { var operators; var hash; - var narrow; var alice = { email: 'alice@example.com', @@ -105,7 +101,7 @@ run_test('people_slugs', () => { ]; hash = hash_util.operators_to_hash(operators); assert.equal(hash, '#narrow/sender/42-alice'); - narrow = hash_util.parse_narrow(hash.split('/')); + const narrow = hash_util.parse_narrow(hash.split('/')); assert.deepEqual(narrow, [ {operator: 'sender', operand: 'alice@example.com', negated: false}, ]); diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index e43736c45f..e9764e21d6 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -74,7 +74,6 @@ exports.make_event_store = (selector) => { // (event_name, handler) or // (event_name, sel, handler) var event_name = arguments[0]; - var sel; var handler; if (arguments.length === 2) { @@ -93,7 +92,7 @@ exports.make_event_store = (selector) => { throw Error('wrong number of arguments passed in'); } - sel = arguments[1]; + const sel = arguments[1]; handler = arguments[2]; assert.equal(typeof sel, 'string', 'String selectors expected here.'); assert.equal(typeof handler, 'function', 'An handler function expected here.'); diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 7edaeff227..a3076eb065 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -273,13 +273,12 @@ exports.cancel = function () { }; exports.respond_to_message = function (opts) { - var message; var msg_type; // Before initiating a reply to a message, if there's an // in-progress composition, snapshot it. drafts.update_draft(); - message = current_msg_list.selected_message(); + const message = current_msg_list.selected_message(); if (message === undefined) { // empty narrow implementation if (!narrow_state.narrowed_by_pm_reply() && diff --git a/static/js/compose_pm_pill.js b/static/js/compose_pm_pill.js index f542b3a4e8..184cd5dad2 100644 --- a/static/js/compose_pm_pill.js +++ b/static/js/compose_pm_pill.js @@ -1,8 +1,7 @@ exports.initialize_pill = function () { - var pill; var container = $("#private_message_recipient").parent(); - pill = input_pill.create({ + const pill = input_pill.create({ container: container, create_item_from_text: user_pill.create_item_from_email, get_text_from_item: user_pill.get_email_from_item, diff --git a/static/js/filter.js b/static/js/filter.js index d902aa2530..81152ed412 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -261,9 +261,8 @@ Filter.parse = function (str) { return operators; } _.each(matches, function (token) { - var parts; var operator; - parts = token.split(':'); + const parts = token.split(':'); if (token[0] === '"' || parts.length === 1) { // Looks like a normal search term. search_term.push(token); @@ -607,15 +606,13 @@ Filter.sorted_term_types = function (term_types) { }; Filter.operator_to_prefix = function (operator, negated) { - var verb; - operator = Filter.canonicalize_operator(operator); if (operator === 'search') { return negated ? 'exclude' : 'search for'; } - verb = negated ? 'exclude ' : ''; + const verb = negated ? 'exclude ' : ''; switch (operator) { case 'stream': diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 325415a95e..c5fe744430 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -649,7 +649,6 @@ MessageListView.prototype = { var table_name = self.table_name; var table = rows.get_table(table_name); var orig_scrolltop_offset; - var message_containers; // If we start with the message feed scrolled up (i.e. // the bottom message is not visible), then we will respect @@ -661,7 +660,7 @@ MessageListView.prototype = { // all messages lists. To prevent having both list views overwriting // each others data we will make a new message object to add data to // for rendering. - message_containers = _.map(messages, function (message) { + const message_containers = _.map(messages, function (message) { if (message.starred) { message.starred_status = i18n.t("Unstar"); } else { diff --git a/static/js/reload.js b/static/js/reload.js index e36faa9cd9..cc7934bfce 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -252,7 +252,6 @@ exports.initiate = function (options) { var unconditional_timeout = 1000 * 60 * 30 + util.random_int(0, 1000 * 60 * 5); var composing_timeout = 1000 * 60 * 5 + util.random_int(0, 1000 * 60); var home_timeout = 1000 * 60 + util.random_int(0, 1000 * 60); - var compose_done_handler; var compose_started_handler; function reload_from_idle() { @@ -266,7 +265,7 @@ exports.initiate = function (options) { // Make sure we always do a reload eventually setTimeout(reload_from_idle, unconditional_timeout); - compose_done_handler = function () { + const compose_done_handler = function () { idle_control.cancel(); idle_control = $(document).idle({idle: home_timeout, onIdle: reload_from_idle}); diff --git a/static/js/resize.js b/static/js/resize.js index ca0aef5d8f..13fbff41c7 100644 --- a/static/js/resize.js +++ b/static/js/resize.js @@ -201,7 +201,6 @@ exports.resize_stream_filters_container = function (h) { }; exports.resize_page_components = function () { - var h; var sidebar; if (page_params.left_side_userlist) { @@ -232,7 +231,7 @@ exports.resize_page_components = function () { } } - h = narrow_window ? left_userlist_get_new_heights() : get_new_heights(); + const h = narrow_window ? left_userlist_get_new_heights() : get_new_heights(); exports.resize_bottom_whitespace(h); $("#buddy_list_wrapper").css('max-height', h.buddy_list_wrapper_max_height); diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index a81d067fcc..e91a5c5330 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -121,8 +121,6 @@ function get_group_suggestions(all_persons, last, operators) { // // We only generate group suggestions when there's more than one part, and // we only use the last part to generate suggestions. - var all_but_last_part; - var last_part; var last_comma_index = operand.lastIndexOf(','); if (last_comma_index < 0) { @@ -130,8 +128,8 @@ function get_group_suggestions(all_persons, last, operators) { } // Neither all_but_last_part nor last_part include the final comma. - all_but_last_part = operand.slice(0, last_comma_index); - last_part = operand.slice(last_comma_index + 1); + const all_but_last_part = operand.slice(0, last_comma_index); + const last_part = operand.slice(last_comma_index + 1); // We don't suggest a person if their email is already present in the // operand (not including the last part). @@ -565,7 +563,6 @@ exports.get_suggestions = function (base_query, query) { // with information for subsequent callbacks. var result = []; var suggestion; - var base; //base, default suggestion var suggestions; // base_query_operators correspond to the existing pills. query_operators correspond @@ -632,7 +629,7 @@ exports.get_suggestions = function (base_query, query) { base_operators = operators.slice(0, -1); } - base = get_default_suggestion(query_operators.slice(0, -1)); + const base = get_default_suggestion(query_operators.slice(0, -1)); // Get all individual suggestions, and then attach_suggestions // mutates the list 'result' to add a properly-formatted suggestion @@ -708,7 +705,6 @@ exports.get_suggestions_legacy = function (query) { // with information for subsequent callbacks. var result = []; var suggestion; - var base; //base, default suggestion var suggestions; // Add an entry for narrow by operators. @@ -755,7 +751,7 @@ exports.get_suggestions_legacy = function (query) { if (operators.length > 1) { base_operators = operators.slice(0, -1); } - base = get_default_suggestion_legacy(base_operators); + const base = get_default_suggestion_legacy(base_operators); // Get all individual suggestions, and then attach_suggestions // mutates the list 'result' to add a properly-formatted suggestion diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js index 2c5e8dd56e..bf5d58e017 100644 --- a/static/js/settings_bots.js +++ b/static/js/settings_bots.js @@ -115,14 +115,13 @@ exports.render_bots = function () { exports.generate_zuliprc_uri = function (bot_id) { var bot = bot_data.get(bot_id); - var data; var token; // For outgoing webhooks, include the token in the zuliprc. // It's needed for authenticating to the Botserver. if (bot.bot_type === 3) { token = bot_data.get_services(bot_id)[0].token; } - data = exports.generate_zuliprc_content(bot.email, bot.api_key, token); + const data = exports.generate_zuliprc_content(bot.email, bot.api_key, token); return exports.encode_zuliprc_as_uri(data); }; diff --git a/static/js/stream_color.js b/static/js/stream_color.js index 49c0941580..4d7fcde6c3 100644 --- a/static/js/stream_color.js +++ b/static/js/stream_color.js @@ -127,7 +127,6 @@ exports.initialize = function () { exports.get_color_class = _.memoize(function (color) { var match; var i; - var lightness; var channel = [0, 0, 0]; var mult = 1; @@ -151,7 +150,7 @@ exports.get_color_class = _.memoize(function (color) { } // Compute perceived lightness as CIE L*. - lightness = colorspace.luminance_to_lightness( + const lightness = colorspace.luminance_to_lightness( colorspace.rgb_luminance(channel)); // Determine if we're past the midpoint between the diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 73f9040030..58488ca8d4 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -16,8 +16,6 @@ function message_unhover() { } function message_hover(message_row) { - var message; - var id = parseInt(message_row.attr("zid"), 10); if (current_message_hover && message_row && current_message_hover.attr("zid") === message_row.attr("zid")) { return; @@ -26,7 +24,7 @@ function message_hover(message_row) { if (message_row.hasClass('local')) { return; } - message = current_msg_list.get(rows.id(message_row)); + const message = current_msg_list.get(rows.id(message_row)); message_unhover(); current_message_hover = message_row;