eslint: Add and enable `space-unary-ops` rule.

Info about rule at https://eslint.org/docs/rules/space-unary-ops.
This commit is contained in:
Shubham Dhama 2018-06-05 00:39:11 +05:30
parent ea6a1750f5
commit c6738889a9
28 changed files with 58 additions and 57 deletions

View File

@ -331,6 +331,7 @@
// Updated regex expressions are currently being tested in casper
// files and will decide about a potential future enforcement of this rule.
"no-useless-escape": 0,
"space-unary-ops": 2,
"no-whitespace-before-property": 2,
"no-with": 2,
"one-var": [ "error", "never" ],

View File

@ -566,8 +566,8 @@ run_test('send_message', () => {
stub_state.send_msg_called += 1;
};
echo.reify_message_id = function (local_id, message_id) {
assert.equal(typeof(local_id), 'number');
assert.equal(typeof(message_id), 'number');
assert.equal(typeof (local_id), 'number');
assert.equal(typeof (message_id), 'number');
stub_state.reify_message_id_checked += 1;
};
@ -779,11 +779,11 @@ function verify_filedrop_payload(payload) {
assert.equal(payload.maxfilesize, 512);
assert.equal(payload.data.csrfmiddlewaretoken, 'fake-csrf-token');
assert.deepEqual(payload.raw_droppable, ['text/uri-list', 'text/plain']);
assert.equal(typeof(payload.drop), 'function');
assert.equal(typeof(payload.progressUpdated), 'function');
assert.equal(typeof(payload.error), 'function');
assert.equal(typeof(payload.uploadFinished), 'function');
assert.equal(typeof(payload.rawDrop), 'function');
assert.equal(typeof (payload.drop), 'function');
assert.equal(typeof (payload.progressUpdated), 'function');
assert.equal(typeof (payload.error), 'function');
assert.equal(typeof (payload.uploadFinished), 'function');
assert.equal(typeof (payload.rawDrop), 'function');
}
function test_raw_file_drop(raw_drop_func) {

View File

@ -100,7 +100,7 @@ run_test('pills', () => {
get_by_email_called = false;
var res = handler(iago.email, pills.items());
assert(get_by_email_called);
assert.equal(typeof(res), 'object');
assert.equal(typeof (res), 'object');
assert.equal(res.user_id, iago.user_id);
assert.equal(res.display_value, iago.full_name);
}());

View File

@ -78,8 +78,8 @@ run_test('basics', () => {
filter = new Filter(operators);
assert(filter.is_search());
assert(! filter.can_apply_locally());
assert(! filter.is_exactly('stream'));
assert(!filter.can_apply_locally());
assert(!filter.is_exactly('stream'));
// If our only stream operator is negated, then for all intents and purposes,
// we don't consider ourselves to have a stream operator, because we don't

View File

@ -18,7 +18,7 @@ run_test('settings', () => {
settings_muting.set_up();
var click_handler = $('body').get_on_handler('click', '.settings-unmute-topic');
assert.equal(typeof(click_handler), 'function');
assert.equal(typeof (click_handler), 'function');
var event = {
stopImmediatePropagation: noop,

View File

@ -154,11 +154,11 @@ run_test('populate_user_groups', () => {
assert(config.fixed);
assert(config.dropup);
assert(config.stopAdvance);
assert.equal(typeof(config.source), 'function');
assert.equal(typeof(config.highlighter), 'function');
assert.equal(typeof(config.matcher), 'function');
assert.equal(typeof(config.sorter), 'function');
assert.equal(typeof(config.updater), 'function');
assert.equal(typeof (config.source), 'function');
assert.equal(typeof (config.highlighter), 'function');
assert.equal(typeof (config.matcher), 'function');
assert.equal(typeof (config.sorter), 'function');
assert.equal(typeof (config.updater), 'function');
(function test_highlighter() {
var fake_person = $.create('fake-person');
@ -210,10 +210,10 @@ run_test('populate_user_groups', () => {
saved_fade_out_called = true;
};
$(cancel_selector).css = function (data) {
if (typeof(data) === 'string') {
if (typeof (data) === 'string') {
assert.equal(data, 'display');
}
assert.equal(typeof(data), 'object');
assert.equal(typeof (data), 'object');
assert.equal(data.display, 'inline-block');
assert.equal(data.opacity, '0');
return $(cancel_selector);
@ -222,10 +222,10 @@ run_test('populate_user_groups', () => {
cancel_fade_to_called = true;
};
$(instructions_selector).css = function (data) {
if (typeof(data) === 'string') {
if (typeof (data) === 'string') {
assert.equal(data, 'display');
}
assert.equal(typeof(data), 'object');
assert.equal(typeof (data), 'object');
assert.equal(data.display, 'block');
assert.equal(data.opacity, '0');
return $(instructions_selector);
@ -258,7 +258,7 @@ run_test('populate_user_groups', () => {
'Expected user email to be of Alice or Iago here.');
};
pills.onPillCreate = function (handler) {
assert.equal(typeof(handler), 'function');
assert.equal(typeof (handler), 'function');
handler();
};
@ -273,7 +273,7 @@ run_test('populate_user_groups', () => {
get_by_email_called = false;
var res = handler(bob.email, pills.items());
assert(get_by_email_called);
assert.equal(typeof(res), 'object');
assert.equal(typeof (res), 'object');
assert.equal(res.user_id, bob.user_id);
assert.equal(res.display_value, bob.full_name);
}());
@ -298,9 +298,9 @@ run_test('populate_user_groups', () => {
test_create_item(create_item_handler);
// Tests for settings_user_groups.set_up workflow.
assert.equal(typeof($('.organization form.admin-user-group-form').get_on_handler("submit")), 'function');
assert.equal(typeof($('#user-groups').get_on_handler('click', '.delete')), 'function');
assert.equal(typeof($('#user-groups').get_on_handler('keypress', '.user-group h4 > span')), 'function');
assert.equal(typeof ($('.organization form.admin-user-group-form').get_on_handler("submit")), 'function');
assert.equal(typeof ($('#user-groups').get_on_handler('click', '.delete')), 'function');
assert.equal(typeof ($('#user-groups').get_on_handler('keypress', '.user-group h4 > span')), 'function');
});
run_test('with_external_user', () => {
@ -392,8 +392,8 @@ run_test('with_external_user', () => {
callback = one;
empty_fn = two;
pill_hover_called = true;
assert.equal(typeof(one), 'function');
assert.equal(typeof(two), 'function');
assert.equal(typeof (one), 'function');
assert.equal(typeof (two), 'function');
};
var exit_button = $.create('fake-pill-exit');
@ -716,10 +716,10 @@ run_test('on_events', () => {
cancel_fade_out_called = true;
};
$(saved_selector).css = function (data) {
if (typeof(data) === 'string') {
if (typeof (data) === 'string') {
assert.equal(data, 'display');
}
assert.equal(typeof(data), 'object');
assert.equal(typeof (data), 'object');
assert.equal(data.display, 'inline-block');
assert.equal(data.opacity, '0');
return $(saved_selector);

View File

@ -18,7 +18,7 @@ exports.make_event_store = (selector) => {
var child_on_functions = new Dict();
function generic_event(event_name, arg) {
if (typeof(arg) === 'function') {
if (typeof (arg) === 'function') {
on_functions.set(event_name, arg);
} else {
var handler = on_functions.get(event_name);
@ -94,8 +94,8 @@ exports.make_event_store = (selector) => {
event_name = arguments[0];
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.');
assert.equal(typeof (sel), 'string', 'String selectors expected here.');
assert.equal(typeof (handler), 'function', 'An handler function expected here.');
var child_on = child_on_functions.setdefault(sel, new Dict());
funcs = child_on.setdefault(event_name, []);
funcs.push(handler);

View File

@ -84,7 +84,7 @@ exports.initialize = function () {
if (prev_sender !== undefined) {
var first_group_msg = $(this).find('.message_row').first();
var message_sender = first_group_msg.find('.message_sender');
if (! message_sender.find('.inline_profile_picture').length) {
if (!message_sender.find('.inline_profile_picture').length) {
message_sender.replaceWith(prev_sender.clone());
}
}

View File

@ -310,7 +310,7 @@ exports.finish = function () {
return;
}
if (! compose.validate()) {
if (!compose.validate()) {
return false;
}

View File

@ -31,7 +31,7 @@ function hide_box() {
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) {
if (msg_type === 'stream' && opts.stream && !opts.subject) {
return 'subject';
} else if ((msg_type === 'stream' && opts.stream)
|| (msg_type === 'private' && opts.private_message_recipient)) {

View File

@ -22,11 +22,11 @@ exports.add_topic = function (uc_stream, uc_topic) {
var stream = uc_stream.toLowerCase();
var topic = uc_topic.toLowerCase();
if (! seen_topics.has(stream)) {
if (!seen_topics.has(stream)) {
seen_topics.set(stream, new Dict());
}
var topic_dict = seen_topics.get(stream);
if (! topic_dict.has(topic)) {
if (!topic_dict.has(topic)) {
topic_dict.set(topic, uc_topic);
}
};

View File

@ -41,7 +41,7 @@ Dict.from = function Dict_from(obj, opts) {
* passed to the Dict constructor.
*/
Dict.from_array = function Dict_from_array(xs, opts) {
if (! (xs instanceof Array)) {
if (!(xs instanceof Array)) {
throw new TypeError("Argument is not an array");
}

View File

@ -471,7 +471,7 @@ Filter.prototype = {
_build_predicate: function () {
var operators = this._operators;
if (! this.can_apply_locally()) {
if (!this.can_apply_locally()) {
return function () { return true; };
}

View File

@ -63,7 +63,7 @@ function get_messages_success(data, opts) {
// don't bother processing the newly arrived messages.
return;
}
if (! data) {
if (!data) {
// The server occasionally returns no data during a
// restart. Ignore those responses and try again
setTimeout(function () {

View File

@ -791,7 +791,7 @@ 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)
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())))) {

View File

@ -6,7 +6,7 @@ var actively_scrolling = false;
var loading_more_messages_indicator_showing = false;
exports.show_loading_older = function () {
if (! loading_more_messages_indicator_showing) {
if (!loading_more_messages_indicator_showing) {
loading.make_indicator($('#loading_more_messages_indicator'),
{abs_positioned: true});
loading_more_messages_indicator_showing = true;

View File

@ -177,7 +177,7 @@ exports.activate = function (raw_operators, opts) {
var msg_list = new message_list.MessageList({
data: msg_data,
table_name: 'zfilt',
collapse_messages: ! narrow_state.get_current_filter().is_search(),
collapse_messages: !narrow_state.get_current_filter().is_search(),
});
msg_list.start_time = start_time;

View File

@ -154,7 +154,7 @@ exports.rebuild_recent = function (active_conversation) {
exports.update_private_messages = function () {
exports._build_private_messages_list();
if (! narrow_state.active()) {
if (!narrow_state.active()) {
return;
}

View File

@ -55,7 +55,7 @@ var valid_table_names = {
};
exports.get_table = function (table_name) {
if (! valid_table_names.hasOwnProperty(table_name)) {
if (!valid_table_names.hasOwnProperty(table_name)) {
return $();
}

View File

@ -77,7 +77,7 @@ Socket.prototype = {
request.error = error;
this._save_request(request);
if (! this._can_send()) {
if (!this._can_send()) {
this._try_to_reconnect({reason: 'cant_send'});
return;
}

View File

@ -398,19 +398,19 @@ function change_stream_privacy(e) {
function stream_desktop_notifications_clicked(e) {
var sub = get_sub_for_target(e.target);
sub.desktop_notifications = ! sub.desktop_notifications;
sub.desktop_notifications = !sub.desktop_notifications;
exports.set_stream_property(sub, 'desktop_notifications', sub.desktop_notifications);
}
function stream_audible_notifications_clicked(e) {
var sub = get_sub_for_target(e.target);
sub.audible_notifications = ! sub.audible_notifications;
sub.audible_notifications = !sub.audible_notifications;
exports.set_stream_property(sub, 'audible_notifications', sub.audible_notifications);
}
function stream_push_notifications_clicked(e) {
var sub = get_sub_for_target(e.target);
sub.push_notifications = ! sub.push_notifications;
sub.push_notifications = !sub.push_notifications;
exports.set_stream_property(sub, 'push_notifications', sub.push_notifications);
}

View File

@ -305,7 +305,7 @@ exports.update_streams_sidebar = function () {
exports.build_stream_list();
exports.stream_cursor.redraw();
if (! narrow_state.active()) {
if (!narrow_state.active()) {
return;
}

View File

@ -43,7 +43,7 @@ exports.update_in_home_view = function (sub, value) {
pointer.recenter_pointer_on_display = true;
pointer.suppress_scroll_pointer_update = true;
if (! home_msg_list.empty()) {
if (!home_msg_list.empty()) {
message_util.do_unread_count_updates(home_msg_list.all_messages());
}
}, 0);

View File

@ -77,7 +77,7 @@ function update_spectrum(popover, update_func) {
var popover_root = popover.closest(".popover");
var current_top_px = parseFloat(popover_root.css('top').replace('px', ''));
var height_delta = - (after_height - initial_height) * 0.5;
var height_delta = -(after_height - initial_height) * 0.5;
popover_root.css('top', (current_top_px + height_delta) + "px");
}

View File

@ -107,7 +107,7 @@ exports.active_stream = function () {
};
exports.toggle_home = function (sub) {
stream_muting.update_in_home_view(sub, ! sub.in_home_view);
stream_muting.update_in_home_view(sub, !sub.in_home_view);
stream_edit.set_stream_property(sub, 'in_home_view', sub.in_home_view);
};
@ -829,7 +829,7 @@ exports.initialize = function () {
// A hack. Don't change the state of the checkbox if we
// clicked on the checkbox itself.
if (control[0] !== e.target) {
control.prop("checked", ! control.prop("checked"));
control.prop("checked", !control.prop("checked"));
}
});

View File

@ -64,7 +64,7 @@ function make_tab_data() {
if (filter.has_operator("pm-with")) {
var emails = filter.operands("pm-with")[0].split(',');
var names = _.map(emails, function (email) {
if (! people.get_by_email(email)) {
if (!people.get_by_email(email)) {
return email;
}
return people.get_by_email(email).full_name;

View File

@ -52,7 +52,7 @@ function update_message_in_all_views(message_id, callback) {
exports.show_error_for_unsupported_platform = function () {
// Check if the user is using old desktop app
if (typeof(bridge) !== 'undefined') {
if (typeof (bridge) !== 'undefined') {
// We don't internationalize this string because it is long,
// and few users will have both the old desktop app and an
// internationalized version of Zulip anyway.

View File

@ -87,7 +87,7 @@ exports.notify_server_message_read = function (message, options) {
// If we ever materially change the algorithm for this function, we
// may need to update notifications.received_messages as well.
exports.process_visible = function () {
if (! notifications.window_has_focus()) {
if (!notifications.window_has_focus()) {
return;
}