diff --git a/.eslintrc.json b/.eslintrc.json index 7c680d3822..db7c93bd78 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -172,6 +172,9 @@ "common": false, "panels": false }, + "plugins": [ + "eslint-plugin-empty-returns" + ], "rules": { "array-callback-return": "error", "array-bracket-spacing": "error", @@ -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" ], diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index f7a1552f9d..4e62c45a3a 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -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) { @@ -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); }()); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 3eb3a5d0d6..c3906c9d79 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -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'); }; diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 437a86ea71..382e294298 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -53,7 +53,7 @@ topic_data.reset(); }; global.narrow_state.stream = function () { - return undefined; + return; }; var suggestions = search.get_suggestions(query); @@ -73,7 +73,7 @@ topic_data.reset(); }; global.narrow_state.stream = function () { - return undefined; + return; }; var ted = @@ -244,7 +244,7 @@ topic_data.reset(); }; global.narrow_state.stream = function () { - return undefined; + return; }; set_global('activity', { @@ -430,7 +430,7 @@ init(); }; global.narrow_state.stream = function () { - return undefined; + return; }; var suggestions = search.get_suggestions(query); @@ -466,7 +466,7 @@ init(); }; global.narrow_state.stream = function () { - return undefined; + return; }; var query = ''; diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js index 70c6b8023f..61f182d870 100644 --- a/frontend_tests/node_tests/topic_generator.js +++ b/frontend_tests/node_tests/topic_generator.js @@ -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) { @@ -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') { diff --git a/package.json b/package.json index 69db08b0d5..2c8a4f0f33 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/static/js/blueslip.js b/static/js/blueslip.js index 65c2c0cc6d..aa597cee54 100644 --- a/static/js/blueslip.js +++ b/static/js/blueslip.js @@ -71,7 +71,7 @@ Logger.prototype = (function () { if (console[name] !== undefined) { return console[name].apply(console, arguments); } - return undefined; + return; }; } diff --git a/static/js/common.js b/static/js/common.js index 12390dde98..d145583bb9 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -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'); @@ -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'); diff --git a/static/js/compose_fade.js b/static/js/compose_fade.js index ea307c5982..4b916097cc 100644 --- a/static/js/compose_fade.js +++ b/static/js/compose_fade.js @@ -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); } diff --git a/static/js/copy_and_paste.js b/static/js/copy_and_paste.js index 69cadb2614..99f3eb1f41 100644 --- a/static/js/copy_and_paste.js +++ b/static/js/copy_and_paste.js @@ -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 @@ -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 diff --git a/static/js/dict.js b/static/js/dict.js index f8b5577f02..b7485f853b 100644 --- a/static/js/dict.js +++ b/static/js/dict.js @@ -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(); @@ -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; }, diff --git a/static/js/echo.js b/static/js/echo.js index d1285b89c5..a6bde1f55b 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -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; @@ -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); diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 9d2d29b70f..917565455e 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -85,7 +85,7 @@ exports.parse_narrow = function (hash) { } operators.push({negated: negated, operator: operator, operand: operand}); } catch (err) { - return undefined; + return; } } return operators; diff --git a/static/js/localstorage.js b/static/js/localstorage.js index c68d7aa1ef..1bea82f21b 100644 --- a/static/js/localstorage.js +++ b/static/js/localstorage.js @@ -6,7 +6,7 @@ var ls = { try { return JSON.parse(str); } catch (err) { - return undefined; + return; } }, diff --git a/static/js/markdown.js b/static/js/markdown.js index c436e73ba6..c171e54eca 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -63,7 +63,7 @@ exports.apply_markdown = function (message) { '@' + name + ''; } - return undefined; + return; }, groupMentionHandler: function (name) { var group = user_groups.get_user_group_from_name(name); @@ -75,7 +75,7 @@ exports.apply_markdown = function (message) { '@' + group.name + ''; } - return undefined; + return; }, }; message.content = marked(message.raw_content + '\n\n', options).trim(); @@ -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 '