Skip to content

Commit

Permalink
lint: Replace 'return undefined;' with 'return;'.
Browse files Browse the repository at this point in the history
Also adds a custom rule to eslint. Since the recommended way of extending
eslint is to create plugins as standalone npm packages, the separate rule
is published as 'eslint-plugins-empty-returns'.

Fixes zulip#8669.
  • Loading branch information
aero31aero authored and showell committed Mar 13, 2018
1 parent 7ce139a commit b22e8dc
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
"common": false,
"panels": false
},
"plugins": [
"eslint-plugin-empty-returns"
],
"rules": {
"array-callback-return": "error",
"array-bracket-spacing": "error",
Expand All @@ -191,6 +194,7 @@
"complexity": [ 0, 4 ],
"curly": 2,
"dot-notation": [ "error", { "allowKeywords": true } ],
"empty-returns/main": "error",
"eol-last": [ "error", "always" ],
"eqeqeq": 2,
"func-style": [ "off", "expression" ],
Expand Down
4 changes: 2 additions & 2 deletions frontend_tests/node_tests/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ zrequire('util');
zrequire('people');

set_global('blueslip', {
error: function () { return undefined; },
error: function () { return; },
});
set_global('page_params', {});
set_global('md5', function (s) {
Expand Down Expand Up @@ -555,7 +555,7 @@ initialize();
assert.equal(email, 'debbie71@example.com');

// Test undefined slug
people.emails_strings_to_user_ids_string = function () { return undefined; };
people.emails_strings_to_user_ids_string = function () { return; };
assert.equal(people.emails_to_slug(), undefined);
}());

Expand Down
2 changes: 1 addition & 1 deletion frontend_tests/node_tests/people_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ people.initialize_current_user(me.user_id);
assert(reply_to.indexOf('?') > -1);

people.pm_with_user_ids = function () { return [42]; };
people.get_person_from_user_id = function () { return undefined; };
people.get_person_from_user_id = function () { return; };
global.blueslip.error = function (msg) {
assert.equal(msg, 'Unknown people in message');
};
Expand Down
10 changes: 5 additions & 5 deletions frontend_tests/node_tests/search_suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ topic_data.reset();
};

global.narrow_state.stream = function () {
return undefined;
return;
};

var suggestions = search.get_suggestions(query);
Expand All @@ -73,7 +73,7 @@ topic_data.reset();
};

global.narrow_state.stream = function () {
return undefined;
return;
};

var ted =
Expand Down Expand Up @@ -244,7 +244,7 @@ topic_data.reset();
};

global.narrow_state.stream = function () {
return undefined;
return;
};

set_global('activity', {
Expand Down Expand Up @@ -430,7 +430,7 @@ init();
};

global.narrow_state.stream = function () {
return undefined;
return;
};

var suggestions = search.get_suggestions(query);
Expand Down Expand Up @@ -466,7 +466,7 @@ init();
};

global.narrow_state.stream = function () {
return undefined;
return;
};

var query = '';
Expand Down
4 changes: 2 additions & 2 deletions frontend_tests/node_tests/topic_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function is_odd(i) { return i % 2 === 1; }
assert.equal(gen.next(), undefined);

var undef = function () {
return undefined;
return;
};

