Enable the no-else-return ESLint rule

Using `else` after `return` is not necessary, and can often lead to unnecessarily cluttered code. By using the `no-else-return` rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.
This commit is contained in:
Jonas Jenwald 2016-12-16 13:05:33 +01:00
parent 049d7fa277
commit 4046d67fde
19 changed files with 67 additions and 79 deletions

View File

@ -45,6 +45,7 @@
"curly": ["error", "all"],
"eqeqeq": ["error", "always"],
"no-caller": "error",
"no-else-return": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",

View File

@ -143,9 +143,8 @@ chrome.webRequest.onHeadersReceived.addListener(
url: viewerUrl
});
return { cancel: true };
} else {
console.warn('Child frames are not supported in ancient Chrome builds!');
}
console.warn('Child frames are not supported in ancient Chrome builds!');
},
{
urls: [

View File

@ -348,10 +348,9 @@ var CFFParser = (function CFFParserClosure() {
return ((value - 247) * 256) + dict[pos++] + 108;
} else if (value >= 251 && value <= 254) {
return -((value - 251) * 256) - dict[pos++] - 108;
} else {
warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
return NaN;
}
warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
return NaN;
}
function parseFloatOperand() {
@ -1363,9 +1362,8 @@ var CFFCompiler = (function CFFCompilerClosure() {
encodeNumber: function CFFCompiler_encodeNumber(value) {
if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
return this.encodeInteger(value);
} else {
return this.encodeFloat(value);
}
return this.encodeFloat(value);
},
encodeFloat: function CFFCompiler_encodeFloat(num) {
var value = num.toString();

View File

@ -1216,11 +1216,13 @@ var LabCS = (function LabCSClosure() {
// Function g(x) from spec
function fn_g(x) {
var result;
if (x >= 6 / 29) {
return x * x * x;
result = x * x * x;
} else {
return (108 / 841) * (x - 4 / 29);
result = (108 / 841) * (x - 4 / 29);
}
return result;
}
function decode(value, high1, low2, high2) {

View File

@ -823,9 +823,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
this.handler);
operatorList.addOp(fn, pattern.getIR());
return Promise.resolve();
} else {
return Promise.reject('Unknown PatternType: ' + typeNum);
}
return Promise.reject('Unknown PatternType: ' + typeNum);
}
// TODO shall we fail here?
operatorList.addOp(fn, args);
@ -2902,18 +2901,17 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
operation.fn = fn;
operation.args = args;
return true;
} else {
if (isEOF(obj)) {
return false; // no more commands
}
// argument
if (obj !== null) {
if (args === null) {
args = [];
}
args.push(obj);
assert(args.length <= 33, 'Too many arguments');
}
if (isEOF(obj)) {
return false; // no more commands
}
// argument
if (obj !== null) {
if (args === null) {
args = [];
}
args.push(obj);
assert(args.length <= 33, 'Too many arguments');
}
}
},

View File

@ -729,9 +729,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
[1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
return new TrueTypeCompiled(
parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
} else {
return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
}
return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
}
};
})();

View File

