Enable the no-lonely-if ESLint rule

These changes were mostly done automatically, using `gulp lint --fix`, and only a few spots with comments needed manual tweaking; please see https://eslint.org/docs/latest/rules/no-lonely-if
This commit is contained in:
Jonas Jenwald 2023-07-20 10:57:30 +02:00
parent abb24f82fb
commit c018070e80
15 changed files with 108 additions and 147 deletions

View File

@ -139,6 +139,7 @@
"no-implied-eval": "error", "no-implied-eval": "error",
"no-iterator": "error", "no-iterator": "error",
"no-lone-blocks": "error", "no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multi-str": "error", "no-multi-str": "error",
"no-new-func": "error", "no-new-func": "error",
"no-new-wrappers": "error", "no-new-wrappers": "error",

View File

@ -198,8 +198,7 @@ function preprocess(inFilename, outFilename, defines) {
} }
break; break;
} }
} else { } else if (state === STATE_NONE) {
if (state === STATE_NONE) {
writeLine(line); writeLine(line);
} else if ( } else if (
(state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) && (state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) &&
@ -214,7 +213,6 @@ function preprocess(inFilename, outFilename, defines) {
); );
} }
} }
}
if (state !== STATE_NONE || stack.length !== 0) { if (state !== STATE_NONE || stack.length !== 0) {
throw new Error( throw new Error(
"Missing #endif in preprocessor for " + fs.realpathSync(inFilename) "Missing #endif in preprocessor for " + fs.realpathSync(inFilename)

View File

@ -100,11 +100,9 @@ function downloadLanguageFiles(root, langCode) {
resolve(); resolve();
} }
}); });
} else { } else if (--downloadsLeft === 0) {
if (--downloadsLeft === 0) {
resolve(); resolve();
} }
}
}); });
}); });
}); });

View File

@ -2698,8 +2698,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
lastSpacePosInStringEnd = end; lastSpacePosInStringEnd = end;
lastSpacePos = i; lastSpacePos = i;
} }
} else { } else if (currentWidth + glyphWidth > width) {
if (currentWidth + glyphWidth > width) {
// We must break to the last white position (if available) // We must break to the last white position (if available)
if (lastSpacePosInStringStart !== -1) { if (lastSpacePosInStringStart !== -1) {
chunks.push(line.substring(startChunk, lastSpacePosInStringEnd)); chunks.push(line.substring(startChunk, lastSpacePosInStringEnd));
@ -2717,7 +2716,6 @@ class TextWidgetAnnotation extends WidgetAnnotation {
currentWidth += glyphWidth; currentWidth += glyphWidth;
} }
} }
}
if (startChunk < line.length) { if (startChunk < line.length) {
chunks.push(line.substring(startChunk, line.length)); chunks.push(line.substring(startChunk, line.length));

View File

@ -353,13 +353,10 @@ function bidi(str, startLevel = -1, vertical = false) {
} else if (t === "AN" || t === "EN") { } else if (t === "AN" || t === "EN") {
levels[i] += 2; levels[i] += 2;
} }
} else { } else if (/* isOdd && */ t === "L" || t === "AN" || t === "EN") {
// isOdd
if (t === "L" || t === "AN" || t === "EN") {
levels[i] += 1; levels[i] += 1;
} }
} }
}
/* /*
L1. On each line, reset the embedding level of the following characters to L1. On each line, reset the embedding level of the following characters to

View File

@ -207,7 +207,7 @@ class ChunkedStream extends Stream {
if (start + length > this.progressiveDataLength) { if (start + length > this.progressiveDataLength) {
this.ensureRange(start, start + length); this.ensureRange(start, start + length);
} }
} else { } else if (start >= this.progressiveDataLength) {
// When the `length` is undefined you do *not*, under any circumstances, // When the `length` is undefined you do *not*, under any circumstances,
// want to fallback on calling `this.ensureRange(start, this.end)` since // want to fallback on calling `this.ensureRange(start, this.end)` since
// that would force the *entire* PDF file to be loaded, thus completely // that would force the *entire* PDF file to be loaded, thus completely
@ -217,10 +217,8 @@ class ChunkedStream extends Stream {
// time/resources during e.g. parsing, since `MissingDataException`s will // time/resources during e.g. parsing, since `MissingDataException`s will
// require data to be re-parsed, which we attempt to minimize by at least // require data to be re-parsed, which we attempt to minimize by at least
// checking that the *beginning* of the data is available here. // checking that the *beginning* of the data is available here.
if (start >= this.progressiveDataLength) {
this.ensureByte(start); this.ensureByte(start);
} }
}
function ChunkedStreamSubstream() {} function ChunkedStreamSubstream() {}
ChunkedStreamSubstream.prototype = Object.create(this); ChunkedStreamSubstream.prototype = Object.create(this);

View File

@ -206,23 +206,13 @@ class ColorSpace {
rgbBuf[rgbPos++] = colorMap[key + 2]; rgbBuf[rgbPos++] = colorMap[key + 2];
} }
} }
} else { } else if (!needsResizing) {
if (!needsResizing) {
// Fill in the RGB values directly into |dest|. // Fill in the RGB values directly into |dest|.
this.getRgbBuffer( this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
comps,
0,
width * actualHeight,
dest,
0,
bpc,
alpha01
);
} else { } else {
rgbBuf = new Uint8ClampedArray(count * 3); rgbBuf = new Uint8ClampedArray(count * 3);
this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */ 0); this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */ 0);
} }
}
if (rgbBuf) { if (rgbBuf) {
if (needsResizing) { if (needsResizing) {

View File

@ -211,15 +211,13 @@ function compileGlyf(code, cmds, font) {
arg2 = getUint16(code, i + 2); arg2 = getUint16(code, i + 2);
} }
i += 4; i += 4;
} else { } else if (flags & 0x02) {
if (flags & 0x02) {
arg1 = getInt8(code, i++); arg1 = getInt8(code, i++);
arg2 = getInt8(code, i++); arg2 = getInt8(code, i++);
} else { } else {
arg1 = code[i++]; arg1 = code[i++];
arg2 = code[i++]; arg2 = code[i++];
} }
}
if (flags & 0x02) { if (flags & 0x02) {
x = arg1; x = arg1;
y = arg2; y = arg2;

View File

@ -619,8 +619,7 @@ class CompositeGlyph {
) { ) {
size += 2; size += 2;
} }
} else { } else if (
if (
!( !(
this.argument1 >= 0 && this.argument1 >= 0 &&
this.argument1 <= 255 && this.argument1 <= 255 &&
@ -630,7 +629,6 @@ class CompositeGlyph {
) { ) {
size += 2; size += 2;
} }
}
return size; return size;
} }
@ -650,8 +648,7 @@ class CompositeGlyph {
) { ) {
this.flags |= ARG_1_AND_2_ARE_WORDS; this.flags |= ARG_1_AND_2_ARE_WORDS;
} }
} else { } else if (
if (
!( !(
this.argument1 >= 0 && this.argument1 >= 0 &&
this.argument1 <= 255 && this.argument1 <= 255 &&
@ -661,7 +658,6 @@ class CompositeGlyph {
) { ) {
this.flags |= ARG_1_AND_2_ARE_WORDS; this.flags |= ARG_1_AND_2_ARE_WORDS;
} }
}
buf.setUint16(pos, this.flags); buf.setUint16(pos, this.flags);
buf.setUint16(pos + 2, this.glyphIndex); buf.setUint16(pos + 2, this.glyphIndex);

View File

@ -3662,13 +3662,11 @@ class Line extends XFAObject {
} else if (parent.h <= thickness) { } else if (parent.h <= thickness) {
[x1, y1, x2, y2] = [0, "50%", "100%", "50%"]; [x1, y1, x2, y2] = [0, "50%", "100%", "50%"];
height = style.strokeWidth; height = style.strokeWidth;
} else { } else if (this.slope === "\\") {
if (this.slope === "\\") {
[x1, y1, x2, y2] = [0, 0, "100%", "100%"]; [x1, y1, x2, y2] = [0, 0, "100%", "100%"];
} else { } else {
[x1, y1, x2, y2] = [0, "100%", "100%", 0]; [x1, y1, x2, y2] = [0, "100%", "100%", 0];
} }
}
const line = { const line = {
name: "line", name: "line",

View File

@ -432,11 +432,9 @@ function pm(m) {
const a = (Math.acos(m[0]) * 180) / Math.PI; const a = (Math.acos(m[0]) * 180) / Math.PI;
return `rotate(${pf(a)})`; return `rotate(${pf(a)})`;
} }
} else { } else if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
return `translate(${pf(m[4])} ${pf(m[5])})`; return `translate(${pf(m[4])} ${pf(m[5])})`;
} }
}
return ( return (
`matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` +
`${pf(m[5])})` `${pf(m[5])})`

View File

@ -127,13 +127,11 @@ class Field extends PDFObject {
indices.forEach(i => { indices.forEach(i => {
this._value.push(this._items[i].displayValue); this._value.push(this._items[i].displayValue);
}); });
} else { } else if (indices.length > 0) {
if (indices.length > 0) {
indices = indices.splice(1, indices.length - 1); indices = indices.splice(1, indices.length - 1);
this._currentValueIndices = indices[0]; this._currentValueIndices = indices[0];
this._value = this._items[this._currentValueIndices]; this._value = this._items[this._currentValueIndices];
} }
}
this._send({ id: this._id, indices }); this._send({ id: this._id, indices });
} }
@ -389,13 +387,11 @@ class Field extends PDFObject {
--this._currentValueIndices[index]; --this._currentValueIndices[index];
} }
} }
} else { } else if (this._currentValueIndices === nIdx) {
if (this._currentValueIndices === nIdx) {
this._currentValueIndices = this.numItems > 0 ? 0 : -1; this._currentValueIndices = this.numItems > 0 ? 0 : -1;
} else if (this._currentValueIndices > nIdx) { } else if (this._currentValueIndices > nIdx) {
--this._currentValueIndices; --this._currentValueIndices;
} }
}
this._send({ id: this._id, remove: nIdx }); this._send({ id: this._id, remove: nIdx });
} }