global.blueslip.error = function (msg) {
Expand Down Expand Up @@ -315,7 +315,7 @@ function is_odd(i) { return i % 2 === 1; }

unread.num_unread_for_person = function (user_ids_string) {
if (user_ids_string === 'unk') {
return undefined;
return;
}

if (user_ids_string === 'read') {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"cssstyle": "0.2.29",
"difflib": "0.2.4",
"eslint": "3.9.1",
"eslint-plugin-empty-returns": "1.0.2",
"htmlparser2": "3.8.3",
"istanbul": "0.4.5",
"jsdom": "9.4.1",
Expand Down
2 changes: 1 addition & 1 deletion static/js/blueslip.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Logger.prototype = (function () {
if (console[name] !== undefined) {
return console[name].apply(console, arguments);
}
return undefined;
return;
};
}

Expand Down
4 changes: 2 additions & 2 deletions static/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.autofocus = function (selector) {
exports.password_quality = function (password, bar, password_field) {
// We load zxcvbn.js asynchronously, so the variable might not be set.
if (typeof zxcvbn === 'undefined') {
return undefined;
return;
}

var min_length = password_field.data('minLength');
Expand Down Expand Up @@ -58,7 +58,7 @@ exports.password_quality = function (password, bar, password_field) {

exports.password_warning = function (password, password_field) {
if (typeof zxcvbn === 'undefined') {
return undefined;
return;
}

var min_length = password_field.data('minLength');
Expand Down
4 changes: 2 additions & 2 deletions static/js/compose_fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ exports.would_receive_message = function (email) {
if (!sub) {
// If the stream isn't valid, there is no risk of a mix
// yet, so don't fade.
return undefined;
return;
}

if (user && user.is_bot && !sub.invite_only) {
// Bots may receive messages on public streams even if they are
// not subscribed.
return undefined;
return;
}
return stream_data.user_is_subscribed(focused_recipient.stream, email);
}
Expand Down
4 changes: 2 additions & 2 deletions static/js/copy_and_paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function find_boundary_tr(initial_tr, iterate_row) {
// parent tr, we should let the browser handle the copy-paste
// entirely on its own
if (tr.length === 0) {
return undefined;
return;
}

// If the selection boundary is on a table row that does not have an
Expand All @@ -24,7 +24,7 @@ function find_boundary_tr(initial_tr, iterate_row) {
tr = iterate_row(tr);
}
if (j === 10) {
return undefined;
return;
} else if (j !== 0) {
// If we updated tr, then we are not dealing with a selection
// that is entirely within one td, and we can skip the same td
Expand Down
4 changes: 2 additions & 2 deletions static/js/dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Dict.prototype = {
_munge: function Dict__munge(k) {
if (k === undefined) {
blueslip.error("Tried to call a Dict method with an undefined key.");
return undefined;
return;
}
if (this._opts.fold_case) {
k = k.toLowerCase();
Expand All @@ -74,7 +74,7 @@ Dict.prototype = {
get: function Dict_get(key) {
var mapping = this._items[this._munge(key)];
if (mapping === undefined) {
return undefined;
return;
}
return mapping.v;
},
Expand Down
12 changes: 6 additions & 6 deletions static/js/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ var get_next_local_id = (function () {
// If our id is already used, it is probably an edge case like we had
// to abort a very recent message.
blueslip.warn("We don't reuse ids for local echo.");
return undefined;
return;
}

if (next_local_id % 1 > local_id_increment * 5) {
blueslip.warn("Turning off local echo for this message to let host catch up");
return undefined;
return;
}

if (next_local_id % 1 === 0) {
// The logic to stop at 0.05 should prevent us from ever wrapping around
// to the next integer.
blueslip.error("Programming error");
return undefined;
return;
}

already_used[next_local_id] = true;
Expand Down Expand Up @@ -139,18 +139,18 @@ function insert_local_message(message_request, local_id) {

exports.try_deliver_locally = function try_deliver_locally(message_request) {
if (markdown.contains_backend_only_syntax(message_request.content)) {
return undefined;
return;
}

if (narrow_state.active() && !narrow_state.filter().can_apply_locally()) {
return undefined;
return;
}

var next_local_id = get_next_local_id();

if (!next_local_id) {
// This can happen for legit reasons.
return undefined;
return;
}

return insert_local_message(message_request, next_local_id);
Expand Down
2 changes: 1 addition & 1 deletion static/js/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports.parse_narrow = function (hash) {
}
operators.push({negated: negated, operator: operator, operand: operand});
} catch (err) {
return undefined;
return;
}
}
return operators;
Expand Down
2 changes: 1 addition & 1 deletion static/js/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var ls = {
try {
return JSON.parse(str);
} catch (err) {
return undefined;
return;
}
},

Expand Down
6 changes: 3 additions & 3 deletions static/js/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports.apply_markdown = function (message) {
'@' + name +
'</span>';
}
return undefined;
return;
},
groupMentionHandler: function (name) {
var group = user_groups.get_user_group_from_name(name);
Expand All @@ -75,7 +75,7 @@ exports.apply_markdown = function (message) {
'@' + group.name +
'</span>';
}
return undefined;
return;
},
};
message.content = marked(message.raw_content + '\n\n', options).trim();
Expand Down Expand Up @@ -165,7 +165,7 @@ function handleAvatar(email) {
function handleStream(streamName) {
var stream = stream_data.get_sub(streamName);
if (stream === undefined) {
return undefined;
return;
}
var href = window.location.origin + '/#narrow/stream/' + hash_util.encode_stream_name(stream.name);
return '<a class="stream" data-stream-id="' + stream.stream_id + '" ' +
Expand Down
2 changes: 1 addition & 1 deletion static/js/message_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ exports.MessageList.prototype = {
get: function MessageList_get(id) {
id = parseFloat(id);
if (isNaN(id)) {
return undefined;
return;
}
return this._hash[id];
},
Expand Down
10 changes: 5 additions & 5 deletions static/js/narrow_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.update_email = function (user_id, new_email) {
/* Operators we should send to the server. */
exports.public_operators = function () {
if (current_filter === undefined) {
return undefined;
return;
}
return current_filter.public_operators();
};
Expand Down Expand Up @@ -96,7 +96,7 @@ exports.set_compose_defaults = function () {

exports.stream = function () {
if (current_filter === undefined) {
return undefined;
return;
}
var stream_operands = current_filter.operands("stream");
if (stream_operands.length === 1) {
Expand All @@ -106,18 +106,18 @@ exports.stream = function () {
// name (considering renames and capitalization).
return stream_data.get_name(name);
}
return undefined;
return;
};

exports.topic = function () {
if (current_filter === undefined) {
return undefined;
return;
}
var operands = current_filter.operands("topic");
if (operands.length === 1) {
return operands[0];
}
return undefined;
return;
};

exports.pm_string = function () {
Expand Down
12 changes: 6 additions & 6 deletions static/js/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.init();
exports.get_person_from_user_id = function (user_id) {
if (!people_by_user_id_dict.has(user_id)) {
blueslip.error('Unknown user_id in get_person_from_user_id: ' + user_id);
return undefined;
return;
}
return people_by_user_id_dict.get(user_id);
};
Expand All @@ -44,7 +44,7 @@ exports.get_by_email = function (email) {
var person = people_dict.get(email);

if (!person) {
return undefined;
return;
}

if (person.email.toLowerCase() !== email.toLowerCase()) {
Expand Down Expand Up @@ -91,12 +91,12 @@ exports.get_user_id = function (email) {
if (person === undefined) {
var error_msg = 'Unknown email for get_user_id: ' + email;
blueslip.error(error_msg);
return undefined;
return;
}
var user_id = person.user_id;
if (!user_id) {
blueslip.error('No user_id found for ' + email);
return undefined;
return;
}

return user_id;
Expand Down Expand Up @@ -555,7 +555,7 @@ exports.is_valid_email_for_compose = function (email) {
exports.get_active_user_for_email = function (email) {
var person = people.get_by_email(email);
if (!person) {
return undefined;
return;
}
return active_user_dict.get(person.user_id);
};
Expand Down Expand Up @@ -596,7 +596,7 @@ exports.get_active_user_ids = function () {
exports.is_cross_realm_email = function (email) {
var person = people.get_by_email(email);
if (!person) {
return undefined;
return;
}
return cross_realm_dict.has(person.user_id);
};
Expand Down
Loading

0 comments on commit b22e8dc

Please sign in to comment.