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-iterator": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",

View File

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

View File

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

View File

@ -2698,8 +2698,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
lastSpacePosInStringEnd = end;
lastSpacePos = i;
}
} else {
if (currentWidth + glyphWidth > width) {
} else if (currentWidth + glyphWidth > width) {
// We must break to the last white position (if available)
if (lastSpacePosInStringStart !== -1) {
chunks.push(line.substring(startChunk, lastSpacePosInStringEnd));
@ -2717,7 +2716,6 @@ class TextWidgetAnnotation extends WidgetAnnotation {
currentWidth += glyphWidth;
}
}
}
if (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") {
levels[i] += 2;
}
} else {
// isOdd
if (t === "L" || t === "AN" || t === "EN") {
} else if (/* isOdd && */ t === "L" || t === "AN" || t === "EN") {
levels[i] += 1;
}
}
}
/*
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) {
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,10 +217,8 @@ 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);
}
}
function ChunkedStreamSubstream() {}
ChunkedStreamSubstream.prototype = Object.create(this);

View File

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

View File

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

View File

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

View File

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

View File

@ -432,11 +432,9 @@ 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) {
} 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])} ` +
`${pf(m[5])})`

View File

@ -127,13 +127,11 @@ class Field extends PDFObject {
indices.forEach(i => {
this._value.push(this._items[i].displayValue);
});
} else {
if (indices.length > 0) {
} 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,13 +387,11 @@ class Field extends PDFObject {
--this._currentValueIndices[index];
}
}
} else {
if (this._currentValueIndices === nIdx) {
} 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 });
}

View File

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

View File

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

View File

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