mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-04 22:25:50 +02:00
Extend the unicorn/logical-assignment-operators rule to if-statements
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/logical-assignment-operators.md and https://eslint.org/docs/latest/rules/logical-assignment-operators#enforceforifstatements
This commit is contained in:
parent
2bc64ec330
commit
046e68d140
@ -181,7 +181,7 @@ export default [
|
||||
"unicorn/logical-assignment-operators": [
|
||||
"error",
|
||||
"always",
|
||||
{ enforceForIfStatements: false },
|
||||
{ enforceForIfStatements: true },
|
||||
],
|
||||
"unicorn/prefer-logical-operator-over-ternary": "error",
|
||||
"unicorn/prefer-modern-dom-apis": "error",
|
||||
|
||||
@ -3318,13 +3318,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
||||
return super.getOperatorList(evaluator, task, intent, annotationStorage);
|
||||
}
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
// There is no default appearance so use the one derived
|
||||
// from the field value.
|
||||
value = this.data.checkBox
|
||||
? this.data.fieldValue === this.data.exportValue
|
||||
: this.data.fieldValue === this.data.buttonValue;
|
||||
}
|
||||
// There is no default appearance, `value === null || value === undefined`,
|
||||
// so use the one derived from the field value.
|
||||
value ??= this.data.checkBox
|
||||
? this.data.fieldValue === this.data.exportValue
|
||||
: this.data.fieldValue === this.data.buttonValue;
|
||||
|
||||
return this.#getOperatorListForAppearance(
|
||||
evaluator,
|
||||
@ -4716,9 +4714,7 @@ class PolylineAnnotation extends MarkupAnnotation {
|
||||
const strokeAlpha = dict.get("CA");
|
||||
|
||||
let fillColor = getRgbColor(dict.getArray("IC"), null);
|
||||
if (fillColor) {
|
||||
fillColor = getPdfColorArray(fillColor);
|
||||
}
|
||||
fillColor &&= getPdfColorArray(fillColor);
|
||||
|
||||
let operator;
|
||||
if (fillColor) {
|
||||
|
||||
@ -58,11 +58,9 @@ class CCITTFaxStream extends DecodeStream {
|
||||
if (this.eof) {
|
||||
return this.buffer;
|
||||
}
|
||||
if (!bytes) {
|
||||
bytes = this.stream.isAsync
|
||||
? (await this.stream.asyncGetBytes()) || this.bytes
|
||||
: this.bytes;
|
||||
}
|
||||
bytes ??= this.stream.isAsync
|
||||
? (await this.stream.asyncGetBytes()) || this.bytes
|
||||
: this.bytes;
|
||||
|
||||
this.buffer = await JBig2CCITTFaxImage.instance.decode(
|
||||
bytes,
|
||||
|
||||
@ -775,14 +775,12 @@ class CFFParser {
|
||||
} else if (localSubrIndex) {
|
||||
localSubrToUse = localSubrIndex;
|
||||
}
|
||||
if (valid) {
|
||||
valid = this.parseCharString(
|
||||
state,
|
||||
charstring,
|
||||
localSubrToUse,
|
||||
globalSubrIndex
|
||||
);
|
||||
}
|
||||
valid &&= this.parseCharString(
|
||||
state,
|
||||
charstring,
|
||||
localSubrToUse,
|
||||
globalSubrIndex
|
||||
);
|
||||
if (state.width !== null) {
|
||||
const nominalWidth = privateDictToUse.getByName("nominalWidthX");
|
||||
widths[i] = nominalWidth + state.width;
|
||||
|
||||
@ -243,9 +243,7 @@ class ColorSpaceUtils {
|
||||
break;
|
||||
case "Pattern":
|
||||
baseCS = cs[1] || null;
|
||||
if (baseCS) {
|
||||
baseCS = this.#subParse(baseCS, options);
|
||||
}
|
||||
baseCS &&= this.#subParse(baseCS, options);
|
||||
return new PatternCS(baseCS);
|
||||
case "I":
|
||||
case "Indexed":
|
||||
|
||||
@ -151,9 +151,8 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
||||
glyphId = glyphNames.indexOf(glyphName);
|
||||
|
||||
if (glyphId === -1) {
|
||||
if (!glyphsUnicodeMap) {
|
||||
glyphsUnicodeMap = getGlyphsUnicode();
|
||||
}
|
||||
glyphsUnicodeMap ??= getGlyphsUnicode();
|
||||
|
||||
const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
|
||||
if (standardGlyphName !== glyphName) {
|
||||
glyphId = glyphNames.indexOf(standardGlyphName);
|
||||
|
||||
@ -160,11 +160,9 @@ class XFAFactory {
|
||||
const { html } = result;
|
||||
const { attributes } = html;
|
||||
if (attributes) {
|
||||
if (attributes.class) {
|
||||
attributes.class = attributes.class.filter(
|
||||
attr => !attr.startsWith("xfa")
|
||||
);
|
||||
}
|
||||
attributes.class &&= attributes.class.filter(
|
||||
attr => !attr.startsWith("xfa")
|
||||
);
|
||||
attributes.dir = "auto";
|
||||
}
|
||||
|
||||
|
||||
@ -31,9 +31,7 @@ class FontFinder {
|
||||
this.addPdfFont(pdfFont);
|
||||
}
|
||||
for (const pdfFont of this.fonts.values()) {
|
||||
if (!pdfFont.regular) {
|
||||
pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
|
||||
}
|
||||
pdfFont.regular ||= pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
|
||||
}
|
||||
|
||||
if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
|
||||
@ -72,10 +70,7 @@ class FontFinder {
|
||||
property += "italic";
|
||||
}
|
||||
}
|
||||
|
||||
if (!property) {
|
||||
property = "regular";
|
||||
}
|
||||
property ||= "regular";
|
||||
|
||||
font[property] = pdfFont;
|
||||
}
|
||||
|
||||
@ -518,9 +518,7 @@ class XFAObject {
|
||||
true /* = dotDotAllowed */,
|
||||
false /* = useCache */
|
||||
);
|
||||
if (proto) {
|
||||
proto = proto[0];
|
||||
}
|
||||
proto &&= proto[0];
|
||||
}
|
||||
|
||||
if (!proto) {
|
||||
|
||||
@ -740,9 +740,7 @@ class XRef {
|
||||
if (isCmd(obj, "xref")) {
|
||||
// Parse end-of-file XRef
|
||||
dict = this.processXRefTable(parser);
|
||||
if (!this.topDict) {
|
||||
this.topDict = dict;
|
||||
}
|
||||
this.topDict ||= dict;
|
||||
|
||||
// Recursively get other XRefs 'XRefStm', if any
|
||||
obj = dict.get("XRefStm");
|
||||
@ -762,9 +760,8 @@ class XRef {
|
||||
throw new FormatError("Invalid XRef stream");
|
||||
}
|
||||
dict = this.processXRefStream(obj);
|
||||
if (!this.topDict) {
|
||||
this.topDict = dict;
|
||||
}
|
||||
this.topDict ||= dict;
|
||||
|
||||
if (!dict) {
|
||||
throw new FormatError("Failed to read XRef stream");
|
||||
}
|
||||
|
||||
@ -1187,10 +1187,8 @@ class LinkAnnotationElement extends AnnotationElement {
|
||||
if (data.overlaidText) {
|
||||
link.title = data.overlaidText;
|
||||
}
|
||||
link.onclick ||= () => false;
|
||||
|
||||
if (!link.onclick) {
|
||||
link.onclick = () => false;
|
||||
}
|
||||
this.#setInternalLink();
|
||||
}
|
||||
|
||||
|
||||
@ -488,12 +488,10 @@ class StampEditor extends AnnotationEditor {
|
||||
}
|
||||
|
||||
copyCanvas(maxDataDimension, maxPreviewDimension, createImageData = false) {
|
||||
if (!maxDataDimension) {
|
||||
// TODO: get this value from Firefox
|
||||
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
|
||||
// It's the maximum dimension that the AI can handle.
|
||||
maxDataDimension = 224;
|
||||
}
|
||||
// TODO: get this value from Firefox
|
||||
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
|
||||
// It's the maximum dimension that the AI can handle.
|
||||
maxDataDimension ||= 224;
|
||||
|
||||
const { width: bitmapWidth, height: bitmapHeight } = this.#bitmap;
|
||||
const outputScale = new OutputScale();
|
||||
|
||||
@ -334,17 +334,11 @@ class Field extends PDFObject {
|
||||
}
|
||||
|
||||
buttonGetCaption(nFace = 0) {
|
||||
if (this._buttonCaption) {
|
||||
return this._buttonCaption[nFace];
|
||||
}
|
||||
return "";
|
||||
return this._buttonCaption ? this._buttonCaption[nFace] : "";
|
||||
}
|
||||
|
||||
buttonGetIcon(nFace = 0) {
|
||||
if (this._buttonIcon) {
|
||||
return this._buttonIcon[nFace];
|
||||
}
|
||||
return null;
|
||||
return this._buttonIcon ? this._buttonIcon[nFace] : null;
|
||||
}
|
||||
|
||||
buttonImportIcon(cPath = null, nPave = 0) {
|
||||
@ -352,9 +346,7 @@ class Field extends PDFObject {
|
||||
}
|
||||
|
||||
buttonSetCaption(cCaption, nFace = 0) {
|
||||
if (!this._buttonCaption) {
|
||||
this._buttonCaption = ["", "", ""];
|
||||
}
|
||||
this._buttonCaption ??= ["", "", ""];
|
||||
this._buttonCaption[nFace] = cCaption;
|
||||
// TODO: send to the annotation layer
|
||||
// Right now the button is drawn on the canvas using its appearance so
|
||||
@ -363,9 +355,7 @@ class Field extends PDFObject {
|
||||
}
|
||||
|
||||
buttonSetIcon(oIcon, nFace = 0) {
|
||||
if (!this._buttonIcon) {
|
||||
this._buttonIcon = [null, null, null];
|
||||
}
|
||||
this._buttonIcon ??= [null, null, null];
|
||||
this._buttonIcon[nFace] = oIcon;
|
||||
}
|
||||
|
||||
|
||||
@ -119,9 +119,7 @@ class Util extends PDFObject {
|
||||
}
|
||||
cFlags = flags;
|
||||
|
||||
if (nWidth) {
|
||||
nWidth = parseInt(nWidth);
|
||||
}
|
||||
nWidth &&= parseInt(nWidth);
|
||||
|
||||
let intPart = Math.trunc(arg);
|
||||
|
||||
@ -136,9 +134,7 @@ class Util extends PDFObject {
|
||||
return hex;
|
||||
}
|
||||
|
||||
if (nPrecision) {
|
||||
nPrecision = parseInt(nPrecision.substring(1));
|
||||
}
|
||||
nPrecision &&= parseInt(nPrecision.substring(1));
|
||||
|
||||
nDecSep = nDecSep ? nDecSep.substring(1) : "0";
|
||||
const separators = {
|
||||
|
||||
@ -968,9 +968,7 @@ class Driver {
|
||||
if (task.type === "other" || task.enableXfa) {
|
||||
return;
|
||||
}
|
||||
if (!task._prefetchedLoadingTask) {
|
||||
task._prefetchedLoadingTask = getDocument(this._getDocumentOptions(task));
|
||||
}
|
||||
task._prefetchedLoadingTask ??= getDocument(this._getDocumentOptions(task));
|
||||
}
|
||||
|
||||
_cleanup() {
|
||||
|
||||
@ -801,9 +801,8 @@ async function handleWsBinaryResult(data) {
|
||||
if (!taskResults) {
|
||||
return;
|
||||
}
|
||||
if (!taskResults[round]) {
|
||||
taskResults[round] = [];
|
||||
}
|
||||
taskResults[round] ||= [];
|
||||
|
||||
if (taskResults[round][page - 1]) {
|
||||
console.error(
|
||||
`Results for ${browser}:${id}:${round}:${page - 1} were already submitted`
|
||||
@ -1010,9 +1009,7 @@ async function startBrowser({
|
||||
protocolTimeout: 0.75 * /* jasmine.DEFAULT_TIMEOUT_INTERVAL = */ 30000,
|
||||
};
|
||||
|
||||
if (!tempDir) {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
|
||||
}
|
||||
tempDir ||= fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
|
||||
const printFile = path.join(tempDir, "print.pdf");
|
||||
|
||||
if (browserName === "chrome") {
|
||||
|
||||
@ -2068,11 +2068,9 @@ const PDFViewerApplication = {
|
||||
);
|
||||
this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
|
||||
|
||||
if (!this.pdfViewer.currentScaleValue) {
|
||||
// Scale was not initialized: invalid bookmark or scale was not specified.
|
||||
// Setting the default one.
|
||||
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
||||
}
|
||||
// Scale was not initialized: invalid bookmark or scale was not specified.
|
||||
// Setting the default one.
|
||||
this.pdfViewer.currentScaleValue ||= DEFAULT_SCALE_VALUE;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -272,11 +272,10 @@ let port;
|
||||
// 4. Page: Invoke callback.
|
||||
function setReferer(url, callback) {
|
||||
dnrRequestId ??= crypto.getRandomValues(new Uint32Array(1))[0] % 0x80000000;
|
||||
if (!port) {
|
||||
// The background page will accept the port, and keep adding the Referer
|
||||
// request header to requests to |url| until the port is disconnected.
|
||||
port = chrome.runtime.connect({ name: "chromecom-referrer" });
|
||||
}
|
||||
// The background page will accept the port, and keep adding the Referer
|
||||
// request header to requests to |url| until the port is disconnected.
|
||||
port ??= chrome.runtime.connect({ name: "chromecom-referrer" });
|
||||
|
||||
port.onDisconnect.addListener(onDisconnect);
|
||||
port.onMessage.addListener(onMessage);
|
||||
// Initiate the information exchange.
|
||||
|
||||
@ -1854,9 +1854,7 @@ class PDFThumbnailViewer {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!nextThumbnail) {
|
||||
nextThumbnail = firstWithDifferentY;
|
||||
}
|
||||
nextThumbnail ??= firstWithDifferentY;
|
||||
}
|
||||
if (nextThumbnail) {
|
||||
this.#focusThumbnailElement(nextThumbnail, navigateCheckboxes);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user