Skip to content

Commit

Permalink
Enable the consistent-return ESLint rule
Browse files Browse the repository at this point in the history
This rule is already enabled in mozilla-central, and helps ensure more consistent functions/methods, see https://searchfox.org/mozilla-central/rev/b9da45f63cb567244933c77b2c7e827a057d3f9b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#119-120

Please see https://eslint.org/docs/rules/consistent-return for additional information.
  • Loading branch information
Snuffleupagus committed May 10, 2019
1 parent ca2fee3 commit 721c5cc
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 54 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

// Best Practices
"accessor-pairs": ["error", { "setWithoutGet": true, }],
"consistent-return": "error",
"curly": ["error", "all"],
"eqeqeq": ["error", "always"],
"no-caller": "error",
Expand Down
4 changes: 3 additions & 1 deletion extensions/chromium/extension-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ limitations under the License.
// Find the (url-encoded) colon and verify that the scheme is whitelisted.
var schemeIndex = url.search(/:|%3A/i);
if (schemeIndex === -1) {
return;
return undefined;
}
var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.includes(scheme)) {
Expand All @@ -53,6 +53,7 @@ limitations under the License.
}
return url;
}
return undefined;
}

// TODO(rob): Use declarativeWebRequest once declared URL-encoding is
Expand All @@ -72,6 +73,7 @@ limitations under the License.
console.log('Redirecting ' + details.url + ' to ' + url);
return { redirectUrl: url, };
}
return undefined;
}, {
types: ['main_frame', 'sub_frame'],
urls: schemes.map(function(scheme) {
Expand Down
16 changes: 10 additions & 6 deletions extensions/chromium/pdfHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getHeaderFromHeaders(headers, headerName) {
return header;
}
}
return undefined;
}

/**
Expand Down Expand Up @@ -86,6 +87,7 @@ function isPdfFile(details) {
}
}
}
return false;
}

/**
Expand All @@ -108,16 +110,17 @@ function getHeadersWithContentDispositionAttachment(details) {
cdHeader.value = 'attachment' + cdHeader.value.replace(/^[^;]+/i, '');
return { responseHeaders: headers, };
}
return undefined;
}

chrome.webRequest.onHeadersReceived.addListener(
function(details) {
if (details.method !== 'GET') {
// Don't intercept POST requests until http://crbug.com/104058 is fixed.
return;
return undefined;
}
if (!isPdfFile(details)) {
return;
return undefined;
}
if (isPdfDownloadable(details)) {
// Force download by ensuring that Content-Disposition: attachment is set
Expand All @@ -142,7 +145,7 @@ chrome.webRequest.onHeadersReceived.addListener(
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (isPdfDownloadable(details)) {
return;
return undefined;
}

var viewerUrl = getViewerURL(details.url);
Expand Down Expand Up @@ -200,7 +203,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
// sensitive (local) file in a frame.
if (!sender.tab) {
sendResponse('');
return;
return undefined;
}
// TODO: This should be the URL of the parent frame, not the tab. But
// chrome-extension:-URLs are not visible in the webNavigation API
Expand All @@ -209,11 +212,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
var parentUrl = sender.tab.url;
if (!parentUrl) {
sendResponse('');
return;
return undefined;
}
if (parentUrl.lastIndexOf('file:', 0) === 0) {
sendResponse('file://');
return;
return undefined;
}
// The regexp should always match for valid URLs, but in case it doesn't,
// just give the full URL (e.g. data URLs).
Expand All @@ -240,6 +243,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
});
}
}
return undefined;
});

// Remove keys from storage that were once part of the deleted feature-detect.js
Expand Down
6 changes: 3 additions & 3 deletions extensions/chromium/preserve-referer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {

function onBeforeSendHeaders(details) {
if (details.frameId !== frameId) {
return;
return undefined;
}
var headers = details.requestHeaders;
var refererHeader = getHeaderFromHeaders(headers, 'referer');
Expand All @@ -141,15 +141,15 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
refererHeader.value.lastIndexOf('chrome-extension:', 0) !== 0) {
// Sanity check. If the referer is set, and the value is not the URL of
// this extension, then the request was not initiated by this extension.
return;
return undefined;
}
refererHeader.value = referer;
return { requestHeaders: headers, };
}

function exposeOnHeadersReceived(details) {
if (details.frameId !== frameId) {
return;
return undefined;
}
var headers = details.responseHeaders;
var aceh = getHeaderFromHeaders(headers, 'access-control-expose-headers');
Expand Down
8 changes: 5 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function getTempFile(prefix, suffix) {

function createTestSource(testsName, bot) {
var source = stream.Readable({ objectMode: true, });
source._read = function () {
source._read = function() {
console.log();
console.log('### Running ' + testsName + ' tests');

Expand Down Expand Up @@ -409,6 +409,7 @@ function createTestSource(testsName, bot) {
testProcess.on('close', function (code) {
source.push(null);
});
return undefined;
};
return source;
}
Expand Down Expand Up @@ -1245,9 +1246,10 @@ gulp.task('gh-pages-prepare', function () {
gulp.task('wintersmith', function (done) {
var wintersmith = require('wintersmith');
var env = wintersmith('docs/config.json');
env.build(GH_PAGES_DIR, function (error) {
env.build(GH_PAGES_DIR, function(error) {
if (error) {
return done(error);
done(error);
return;
}
replaceInFile(GH_PAGES_DIR + '/getting_started/index.html',
/STABLE_VERSION/g, config.stableVersion);
Expand Down
4 changes: 2 additions & 2 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AnnotationFactory {
static _create(xref, ref, pdfManager, idFactory) {
let dict = xref.fetchIfRef(ref);
if (!isDict(dict)) {
return;
return undefined;
}
let id = isRef(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;

Expand Down Expand Up @@ -432,7 +432,7 @@ class Annotation {
loadResources(keys) {
return this.appearance.dict.getAsync('Resources').then((resources) => {
if (!resources) {
return;
return undefined;
}
let objectLoader = new ObjectLoader(resources, keys, resources.xref);

Expand Down
11 changes: 7 additions & 4 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {

if (!(w && isNum(w)) || !(h && isNum(h))) {
warn('Image dimensions are missing, or not numbers.');
return;
return undefined;
}
var maxImageSize = this.options.maxImageSize;
if (maxImageSize !== -1 && w * h > maxImageSize) {
warn('Image exceeded maximum allowed size and was removed.');
return;
return undefined;
}

var imageMask = (dict.get('ImageMask', 'IM') || false);
Expand Down Expand Up @@ -343,7 +343,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args,
};
}
return;
return undefined;
}

var softMask = (dict.get('SMask', 'SM') || false);
Expand All @@ -364,7 +364,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// any other kind.
imgData = imageObj.createImageData(/* forceRGBA = */ true);
operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
return;
return undefined;
}

