eslint: change one-var from warning to error and fix violations

This commit is contained in:
AZtheAsian 2016-12-02 09:09:31 -07:00
parent b3f4feb996
commit ed0bc831be
22 changed files with 94 additions and 41 deletions

View File

@ -165,7 +165,7 @@
"max-statements": [0, 10],
"new-cap": 1,
"new-parens": 2,
"one-var": 1,
"one-var": ["error", "never"],
"quotes": [1, "single"],
"quote-props": 0,
"radix": 2,

View File

@ -386,10 +386,10 @@ $(function () {
(function () {
$("#main_div").on("click", ".message_inline_image a", function (e) {
var img = e.target,
row = rows.id($(img).closest(".message_row")),
user = current_msg_list.get(row).sender_full_name,
$target = $(this);
var img = e.target;
var row = rows.id($(img).closest(".message_row"));
var user = current_msg_list.get(row).sender_full_name;
var $target = $(this);
// prevent the link from opening in a new page.
e.preventDefault();

View File

@ -610,7 +610,8 @@ function send_message(request) {
}
exports.respond_to_message = function (opts) {
var message, msg_type;
var message;
var msg_type;
// Before initiating a reply to a message, if there's an
// in-progress composition, snapshot it.
compose.snapshot_message();
@ -1117,9 +1118,9 @@ $(function () {
if (response.uri === undefined) {
return;
}
var textbox = $("#new_message_content"),
split_uri = response.uri.split("/"),
filename = split_uri[split_uri.length - 1];
var textbox = $("#new_message_content");
var split_uri = response.uri.split("/");
var filename = split_uri[split_uri.length - 1];
// Urgh, yet another hack to make sure we're "composing"
// when text gets added into the composebox.
if (!compose.composing()) {

View File

@ -54,7 +54,9 @@ function change_fade_state(elt, should_fade_group) {
}
function _fade_messages() {
var i, first_message, first_row;
var i;
var first_message;
var first_row;
var should_fade_group = false;
var visible_groups = viewport.visible_groups(false);

View File

@ -3,7 +3,8 @@ var copy_and_paste = (function () {
var exports = {}; // we don't actually export anything yet, but that's ok
function find_boundary_tr(initial_tr, iterate_row) {
var j, skip_same_td_check = false;
var j;
var skip_same_td_check = false;
var tr = initial_tr;
// If the selection boundary is somewhere that does not have a
@ -37,10 +38,21 @@ function find_boundary_tr(initial_tr, iterate_row) {
function copy_handler(e) {
var selection = window.getSelection();
var i, range, ranges = [], startc, endc, initial_end_tr, start_id, end_id, row, message;
var start_data, end_data;
var i;
var range;
var ranges = [];
var startc;
var endc;
var initial_end_tr;
var start_id;
var end_id;
var row;
var message;
var start_data;
var end_data;
var skip_same_td_check = false;
var div = $('<div>'), content;
var div = $('<div>');
var content;
for (i = 0; i < selection.rangeCount; i += 1) {
range = selection.getRangeAt(i);
ranges.push(range);

View File

@ -81,7 +81,10 @@ var exports = {};
});
$(document).on('message_rendered.zulip', function (e) {
var $inline_subscribe, $button, stream_name, id;
var $inline_subscribe;
var $button;
var stream_name;
var id;
$inline_subscribe = $(e.target).find('.inline-subscribe');
if ($inline_subscribe.length === 0) {
return;

View File

@ -217,7 +217,8 @@ Filter.parse = function (str) {
return operators;
}
_.each(matches, function (token) {
var parts, operator;
var parts;
var operator;
parts = token.split(':');
if (token[0] === '"' || parts.length === 1) {
// Looks like a normal search term.

View File

@ -14,7 +14,9 @@ function show_floating_recipient_bar() {
var old_label;
function replace_floating_recipient_bar(desired_label) {
var new_label, other_label, header;
var new_label;
var other_label;
var header;
if (desired_label !== old_label) {
if (desired_label.children(".message_header_stream").length !== 0) {
new_label = $("#current_label_stream");

View File

@ -83,7 +83,8 @@ exports.save_narrow = function (operators) {
};
function parse_narrow(hash) {
var i, operators = [];
var i;
var operators = [];
for (i=1; i<hash.length; i+=2) {
// We don't construct URLs with an odd number of components,
// but the user might write one.

View File

@ -104,9 +104,11 @@ function get_hotkey_from_event(e) {
//
// Returns true if we handled it, false if the browser should.
function process_hotkey(e) {
var row, alert_words_content, focused_message_edit_content,
focused_message_edit_save, message_edit_form;
var row;
var alert_words_content;
var focused_message_edit_content;
var focused_message_edit_save;
var message_edit_form;
var hotkey = get_hotkey_from_event(e);
var event_name = hotkey.name;
activity.new_user_input = true;

View File

@ -121,7 +121,8 @@ exports.save = function (row, from_topic_edited_only) {
};
function handle_edit_keydown(from_topic_edited_only, e) {
var row, code = e.keyCode || e.which;
var row;
var code = e.keyCode || e.which;
if (e.target.id === "message_edit_content" && code === 13 &&
(e.metaKey || e.ctrlKey)) {

View File

@ -363,7 +363,8 @@ exports.MessageList.prototype = {
if (stream === undefined) {
return;
}
var trailing_bookend_content, subscribed = stream_data.is_subscribed(stream);
var trailing_bookend_content;
var subscribed = stream_data.is_subscribed(stream);
if (subscribed) {
trailing_bookend_content = this.subscribed_bookend_content(stream);
} else {

View File

@ -277,7 +277,8 @@ MessageListView.prototype = {
append_messages: [],
rerender_messages: []
};
var first_group, second_group;
var first_group;
var second_group;
if (where === 'top') {
first_group = _.last(new_message_groups);
@ -389,8 +390,11 @@ MessageListView.prototype = {
var table = rows.get_table(table_name);
// we we record if last_message_was_selected before updating the table
var last_message_was_selected = rows.id(rows.last_visible()) === list.selected_id();
var orig_scrolltop_offset, last_message_id;
var message_containers, first_msg, last_msg;
var orig_scrolltop_offset;
var last_message_id;
var message_containers;
var first_msg;
var last_msg;
var self = this;
@ -423,7 +427,10 @@ MessageListView.prototype = {
var new_message_groups = this.build_message_groups(message_containers, this.table_name);
var message_actions = this.merge_message_groups(new_message_groups, where);
var new_dom_elements = [];
var rendered_groups, dom_messages, last_message_row, last_group_row;
var rendered_groups;
var dom_messages;
var last_message_row;
var last_group_row;
_.each(message_containers, function (message_container) {
self.message_containers[message_container.msg.id] = message_container;

View File

@ -15,7 +15,8 @@ exports.get = function get(message_id) {
};
exports.get_private_message_recipient = function (message, attr, fallback_attr) {
var recipient, i;
var recipient;
var i;
var other_recipients = _.filter(message.display_recipient,
function (element) {
return !util.is_current_user(element.email);
@ -616,7 +617,8 @@ util.execute_early(function () {
}
$(document).on('message_id_changed', function (event) {
var old_id = event.old_id, new_id = event.new_id;
var old_id = event.old_id;
var new_id = event.new_id;
if (pointer.furthest_read === old_id) {
pointer.furthest_read = new_id;
}

View File

@ -69,7 +69,8 @@ exports.page_down = function () {
};
exports.cycle_stream = function (direction) {
var currentStream, nextStream;
var currentStream;
var nextStream;
if (narrow.stream() !== undefined) {
currentStream = stream_list.get_stream_li(narrow.stream());
}

View File

@ -240,7 +240,11 @@ exports.notify_above_composebox = function (note, link_class, link_msg_id, link_
};
function process_notification(notification) {
var i, notification_object, key, content, other_recipients;
var i;
var notification_object;
var key;
var content;
var other_recipients;
var message = notification.message;
var title = message.sender_full_name;
var msg_count = 1;
@ -557,7 +561,8 @@ $(function () {
}
$(document).on('message_id_changed', function (event) {
var old_id = event.old_id, new_id = event.new_id;
var old_id = event.old_id;
var new_id = event.new_id;
// If a message ID that we're currently storing (as a link) has changed,
// update that link as well

View File

@ -225,7 +225,8 @@ 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, compose_started_handler;
var compose_done_handler;
var compose_started_handler;
function reload_from_idle () {
do_reload_app(false,

View File

@ -155,7 +155,11 @@ $(function () {
//
// This gets called on every message, so cache the results.
exports.get_color_class = _.memoize(function (color) {
var match, i, lightness, channel = [0, 0, 0], mult = 1;
var match;
var i;
var lightness;
var channel = [0, 0, 0];
var mult = 1;
match = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/.exec(color);
if (!match) {

View File

@ -19,7 +19,8 @@ function get_color() {
}
function selectText(element) {
var range, sel;
var range;
var sel;
if (window.getSelection) {
sel = window.getSelection();
range = document.createRange();
@ -97,7 +98,8 @@ function update_in_home_view(sub, value) {
sub.in_home_view = value;
setTimeout(function () {
var msg_offset, saved_ypos;
var msg_offset;
var saved_ypos;
// Save our current scroll position
if (ui.home_tab_obscured()) {
saved_ypos = viewport.scrollTop();
@ -622,7 +624,8 @@ function ajaxUnsubscribe(stream) {
url: "/json/subscriptions/remove",
data: {"subscriptions": JSON.stringify([stream]) },
success: function (resp, statusText, xhr, form) {
var name, res = JSON.parse(xhr.responseText);
var name;
var res = JSON.parse(xhr.responseText);
$("#subscriptions-status").hide();
// The rest of the work is done via the unsubscribe event we will get
},

View File

@ -35,7 +35,8 @@ function make_tab_data() {
}
if (narrow.active() && narrow.operators().length > 0) {
var stream, ops = narrow.operators();
var stream;
var ops = narrow.operators();
var hash = hashchange.operators_to_hash(ops);
// Second breadcrumb item
var hashed = hashchange.operators_to_hash(ops.slice(0, 1));

View File

@ -295,8 +295,8 @@ exports.lightbox = function (data) {
exports.lightbox_photo = function (image, user) {
// image should be an Image Object in JavaScript.
var url = $(image).attr("src"),
title = $(image).parent().attr("title");
var url = $(image).attr("src");
var title = $(image).parent().attr("title");
$("#overlay .player-container").hide();
$("#overlay .image-actions, .image-description, .download").show();

View File

@ -19,7 +19,10 @@ exports.random_int = function random_int(min, max) {
// Usage: lower_bound(array, value, [less])
// lower_bound(array, first, last, value, [less])
exports.lower_bound = function (array, arg1, arg2, arg3, arg4) {
var first, last, value, less;
var first;
var last;
var value;
var less;
if (arg3 === undefined) {
first = 0;
last = array.length;