Commit 745f145f authored by Robert Knight's avatar Robert Knight Committed by Nick Stenning

Enable consistent return lint rule (#30)

Enforce that all paths through a function either return a value
or do not return a value.

This cause several cases of spurious returns left in by CoffeeScript ->
JS conversion and return statements with missing values.
parent d3414b62
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"rules": { "rules": {
"array-callback-return": "error", "array-callback-return": "error",
"block-scoped-var": "error", "block-scoped-var": "error",
"consistent-return": "error",
"curly": "error", "curly": "error",
"dot-notation": "error", "dot-notation": "error",
"eqeqeq": "error", "eqeqeq": "error",
......
...@@ -127,7 +127,7 @@ module.exports = function AppController( ...@@ -127,7 +127,7 @@ module.exports = function AppController(
}); });
drafts.discard(); drafts.discard();
$scope.accountDialog.visible = false; $scope.accountDialog.visible = false;
return auth.logout(); auth.logout();
}; };
$scope.clearSelection = function () { $scope.clearSelection = function () {
......
...@@ -90,7 +90,7 @@ function excerpt(ExcerptOverflowMonitor) { ...@@ -90,7 +90,7 @@ function excerpt(ExcerptOverflowMonitor) {
contentHeight: function () { contentHeight: function () {
var contentElem = elem[0].querySelector('.excerpt'); var contentElem = elem[0].querySelector('.excerpt');
if (!contentElem) { if (!contentElem) {
return; return null;
} }
return contentElem.scrollHeight; return contentElem.scrollHeight;
}, },
......
...@@ -113,8 +113,8 @@ module.exports = function($sanitize) { ...@@ -113,8 +113,8 @@ module.exports = function($sanitize) {
// Keyboard shortcuts for bold, italic, and link. // Keyboard shortcuts for bold, italic, and link.
elem.on('keydown', function(e) { elem.on('keydown', function(e) {
var shortcuts = var shortcuts = {
{66: scope.insertBold, 66: scope.insertBold,
73: scope.insertItalic, 73: scope.insertItalic,
75: scope.insertLink 75: scope.insertLink
}; };
...@@ -122,7 +122,7 @@ module.exports = function($sanitize) { ...@@ -122,7 +122,7 @@ module.exports = function($sanitize) {
var shortcut = shortcuts[e.keyCode]; var shortcut = shortcuts[e.keyCode];
if (shortcut && (e.ctrlKey || e.metaKey)) { if (shortcut && (e.ctrlKey || e.metaKey)) {
e.preventDefault(); e.preventDefault();
return shortcut(); shortcut();
} }
}); });
......
...@@ -62,6 +62,7 @@ function DraftStore() { ...@@ -62,6 +62,7 @@ function DraftStore() {
}; };
} }
} }
return null;
}; };
/** /**
......
...@@ -35,6 +35,7 @@ function groups(localStorage, session, settings, $rootScope, $http) { ...@@ -35,6 +35,7 @@ function groups(localStorage, session, settings, $rootScope, $http) {
return gs[i]; return gs[i];
} }
} }
return null;
} }
/** Leave the group with the given ID. /** Leave the group with the given ID.
......
...@@ -36,53 +36,57 @@ var embedGenerators = [ ...@@ -36,53 +36,57 @@ var embedGenerators = [
// Matches URLs like https://www.youtube.com/watch?v=rw6oWkCojpw // Matches URLs like https://www.youtube.com/watch?v=rw6oWkCojpw
function iframeFromYouTubeWatchURL(link) { function iframeFromYouTubeWatchURL(link) {
if (link.hostname !== 'www.youtube.com') { if (link.hostname !== 'www.youtube.com') {
return; return null;
} }
if (!/\/watch\/?/.test(link.pathname)) { if (!/\/watch\/?/.test(link.pathname)) {
return; return null;
} }
var groups = /[&\?]v=([^&#]+)/.exec(link.search); var groups = /[&\?]v=([^&#]+)/.exec(link.search);
if (groups) { if (groups) {
return youTubeEmbed(groups[1]); return youTubeEmbed(groups[1]);
} }
return null;
}, },
// Matches URLs like https://youtu.be/rw6oWkCojpw // Matches URLs like https://youtu.be/rw6oWkCojpw
function iframeFromYouTubeShareURL(link) { function iframeFromYouTubeShareURL(link) {
if (link.hostname !== 'youtu.be') { if (link.hostname !== 'youtu.be') {
return; return null;
} }
var groups = /^\/([^\/]+)\/?$/.exec(link.pathname); var groups = /^\/([^\/]+)\/?$/.exec(link.pathname);
if (groups) { if (groups) {
return youTubeEmbed(groups[1]); return youTubeEmbed(groups[1]);
} }
return null;
}, },
// Matches URLs like https://vimeo.com/149000090 // Matches URLs like https://vimeo.com/149000090
function iFrameFromVimeoLink(link) { function iFrameFromVimeoLink(link) {
if (link.hostname !== 'vimeo.com') { if (link.hostname !== 'vimeo.com') {
return; return null;
} }
var groups = /^\/([^\/\?#]+)\/?$/.exec(link.pathname); var groups = /^\/([^\/\?#]+)\/?$/.exec(link.pathname);
if (groups) { if (groups) {
return vimeoEmbed(groups[1]); return vimeoEmbed(groups[1]);
} }
return null;
}, },
// Matches URLs like https://vimeo.com/channels/staffpicks/148845534 // Matches URLs like https://vimeo.com/channels/staffpicks/148845534
function iFrameFromVimeoChannelLink(link) { function iFrameFromVimeoChannelLink(link) {
if (link.hostname !== 'vimeo.com') { if (link.hostname !== 'vimeo.com') {
return; return null;
} }
var groups = /^\/channels\/[^\/]+\/([^\/?#]+)\/?$/.exec(link.pathname); var groups = /^\/channels\/[^\/]+\/([^\/?#]+)\/?$/.exec(link.pathname);
if (groups) { if (groups) {
return vimeoEmbed(groups[1]); return vimeoEmbed(groups[1]);
} }
return null;
}, },
]; ];
...@@ -104,6 +108,7 @@ function embedForLink(link) { ...@@ -104,6 +108,7 @@ function embedForLink(link) {
return embed; return embed;
} }
} }
return null;
} }
/** Replace the given link element with an embed. /** Replace the given link element with an embed.
......
...@@ -65,6 +65,8 @@ function RootThread($rootScope, annotationUI, features, searchFilter, viewFilter ...@@ -65,6 +65,8 @@ function RootThread($rootScope, annotationUI, features, searchFilter, viewFilter
return thread.annotation && metadata.isAnnotation(thread.annotation); return thread.annotation && metadata.isAnnotation(thread.annotation);
} else if (state.selectedTab === uiConstants.TAB_NOTES) { } else if (state.selectedTab === uiConstants.TAB_NOTES) {
return thread.annotation && metadata.isPageNote(thread.annotation); return thread.annotation && metadata.isPageNote(thread.annotation);
} else {
throw new Error('Invalid selected tab');
} }
}; };
} }
......
...@@ -156,7 +156,7 @@ function session($http, $resource, $rootScope, flash, raven, settings) { ...@@ -156,7 +156,7 @@ function session($http, $resource, $rootScope, flash, raven, settings) {
function process(data, headersGetter, status) { function process(data, headersGetter, status) {
if (status < 200 || status >= 500) { if (status < 200 || status >= 500) {
return; return null;
} }
data = angular.fromJson(data); data = angular.fromJson(data);
......
...@@ -85,10 +85,10 @@ describe('groups', function() { ...@@ -85,10 +85,10 @@ describe('groups', function() {
assert.equal(group.id, 'id2'); assert.equal(group.id, 'id2');
}); });
it("returns undefined if the group doesn't exist", function() { it("returns null if the group doesn't exist", function() {
var group = service().get('foobar'); var group = service().get('foobar');
assert.isUndefined(group); assert.isNull(group);
}); });
}); });
......
...@@ -144,6 +144,8 @@ function getBreakpoint(date, now) { ...@@ -144,6 +144,8 @@ function getBreakpoint(date, now) {
return breakpoint; return breakpoint;
} }
} }
return null;
} }
function nextFuzzyUpdate(date) { function nextFuzzyUpdate(date) {
......
...@@ -27,7 +27,7 @@ function groupIDFromSelection(selection, results) { ...@@ -27,7 +27,7 @@ function groupIDFromSelection(selection, results) {
return annot.id === id; return annot.id === id;
}); });
if (!annot) { if (!annot) {
return; return null;
} }
return annot.group; return annot.group;
} }
...@@ -67,7 +67,7 @@ module.exports = function WidgetController( ...@@ -67,7 +67,7 @@ module.exports = function WidgetController(
function getThreadHeight(id) { function getThreadHeight(id) {
var threadElement = document.getElementById(id); var threadElement = document.getElementById(id);
if (!threadElement) { if (!threadElement) {
return; return null;
} }
// Get the height of the element inside the border-box, excluding // Get the height of the element inside the border-box, excluding
...@@ -155,11 +155,13 @@ module.exports = function WidgetController( ...@@ -155,11 +155,13 @@ module.exports = function WidgetController(
if (!annot) { if (!annot) {
return null; return null;
} }
if (metadata.isAnnotation(annot)) { if (metadata.isAnnotation(annot)) {
return uiConstants.TAB_ANNOTATIONS; return uiConstants.TAB_ANNOTATIONS;
} } else if (metadata.isPageNote(annot)) {
if (metadata.isPageNote(annot)) {
return uiConstants.TAB_NOTES; return uiConstants.TAB_NOTES;
} else {
return null;
} }
} }
...@@ -322,7 +324,7 @@ module.exports = function WidgetController( ...@@ -322,7 +324,7 @@ module.exports = function WidgetController(
} }
annotationUI.clearSelectedAnnotations(); annotationUI.clearSelectedAnnotations();
return loadAnnotations(crossframe.frames); loadAnnotations(crossframe.frames);
}); });
// Watch anything that may require us to reload annotations. // Watch anything that may require us to reload annotations.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment