diff --git a/.eslintrc b/.eslintrc index bec3bdcde..7a8b33b75 100644 --- a/.eslintrc +++ b/.eslintrc @@ -139,6 +139,7 @@ "no-implied-eval": "error", "no-iterator": "error", "no-lone-blocks": "error", + "no-lonely-if": "error", "no-multi-str": "error", "no-new-func": "error", "no-new-wrappers": "error", diff --git a/external/builder/builder.mjs b/external/builder/builder.mjs index c1305f46d..5f6c0551c 100644 --- a/external/builder/builder.mjs +++ b/external/builder/builder.mjs @@ -198,21 +198,19 @@ function preprocess(inFilename, outFilename, defines) { } break; } - } else { - if (state === STATE_NONE) { - writeLine(line); - } else if ( - (state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) && - !stack.includes(STATE_IF_FALSE) && - !stack.includes(STATE_ELSE_FALSE) - ) { - writeLine( - line - .replaceAll(/^\/\/|^$/g, "") - ); - } + } else if (state === STATE_NONE) { + writeLine(line); + } else if ( + (state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) && + !stack.includes(STATE_IF_FALSE) && + !stack.includes(STATE_ELSE_FALSE) + ) { + writeLine( + line + .replaceAll(/^\/\/|^$/g, "") + ); } } if (state !== STATE_NONE || stack.length !== 0) { diff --git a/external/importL10n/locales.mjs b/external/importL10n/locales.mjs index 04d818f88..6014df179 100644 --- a/external/importL10n/locales.mjs +++ b/external/importL10n/locales.mjs @@ -100,10 +100,8 @@ function downloadLanguageFiles(root, langCode) { resolve(); } }); - } else { - if (--downloadsLeft === 0) { - resolve(); - } + } else if (--downloadsLeft === 0) { + resolve(); } }); }); diff --git a/src/core/annotation.js b/src/core/annotation.js index 81a8d3d25..4c9e5ba10 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -2698,24 +2698,22 @@ class TextWidgetAnnotation extends WidgetAnnotation { lastSpacePosInStringEnd = end; lastSpacePos = i; } - } else { - if (currentWidth + glyphWidth > width) { - // We must break to the last white position (if available) - if (lastSpacePosInStringStart !== -1) { - chunks.push(line.substring(startChunk, lastSpacePosInStringEnd)); - startChunk = lastSpacePosInStringEnd; - i = lastSpacePos + 1; - lastSpacePosInStringStart = -1; - currentWidth = 0; - } else { - // Just break in the middle of the word - chunks.push(line.substring(startChunk, start)); - startChunk = start; - currentWidth = glyphWidth; - } + } else if (currentWidth + glyphWidth > width) { + // We must break to the last white position (if available) + if (lastSpacePosInStringStart !== -1) { + chunks.push(line.substring(startChunk, lastSpacePosInStringEnd)); + startChunk = lastSpacePosInStringEnd; + i = lastSpacePos + 1; + lastSpacePosInStringStart = -1; + currentWidth = 0; } else { - currentWidth += glyphWidth; + // Just break in the middle of the word + chunks.push(line.substring(startChunk, start)); + startChunk = start; + currentWidth = glyphWidth; } + } else { + currentWidth += glyphWidth; } } diff --git a/src/core/bidi.js b/src/core/bidi.js index 2596748e0..d8e7fd7b5 100644 --- a/src/core/bidi.js +++ b/src/core/bidi.js @@ -353,11 +353,8 @@ function bidi(str, startLevel = -1, vertical = false) { } else if (t === "AN" || t === "EN") { levels[i] += 2; } - } else { - // isOdd - if (t === "L" || t === "AN" || t === "EN") { - levels[i] += 1; - } + } else if (/* isOdd && */ t === "L" || t === "AN" || t === "EN") { + levels[i] += 1; } } diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 19c7f1b77..014b50bbc 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -207,7 +207,7 @@ class ChunkedStream extends Stream { if (start + length > this.progressiveDataLength) { this.ensureRange(start, start + length); } - } else { + } else if (start >= this.progressiveDataLength) { // When the `length` is undefined you do *not*, under any circumstances, // want to fallback on calling `this.ensureRange(start, this.end)` since // that would force the *entire* PDF file to be loaded, thus completely @@ -217,9 +217,7 @@ class ChunkedStream extends Stream { // time/resources during e.g. parsing, since `MissingDataException`s will // require data to be re-parsed, which we attempt to minimize by at least // checking that the *beginning* of the data is available here. - if (start >= this.progressiveDataLength) { - this.ensureByte(start); - } + this.ensureByte(start); } function ChunkedStreamSubstream() {} diff --git a/src/core/colorspace.js b/src/core/colorspace.js index f1140e9dd..9326d56e6 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -206,22 +206,12 @@ class ColorSpace { rgbBuf[rgbPos++] = colorMap[key + 2]; } } + } else if (!needsResizing) { + // Fill in the RGB values directly into |dest|. + this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01); } else { - if (!needsResizing) { - // Fill in the RGB values directly into |dest|. - this.getRgbBuffer( - comps, - 0, - width * actualHeight, - dest, - 0, - bpc, - alpha01 - ); - } else { - rgbBuf = new Uint8ClampedArray(count * 3); - this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */ 0); - } + rgbBuf = new Uint8ClampedArray(count * 3); + this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */ 0); } if (rgbBuf) { diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index c0e9cc317..7b5253639 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -211,14 +211,12 @@ function compileGlyf(code, cmds, font) { arg2 = getUint16(code, i + 2); } i += 4; + } else if (flags & 0x02) { + arg1 = getInt8(code, i++); + arg2 = getInt8(code, i++); } else { - if (flags & 0x02) { - arg1 = getInt8(code, i++); - arg2 = getInt8(code, i++); - } else { - arg1 = code[i++]; - arg2 = code[i++]; - } + arg1 = code[i++]; + arg2 = code[i++]; } if (flags & 0x02) { x = arg1; diff --git a/src/core/glyf.js b/src/core/glyf.js index 29ed0d7ed..d5ddb3306 100644 --- a/src/core/glyf.js +++ b/src/core/glyf.js @@ -619,17 +619,15 @@ class CompositeGlyph { ) { size += 2; } - } else { - if ( - !( - this.argument1 >= 0 && - this.argument1 <= 255 && - this.argument2 >= 0 && - this.argument2 <= 255 - ) - ) { - size += 2; - } + } else if ( + !( + this.argument1 >= 0 && + this.argument1 <= 255 && + this.argument2 >= 0 && + this.argument2 <= 255 + ) + ) { + size += 2; } return size; @@ -650,17 +648,15 @@ class CompositeGlyph { ) { this.flags |= ARG_1_AND_2_ARE_WORDS; } - } else { - if ( - !( - this.argument1 >= 0 && - this.argument1 <= 255 && - this.argument2 >= 0 && - this.argument2 <= 255 - ) - ) { - this.flags |= ARG_1_AND_2_ARE_WORDS; - } + } else if ( + !( + this.argument1 >= 0 && + this.argument1 <= 255 && + this.argument2 >= 0 && + this.argument2 <= 255 + ) + ) { + this.flags |= ARG_1_AND_2_ARE_WORDS; } buf.setUint16(pos, this.flags); diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index d48e7118e..ebaadddb9 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -3662,12 +3662,10 @@ class Line extends XFAObject { } else if (parent.h <= thickness) { [x1, y1, x2, y2] = [0, "50%", "100%", "50%"]; height = style.strokeWidth; + } else if (this.slope === "\\") { + [x1, y1, x2, y2] = [0, 0, "100%", "100%"]; } else { - if (this.slope === "\\") { - [x1, y1, x2, y2] = [0, 0, "100%", "100%"]; - } else { - [x1, y1, x2, y2] = [0, "100%", "100%", 0]; - } + [x1, y1, x2, y2] = [0, "100%", "100%", 0]; } const line = { diff --git a/src/display/svg.js b/src/display/svg.js index d0dfc0162..61ff4e155 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -432,10 +432,8 @@ function pm(m) { const a = (Math.acos(m[0]) * 180) / Math.PI; return `rotate(${pf(a)})`; } - } else { - if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) { - return `translate(${pf(m[4])} ${pf(m[5])})`; - } + } else if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) { + return `translate(${pf(m[4])} ${pf(m[5])})`; } return ( `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + diff --git a/src/scripting_api/field.js b/src/scripting_api/field.js index 19b71c731..5a692c999 100644 --- a/src/scripting_api/field.js +++ b/src/scripting_api/field.js @@ -127,12 +127,10 @@ class Field extends PDFObject { indices.forEach(i => { this._value.push(this._items[i].displayValue); }); - } else { - if (indices.length > 0) { - indices = indices.splice(1, indices.length - 1); - this._currentValueIndices = indices[0]; - this._value = this._items[this._currentValueIndices]; - } + } else if (indices.length > 0) { + indices = indices.splice(1, indices.length - 1); + this._currentValueIndices = indices[0]; + this._value = this._items[this._currentValueIndices]; } this._send({ id: this._id, indices }); } @@ -389,12 +387,10 @@ class Field extends PDFObject { --this._currentValueIndices[index]; } } - } else { - if (this._currentValueIndices === nIdx) { - this._currentValueIndices = this.numItems > 0 ? 0 : -1; - } else if (this._currentValueIndices > nIdx) { - --this._currentValueIndices; - } + } else if (this._currentValueIndices === nIdx) { + this._currentValueIndices = this.numItems > 0 ? 0 : -1; + } else if (this._currentValueIndices > nIdx) { + --this._currentValueIndices; } this._send({ id: this._id, remove: nIdx }); diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 201e71612..93d860110 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -623,11 +623,10 @@ class PDFFindController { if (newQuery !== prevQuery) { return true; } - } else { - // Array - if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) { - return true; - } + } else if ( + /* isArray && */ JSON.stringify(newQuery) !== JSON.stringify(prevQuery) + ) { + return true; } switch (state.type) { diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 5ec69ff9c..f022d99f2 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -378,40 +378,38 @@ class PDFLinkService { zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg, ]; - } else { - if (zoomArg === "Fit" || zoomArg === "FitB") { - dest = [null, { name: zoomArg }]; - } else if ( - zoomArg === "FitH" || - zoomArg === "FitBH" || - zoomArg === "FitV" || - zoomArg === "FitBV" - ) { + } else if (zoomArg === "Fit" || zoomArg === "FitB") { + dest = [null, { name: zoomArg }]; + } else if ( + zoomArg === "FitH" || + zoomArg === "FitBH" || + zoomArg === "FitV" || + zoomArg === "FitBV" + ) { + dest = [ + null, + { name: zoomArg }, + zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, + ]; + } else if (zoomArg === "FitR") { + if (zoomArgs.length !== 5) { + console.error( + 'PDFLinkService.setHash: Not enough parameters for "FitR".' + ); + } else { dest = [ null, { name: zoomArg }, - zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, + zoomArgs[1] | 0, + zoomArgs[2] | 0, + zoomArgs[3] | 0, + zoomArgs[4] | 0, ]; - } else if (zoomArg === "FitR") { - if (zoomArgs.length !== 5) { - console.error( - 'PDFLinkService.setHash: Not enough parameters for "FitR".' - ); - } else { - dest = [ - null, - { name: zoomArg }, - zoomArgs[1] | 0, - zoomArgs[2] | 0, - zoomArgs[3] | 0, - zoomArgs[4] | 0, - ]; - } - } else { - console.error( - `PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.` - ); } + } else { + console.error( + `PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.` + ); } } if (dest) { diff --git a/web/preferences.js b/web/preferences.js index dead99e98..136baf343 100644 --- a/web/preferences.js +++ b/web/preferences.js @@ -128,10 +128,8 @@ class BasePreferences { `Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.` ); } - } else { - if (valueType === "number" && !Number.isInteger(value)) { - throw new Error(`Set preference: "${value}" must be an integer.`); - } + } else if (valueType === "number" && !Number.isInteger(value)) { + throw new Error(`Set preference: "${value}" must be an integer.`); } this.#prefs[name] = value;