@ -53,9 +53,8 @@ var PDFImage = (function PDFImageClosure() {
function handleImageData(image, nativeDecoder) {
if (nativeDecoder && nativeDecoder.canDecode(image)) {
return nativeDecoder.decode(image);
} else {
return Promise.resolve(image);
}
return Promise.resolve(image);
}
/**

View File

@ -918,15 +918,15 @@ var JpegImage = (function JpegImageClosure() {
return false;
}
return true;
} else { // `this.numComponents !== 3`
if (!this.adobe && this.colorTransform === 1) {
// If the Adobe transform marker is not present and the image
// dictionary has a 'ColorTransform' entry, explicitly set to `1`,
// then the colours should be transformed.
return true;
}
return false;
}
// `this.numComponents !== 3`
if (!this.adobe && this.colorTransform === 1) {
// If the Adobe transform marker is not present and the image
// dictionary has a 'ColorTransform' entry, explicitly set to `1`,
// then the colours should be transformed.
return true;
}
return false;
},
_convertYccToRgb: function convertYccToRgb(data) {
@ -1072,9 +1072,8 @@ var JpegImage = (function JpegImageClosure() {
if (this._isColorConversionNeeded()) {
if (forceRGBoutput) {
return this._convertYcckToRgb(data);
} else {
return this._convertYcckToCmyk(data);
}
return this._convertYcckToCmyk(data);
} else if (forceRGBoutput) {
return this._convertCmykToRgb(data);
}

View File

@ -1585,9 +1585,8 @@ var FileSpec = (function FileSpecClosure() {
return dict.get('Mac');
} else if (dict.has('DOS')) {
return dict.get('DOS');
} else {
return null;
}
return null;
}
FileSpec.prototype = {

View File

@ -81,9 +81,8 @@ AnnotationElementFactory.prototype =
return new RadioButtonWidgetAnnotationElement(parameters);
} else if (parameters.data.checkBox) {
return new CheckboxWidgetAnnotationElement(parameters);
} else {
warn('Unimplemented button widget annotation: pushbutton');
}
warn('Unimplemented button widget annotation: pushbutton');
break;
case 'Ch':
return new ChoiceWidgetAnnotationElement(parameters);

View File

@ -1945,9 +1945,8 @@ var PDFObjects = (function PDFObjectsClosure() {
if (!objs[objId]) {
return false;
} else {
return objs[objId].resolved;
}
return objs[objId].resolved;
},
hasData: function PDFObjects_hasData(objId) {
@ -1961,9 +1960,8 @@ var PDFObjects = (function PDFObjectsClosure() {
var objs = this.objs;
if (!objs[objId] || !objs[objId].resolved) {
return null;
} else {
return objs[objId].data;
}
return objs[objId].data;
},
clear: function PDFObjects_clear() {

View File

@ -376,7 +376,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
this.options.fontRegistry.registerFont(this);
}
return nativeFontFace;
} else {
} else { // eslint-disable-line no-else-return
throw new Error('Not implemented: createNativeFontFace');
}
},

View File

@ -202,9 +202,8 @@ if (typeof PDFJS === 'undefined') {
get: function xmlHttpRequestResponseGet() {
if (this.responseType === 'arraybuffer') {
return new Uint8Array(new VBArray(this.responseBody).toArray());
} else {
return this.responseText;
}
return this.responseText;
}
});
return;

View File

@ -178,12 +178,11 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
size_kb: (+kb.toPrecision(3)).toLocaleString(),
size_b: fileSize.toLocaleString()
}, '{{size_kb}} KB ({{size_b}} bytes)');
} else {
return mozL10n.get('document_properties_mb', {
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
size_b: fileSize.toLocaleString()
}, '{{size_mb}} MB ({{size_b}} bytes)');
}
return mozL10n.get('document_properties_mb', {
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
size_b: fileSize.toLocaleString()
}, '{{size_mb}} MB ({{size_b}} bytes)');
},
/**

View File

@ -399,22 +399,21 @@ var PDFFindController = (function PDFFindControllerClosure() {
offset.matchIdx = (previous ? numMatches - 1 : 0);
this.updateMatch(true);
return true;
} else {
// No matches, so attempt to search the next page.
this.advanceOffsetPage(previous);
if (offset.wrapped) {
offset.matchIdx = null;
if (this.pagesToSearch < 0) {
// No point in wrapping again, there were no matches.
this.updateMatch(false);
// while matches were not found, searching for a page
// with matches should nevertheless halt.
return true;
}
}
// Matches were not found (and searching is not done).
return false;
}
// No matches, so attempt to search the next page.
this.advanceOffsetPage(previous);
if (offset.wrapped) {
offset.matchIdx = null;
if (this.pagesToSearch < 0) {
// No point in wrapping again, there were no matches.
this.updateMatch(false);
// while matches were not found, searching for a page
// with matches should nevertheless halt.
return true;
}
}
// Matches were not found (and searching is not done).
return false;
},
/**

View File

@ -284,9 +284,8 @@
this.nextHashParam = null;
this.updatePreviousBookmark = true;
return;
} else {
this.nextHashParam = null;
}
this.nextHashParam = null;
}
if (params.hash) {

View File

@ -624,7 +624,7 @@ var PDFPageView = (function PDFPageViewClosure() {
onRenderContinue: function (cont) { },
cancel: function () { },
};
} else {
} else { // eslint-disable-line no-else-return
var cancelled = false;
var ensureNotCancelled = function () {
if (cancelled) {

View File

@ -833,14 +833,13 @@ var PDFViewer = (function pdfViewer() {
_getVisiblePages: function () {
if (!this.isInPresentationMode) {
return getVisibleElements(this.container, this._pages, true);
} else {
// The algorithm in getVisibleElements doesn't work in all browsers and
// configurations when presentation mode is active.
var visible = [];
var currentPage = this._pages[this._currentPageNumber - 1];
visible.push({ id: currentPage.id, view: currentPage });
return { first: currentPage, last: currentPage, views: visible };
}
// The algorithm in getVisibleElements doesn't work in all browsers and
// configurations when presentation mode is active.
var visible = [];
var currentPage = this._pages[this._currentPageNumber - 1];
visible.push({ id: currentPage.id, view: currentPage });
return { first: currentPage, last: currentPage, views: visible };
},
cleanup: function () {

View File

@ -280,12 +280,14 @@ function approximateFraction(x) {
a = p; b = q;
}
}
var result;
// Select closest of the neighbours to x.
if (x_ - a / b < c / d - x_) {
return x_ === x ? [a, b] : [b, a];
result = x_ === x ? [a, b] : [b, a];
} else {
return x_ === x ? [c, d] : [d, c];
result = x_ === x ? [c, d] : [d, c];
}
return result;
}
function roundToDivide(x, div) {