Fix all outstanding ESLint arrow-body-style warnings

Currently this rule is disabled in a number of spots across the code-base, and unless absolutely necessary we probably shouldn't disable linting, so let's just update the code to fix all the outstanding cases.
This commit is contained in:
Jonas Jenwald 2025-02-17 15:45:44 +01:00
parent affce70a09
commit 36979e9eb2
5 changed files with 71 additions and 82 deletions

View File

@ -84,17 +84,14 @@ class AnnotationFactory {
// with "GoToE" actions, from throwing and thus breaking parsing: // with "GoToE" actions, from throwing and thus breaking parsing:
pdfManager.ensureCatalog("attachments"), pdfManager.ensureCatalog("attachments"),
]).then( ]).then(
// eslint-disable-next-line arrow-body-style ([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => ({
([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => { pdfManager,
return { acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
pdfManager, xfaDatasets,
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, structTreeRoot,
xfaDatasets, baseUrl,
structTreeRoot, attachments,
baseUrl, }),
attachments,
};
},
reason => { reason => {
warn(`createGlobals: "${reason}".`); warn(`createGlobals: "${reason}".`);
return null; return null;

View File

@ -1620,24 +1620,24 @@ class PDFDocument {
} else { } else {
promise = catalog.getPageDict(pageIndex); promise = catalog.getPageDict(pageIndex);
} }
// eslint-disable-next-line arrow-body-style promise = promise.then(
promise = promise.then(([pageDict, ref]) => { ([pageDict, ref]) =>
return new Page({ new Page({
pdfManager: this.pdfManager, pdfManager: this.pdfManager,
xref: this.xref, xref: this.xref,
pageIndex, pageIndex,
pageDict, pageDict,
ref, ref,
globalIdFactory: this._globalIdFactory, globalIdFactory: this._globalIdFactory,
fontCache: catalog.fontCache, fontCache: catalog.fontCache,
builtInCMapCache: catalog.builtInCMapCache, builtInCMapCache: catalog.builtInCMapCache,
standardFontDataCache: catalog.standardFontDataCache, standardFontDataCache: catalog.standardFontDataCache,
globalImageCache: catalog.globalImageCache, globalImageCache: catalog.globalImageCache,
systemFontCache: catalog.systemFontCache, systemFontCache: catalog.systemFontCache,
nonBlendModesSet: catalog.nonBlendModesSet, nonBlendModesSet: catalog.nonBlendModesSet,
xfaFactory, xfaFactory,
}); })
}); );
this._pagePromises.set(pageIndex, promise); this._pagePromises.set(pageIndex, promise);
return promise; return promise;

View File

@ -1231,15 +1231,13 @@ class PartialEvaluator {
fallbackFontDict = null, fallbackFontDict = null,
cssFontInfo = null cssFontInfo = null
) { ) {
// eslint-disable-next-line arrow-body-style const errorFont = async () =>
const errorFont = async () => { new TranslatedFont({
return new TranslatedFont({
loadedName: "g_font_error", loadedName: "g_font_error",
font: new ErrorFont(`Font "${fontName}" is not available.`), font: new ErrorFont(`Font "${fontName}" is not available.`),
dict: font, dict: font,
evaluatorOptions: this.options, evaluatorOptions: this.options,
}); });
};
let fontRef; let fontRef;
if (font) { if (font) {

View File

@ -106,33 +106,33 @@ async function inlineImages(node, silentErrors = false) {
} }
return response.blob(); return response.blob();
}) })
// eslint-disable-next-line arrow-body-style .then(
.then(blob => { blob =>
return new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
resolve(reader.result); resolve(reader.result);
}; };
reader.onerror = reject; reader.onerror = reject;
reader.readAsDataURL(blob); reader.readAsDataURL(blob);
}); })
}) )
// eslint-disable-next-line arrow-body-style .then(
.then(dataUrl => { dataUrl =>
return new Promise((resolve, reject) => { new Promise((resolve, reject) => {
image.onload = resolve; image.onload = resolve;
image.onerror = evt => { image.onerror = evt => {
if (silentErrors) { if (silentErrors) {
resolve(); resolve();
return; return;
} }
reject(evt); reject(evt);
}; };
image.src = dataUrl; image.src = dataUrl;
}); })
}) )
.catch(reason => { .catch(reason => {
throw new Error(`Error inlining image (${url}): ${reason}`); throw new Error(`Error inlining image (${url}): ${reason}`);
}) })

View File

@ -4110,34 +4110,28 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
}) })
); );
// eslint-disable-next-line arrow-body-style const result1 = loadingTask1.promise.then(async pdfDoc => {
const result1 = loadingTask1.promise.then(pdfDoc => { const pdfPage = await pdfDoc.getPage(1);
// eslint-disable-next-line arrow-body-style const opList = await pdfPage.getOperatorList();
return pdfDoc.getPage(1).then(pdfPage => {
return pdfPage.getOperatorList().then(opList => {
expect(opList.fnArray.length).toBeGreaterThan(100);
expect(opList.argsArray.length).toBeGreaterThan(100);
expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null);
return loadingTask1.destroy(); expect(opList.fnArray.length).toBeGreaterThan(100);
}); expect(opList.argsArray.length).toBeGreaterThan(100);
}); expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null);
await loadingTask1.destroy();
}); });
// eslint-disable-next-line arrow-body-style const result2 = loadingTask2.promise.then(async pdfDoc => {
const result2 = loadingTask2.promise.then(pdfDoc => { const pdfPage = await pdfDoc.getPage(1);
// eslint-disable-next-line arrow-body-style const opList = await pdfPage.getOperatorList();
return pdfDoc.getPage(1).then(pdfPage => {
return pdfPage.getOperatorList().then(opList => {
expect(opList.fnArray.length).toEqual(0);
expect(opList.argsArray.length).toEqual(0);
expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null);
return loadingTask2.destroy(); expect(opList.fnArray.length).toEqual(0);
}); expect(opList.argsArray.length).toEqual(0);
}); expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null);
await loadingTask2.destroy();
}); });
await Promise.all([result1, result2]); await Promise.all([result1, result2]);