View File

@ -623,12 +623,11 @@ class PDFFindController {
if (newQuery !== prevQuery) { if (newQuery !== prevQuery) {
return true; return true;
} }
} else { } else if (
// Array /* isArray && */ JSON.stringify(newQuery) !== JSON.stringify(prevQuery)
if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) { ) {
return true; return true;
} }
}
switch (state.type) { switch (state.type) {
case "again": case "again":

View File

@ -378,8 +378,7 @@ class PDFLinkService {
zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
zoomArgNumber ? zoomArgNumber / 100 : zoomArg, zoomArgNumber ? zoomArgNumber / 100 : zoomArg,
]; ];
} else { } else if (zoomArg === "Fit" || zoomArg === "FitB") {
if (zoomArg === "Fit" || zoomArg === "FitB") {
dest = [null, { name: zoomArg }]; dest = [null, { name: zoomArg }];
} else if ( } else if (
zoomArg === "FitH" || zoomArg === "FitH" ||
@ -413,7 +412,6 @@ class PDFLinkService {
); );
} }
} }
}
if (dest) { if (dest) {
this.pdfViewer.scrollPageIntoView({ this.pdfViewer.scrollPageIntoView({
pageNumber: pageNumber || this.page, pageNumber: pageNumber || this.page,

View File

@ -128,11 +128,9 @@ class BasePreferences {
`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.` `Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`
); );
} }
} else { } else if (valueType === "number" && !Number.isInteger(value)) {
if (valueType === "number" && !Number.isInteger(value)) {
throw new Error(`Set preference: "${value}" must be an integer.`); throw new Error(`Set preference: "${value}" must be an integer.`);
} }
}
this.#prefs[name] = value; this.#prefs[name] = value;
return this._writeToStorage(this.#prefs).catch(reason => { return this._writeToStorage(this.#prefs).catch(reason => {