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,21 +198,19 @@ 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) && !stack.includes(STATE_IF_FALSE) &&
!stack.includes(STATE_IF_FALSE) && !stack.includes(STATE_ELSE_FALSE)
!stack.includes(STATE_ELSE_FALSE) ) {
) { writeLine(
writeLine( line
line .replaceAll(/^\/\/|^<!--/g, " ")
.replaceAll(/^\/\/|^<!--/g, " ") .replaceAll(/(^\s*)\/\*/g, "$1 ")
.replaceAll(/(^\s*)\/\*/g, "$1 ") .replaceAll(/\*\/$|-->$/g, "")
.replaceAll(/\*\/$|-->$/g, "") );
);
}
} }
} }
if (state !== STATE_NONE || stack.length !== 0) { if (state !== STATE_NONE || stack.length !== 0) {

View File

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

View File

@ -2698,24 +2698,22 @@ 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)); startChunk = lastSpacePosInStringEnd;
startChunk = lastSpacePosInStringEnd; i = lastSpacePos + 1;
i = lastSpacePos + 1; lastSpacePosInStringStart = -1;
lastSpacePosInStringStart = -1; currentWidth = 0;
currentWidth = 0;
} else {
// Just break in the middle of the word
chunks.push(line.substring(startChunk, start));
startChunk = start;
currentWidth = glyphWidth;
}
} else { } else {
currentWidth += glyphWidth; // Just break in the middle of the word
chunks.push(line.substring(startChunk, start));
startChunk = start;
currentWidth = glyphWidth;
} }
} else {
currentWidth += glyphWidth;
} }
} }

View File

@ -353,11 +353,8 @@ 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 levels[i] += 1;
if (t === "L" || t === "AN" || t === "EN") {
levels[i] += 1;
}
} }
} }

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,9 +217,7 @@ 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() {}

View File

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

View File

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

View File

@ -619,17 +619,15 @@ class CompositeGlyph {
) { ) {
size += 2; size += 2;
} }
} else { } else if (
if ( !(
!( this.argument1 >= 0 &&
this.argument1 >= 0 && this.argument1 <= 255 &&
this.argument1 <= 255 && this.argument2 >= 0 &&
this.argument2 >= 0 && this.argument2 <= 255
this.argument2 <= 255 )
) ) {
) { size += 2;
size += 2;
}
} }
return size; return size;
@ -650,17 +648,15 @@ 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 && this.argument2 >= 0 &&
this.argument2 >= 0 && this.argument2 <= 255
this.argument2 <= 255 )
) ) {
) { 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);

View File

@ -3662,12 +3662,10 @@ 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 if (this.slope === "\\") {
[x1, y1, x2, y2] = [0, 0, "100%", "100%"];
} else { } else {
if (this.slope === "\\") { [x1, y1, x2, y2] = [0, "100%", "100%", 0];
[x1, y1, x2, y2] = [0, 0, "100%", "100%"];
} else {
[x1, y1, x2, y2] = [0, "100%", "100%", 0];
}
} }
const line = { const line = {

View File

@ -432,10 +432,8 @@ 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])} ` +

View File

@ -127,12 +127,10 @@ 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,12 +387,10 @@ 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,11 +623,10 @@ 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) {

View File

@ -378,40 +378,38 @@ 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" || zoomArg === "FitBH" ||
zoomArg === "FitBH" || zoomArg === "FitV" ||
zoomArg === "FitV" || zoomArg === "FitBV"
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 = [ dest = [
null, null,
{ name: zoomArg }, { 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) { if (dest) {

View File

@ -128,10 +128,8 @@ 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;