Additional *manual* unicorn/prefer-ternary changes

Not all cases could be automatically fixed, and the changes also triggered a number of `prefer-const` errors that needed to be handled manually.
This commit is contained in:
Jonas Jenwald 2023-07-27 09:38:11 +02:00
parent 674e7ee381
commit c0fe96b8fe
13 changed files with 20 additions and 55 deletions

View File

@ -839,8 +839,7 @@ class Annotation {
setRotation(mk, dict) {
this.rotation = 0;
let angle;
angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0;
let angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0;
if (Number.isInteger(angle) && angle !== 0) {
angle %= 360;
if (angle < 0) {

View File

@ -558,8 +558,7 @@ class CFFParser {
stackSize %= 2;
validationCommand = CharstringValidationData[value];
} else if (value === 10 || value === 29) {
let subrsIndex;
subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex;
const subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex;
if (!subrsIndex) {
validationCommand = CharstringValidationData[value];
warn("Missing subrsIndex for " + validationCommand.id);

View File

@ -1305,9 +1305,7 @@ const CalRGBCS = (function CalRGBCSClosure() {
const LabCS = (function LabCSClosure() {
// Function g(x) from spec
function fn_g(x) {
let result;
result = x >= 6 / 29 ? x ** 3 : (108 / 841) * (x - 4 / 29);
return result;
return x >= 6 / 29 ? x ** 3 : (108 / 841) * (x - 4 / 29);
}
function decode(value, high1, low2, high2) {

View File

@ -1445,8 +1445,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
} else {
password = [];
}
let pdfAlgorithm;
pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
if (
pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)

View File

@ -793,8 +793,7 @@ class PartialEvaluator {
);
if (cacheKey && imageRef && cacheGlobally) {
let length = 0;
length = imgData.bitmap
const length = imgData.bitmap
? imgData.width * imgData.height * 4
: imgData.data.length;
this.globalImageCache.addByteSize(imageRef, length);

View File

@ -116,11 +116,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
baseEncoding = builtInEncoding;
for (charCode = 0; charCode < baseEncoding.length; charCode++) {
glyphId = glyphNames.indexOf(baseEncoding[charCode]);
if (glyphId >= 0) {
charCodeToGlyphId[charCode] = glyphId;
} else {
charCodeToGlyphId[charCode] = 0; // notdef
}
charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
}
} else if (properties.baseEncodingName) {
// If a valid base encoding name was used, the mapping is initialized with
@ -128,11 +124,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
baseEncoding = getEncoding(properties.baseEncodingName);
for (charCode = 0; charCode < baseEncoding.length; charCode++) {
glyphId = glyphNames.indexOf(baseEncoding[charCode]);
if (glyphId >= 0) {
charCodeToGlyphId[charCode] = glyphId;
} else {
charCodeToGlyphId[charCode] = 0; // notdef
}
charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
}
} else if (isSymbolicFont) {
// For a symbolic font the encoding should be the fonts built-in encoding.
@ -145,11 +137,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
baseEncoding = StandardEncoding;
for (charCode = 0; charCode < baseEncoding.length; charCode++) {
glyphId = glyphNames.indexOf(baseEncoding[charCode]);
if (glyphId >= 0) {
charCodeToGlyphId[charCode] = glyphId;
} else {
charCodeToGlyphId[charCode] = 0; // notdef
}
charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
}
}
@ -170,11 +158,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
glyphId = glyphNames.indexOf(standardGlyphName);
}
}
if (glyphId >= 0) {
charCodeToGlyphId[charCode] = glyphId;
} else {
charCodeToGlyphId[charCode] = 0; // notdef
}
charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
}
}
return charCodeToGlyphId;

View File

@ -385,8 +385,7 @@ function decodeScan(
let mcu = 0,
fileMarker;
let mcuExpected;
mcuExpected =
const mcuExpected =
componentsLength === 1
? components[0].blocksPerLine * components[0].blocksPerColumn
: mcusPerLine * frame.mcusPerColumn;

View File

@ -55,9 +55,8 @@ class Binder {
constructor(root) {
this.root = root;
this.datasets = root.datasets;
this.data = root.datasets?.data
? root.datasets.data
: new XmlObject(NamespaceIds.datasets.id, "data");
this.data =
root.datasets?.data || new XmlObject(NamespaceIds.datasets.id, "data");
this.emptyMerge = this.data[$getChildren]().length === 0;
this.root.form = this.form = root.template[$clone]();

View File

@ -224,8 +224,7 @@ function getXfaFontWidths(name) {
}
const { baseWidths, baseMapping, factors } = info;
let rescaledBaseWidths;
rescaledBaseWidths = !factors
const rescaledBaseWidths = !factors
? baseWidths
: baseWidths.map((w, i) => w * factors[i]);

View File

@ -854,8 +854,7 @@ function genericComposeSMask(
const g0 = hasBackdrop ? backdrop[1] : 0;
const b0 = hasBackdrop ? backdrop[2] : 0;
let composeFn;
composeFn =
const composeFn =
subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha;
// processing image in chunks to save memory
@ -2254,8 +2253,7 @@ class CanvasGraphics {
}
}
let charWidth;
charWidth = vertical
const charWidth = vertical
? width * widthAdvanceScale - spacing * fontDirection
: width * widthAdvanceScale + spacing * fontDirection;
x += charWidth;

View File

@ -200,8 +200,7 @@ function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
let xb, cbr, cbg, cbb;
for (let y = minY; y <= maxY; y++) {
if (y < y2) {
let k;
k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
const k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
xa = x1 - (x1 - x2) * k;
car = c1r - (c1r - c2r) * k;
cag = c1g - (c1g - c2g) * k;

View File

@ -152,14 +152,9 @@ const convertImgDataToPng = (function () {
// Node v0.11.12 zlib.deflateSync is introduced (and returns a Buffer).
// Node v3.0.0 Buffer inherits from Uint8Array.
// Node v8.0.0 zlib.deflateSync accepts Uint8Array as input.
let input;
// eslint-disable-next-line no-undef
if (parseInt(process.versions.node) >= 8) {
input = literals;
} else {
const input =
// eslint-disable-next-line no-undef
input = Buffer.from(literals);
}
parseInt(process.versions.node) >= 8 ? literals : Buffer.from(literals);
const output = __non_webpack_require__("zlib").deflateSync(input, {
level: 9,
});
@ -857,8 +852,7 @@ class SVGGraphics {
// might actually map to a different glyph.
}
let charWidth;
charWidth = vertical
const charWidth = vertical
? width * widthAdvanceScale - spacing * fontDirection
: width * widthAdvanceScale + spacing * fontDirection;

View File

@ -212,8 +212,7 @@ class XfaLayer {
continue;
}
let childHtml;
childHtml = child?.attributes?.xmlns
const childHtml = child?.attributes?.xmlns
? document.createElementNS(child.attributes.xmlns, name)
: document.createElement(name);