const nativeImageDecoderSupport = forceDisableNativeImageDecoder ?
Expand Down Expand Up @@ -452,6 +452,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
this.handler.send('obj', [objId, this.pageIndex, 'Image', imgData],
[imgData.data.buffer]);
return undefined;
}).catch((reason) => {
warn('Unable to decode image: ' + reason);

Expand All @@ -460,6 +461,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
[objId, 'FontType3Res', null]);
}
this.handler.send('obj', [objId, this.pageIndex, 'Image', null]);
return undefined;
});

if (this.parsingType3Font) {
Expand All @@ -476,6 +478,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args,
};
}
return undefined;
},

handleSMask: function PartialEvaluator_handleSmask(smask, resources,
Expand Down
1 change: 1 addition & 0 deletions src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ var JpegImage = (function JpegImageClosure() {
});
}
this.numComponents = this.components.length;
return undefined;
},

_getLinearizedBlockData(width, height, isSourcePDF = false) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class Catalog {
} else if (this.catDict.has('Dests')) { // Simple destination dictionary.
return this.catDict.get('Dests');
}
return undefined;
}

get pageLabels() {
Expand Down Expand Up @@ -1596,7 +1597,7 @@ var XRef = (function XRefClosure() {
}

if (recoveryMode) {
return;
return undefined;
}
throw new XRefParseException();
},
Expand Down
8 changes: 6 additions & 2 deletions src/core/operator_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3:
return fnArray[i] === OPS.restore;
}
throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`);
},
function foundInlineImageGroup(context, i) {
var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
Expand Down Expand Up @@ -173,6 +174,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3:
return fnArray[i] === OPS.restore;
}
throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`);
},
function foundImageMaskGroup(context, i) {
var MIN_IMAGES_IN_MASKS_BLOCK = 10;
Expand Down Expand Up @@ -266,7 +268,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return argsArray[iFirstTransform][1] === 0 &&
argsArray[iFirstTransform][2] === 0;
},
function (context, i) {
function iterateImageGroup(context, i) {
var fnArray = context.fnArray, argsArray = context.argsArray;
var iFirstSave = context.iCurr - 3;
var pos = (i - iFirstSave) % 4;
Expand Down Expand Up @@ -300,6 +302,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3:
return fnArray[i] === OPS.restore;
}
throw new Error(`iterateImageGroup - invalid pos: ${pos}`);
},
function (context, i) {
var MIN_IMAGES_IN_BLOCK = 3;
Expand Down Expand Up @@ -346,7 +349,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
addState(InitialState,
[OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
null,
function (context, i) {
function iterateShowTextGroup(context, i) {
var fnArray = context.fnArray, argsArray = context.argsArray;
var iFirstSave = context.iCurr - 4;
var pos = (i - iFirstSave) % 5;
Expand All @@ -372,6 +375,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 4:
return fnArray[i] === OPS.endText;
}
throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`);
},
function (context, i) {
var MIN_CHARS_IN_BLOCK = 3;
Expand Down
6 changes: 4 additions & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2021,13 +2021,14 @@ class WorkerTransport {

messageHandler.on('obj', function(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
// Ignore any pending requests if the worker was terminated.
return undefined;
}

const [id, pageIndex, type, imageData] = data;
const pageProxy = this.pageCache[pageIndex];
if (pageProxy.objs.has(id)) {
return;
return undefined;
}

switch (type) {
Expand Down Expand Up @@ -2064,6 +2065,7 @@ class WorkerTransport {
default:
throw new Error(`Got unknown object type ${type}`);
}
return undefined;
}, this);

messageHandler.on('DocProgress', function(data) {
Expand Down
2 changes: 1 addition & 1 deletion src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {

var fontSize = current.fontSize;
if (fontSize === 0) {
return;
return undefined;
}

var ctx = this.ctx;
Expand Down
7 changes: 4 additions & 3 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BaseFontLoader {
async bind(font) {
// Add the font to the DOM only once; skip if the font is already loaded.
if (font.attached || font.missingFile) {
return;
return undefined;
}
font.attached = true;

Expand All @@ -83,7 +83,7 @@ class BaseFontLoader {
throw ex;
}
}
return; // The font was, asynchronously, loaded.
return undefined; // The font was, asynchronously, loaded.
}

// !this.isFontLoadingAPISupported
Expand All @@ -92,13 +92,14 @@ class BaseFontLoader {
this.insertRule(rule);

if (this.isSyncFontLoadingSupported) {
return; // The font was, synchronously, loaded.
return undefined; // The font was, synchronously, loaded.
}
return new Promise((resolve) => {
const request = this._queueLoadingCallback(resolve);
this._prepareFontLoadEvent([rule], [font], request);
});
}
return undefined;
}

_queueLoadingCallback(callback) {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

async function resolveCall(fn, args, thisArg = null) {
if (!fn) {
return;
return undefined;
}
return fn.apply(thisArg, args);
}
Expand Down
Loading

0 comments on commit 721c5cc

Please sign in to comment.