Merge pull request #20657 from Snuffleupagus/unicorn-prefer-class-fields

Enable the `unicorn/prefer-class-fields` ESLint plugin rule
This commit is contained in:
Tim van der Meij 2026-02-14 15:26:28 +01:00 committed by GitHub
commit 1d6307f5d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 283 additions and 210 deletions

View File

@ -148,6 +148,7 @@ export default [
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-class-fields": "error",
"unicorn/prefer-classlist-toggle": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-append": "error",

View File

@ -1462,14 +1462,17 @@ class Annotation {
* Contains all data regarding an annotation's border style.
*/
class AnnotationBorderStyle {
constructor() {
this.width = 1;
this.rawWidth = 1;
this.style = AnnotationBorderStyleType.SOLID;
this.dashArray = [3];
this.horizontalCornerRadius = 0;
this.verticalCornerRadius = 0;
}
width = 1;
rawWidth = 1;
style = AnnotationBorderStyleType.SOLID;
dashArray = [3];
horizontalCornerRadius = 0;
verticalCornerRadius = 0;
/**
* Set the width.

View File

@ -991,24 +991,31 @@ class CFFParser {
// Compact Font Format
class CFF {
constructor() {
this.header = null;
this.names = [];
this.topDict = null;
this.strings = new CFFStrings();
this.globalSubrIndex = null;
header = null;
// The following could really be per font, but since we only have one font
// store them here.
this.encoding = null;
this.charset = null;
this.charStrings = null;
this.fdArray = [];
this.fdSelect = null;
names = [];
this.isCIDFont = false;
this.charStringCount = 0;
}
topDict = null;
strings = new CFFStrings();
globalSubrIndex = null;
// The following could really be per font, but since we only have one font
// store them here.
encoding = null;
charset = null;
charStrings = null;
fdArray = [];
fdSelect = null;
isCIDFont = false;
charStringCount = 0;
duplicateFirstGlyph() {
// Browsers will not display a glyph at position 0. Typically glyph 0 is

View File

@ -32,9 +32,11 @@ import { calculateSHA256 } from "./calculate_sha256.js";
import { DecryptStream } from "./decrypt_stream.js";
class ARCFourCipher {
a = 0;
b = 0;
constructor(key) {
this.a = 0;
this.b = 0;
const s = new Uint8Array(256);
const keyLength = key.length;

View File

@ -74,33 +74,52 @@ class XRefWrapper {
}
class PDFEditor {
hasSingleFile = false;
currentDocument = null;
oldPages = [];
newPages = [];
xref = [null];
xrefWrapper = new XRefWrapper(this.xref);
newRefCount = 1;
namesDict = null;
version = "1.7";
pageLabels = null;
namedDestinations = new Map();
parentTree = new Map();
structTreeKids = [];
idTree = new Map();
classMap = new Dict();
roleMap = new Dict();
namespaces = new Map();
structTreeAF = [];
structTreePronunciationLexicon = [];
constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
this.hasSingleFile = false;
this.currentDocument = null;
this.oldPages = [];
this.newPages = [];
this.xref = [null];
this.xrefWrapper = new XRefWrapper(this.xref);
this.newRefCount = 1;
[this.rootRef, this.rootDict] = this.newDict;
[this.infoRef, this.infoDict] = this.newDict;
[this.pagesRef, this.pagesDict] = this.newDict;
this.namesDict = null;
this.useObjectStreams = useObjectStreams;
this.objStreamRefs = useObjectStreams ? new Set() : null;
this.version = "1.7";
this.title = title;
this.author = author;
this.pageLabels = null;
this.namedDestinations = new Map();
this.parentTree = new Map();
this.structTreeKids = [];
this.idTree = new Map();
this.classMap = new Dict();
this.roleMap = new Dict();
this.namespaces = new Map();
this.structTreeAF = [];
this.structTreePronunciationLexicon = [];
}
/**

View File

@ -79,13 +79,15 @@ const COMMAND_MAP = {
* the charStrings.
*/
class Type1CharString {
constructor() {
this.width = 0;
this.lsb = 0;
this.flexing = false;
this.output = [];
this.stack = [];
}
width = 0;
lsb = 0;
flexing = false;
output = [];
stack = [];
convert(encoded, subrs, seacAnalysisEnabled) {
const count = encoded.length;

View File

@ -35,15 +35,17 @@ class AnnotationStorage {
#storage = new Map();
constructor() {
// Callbacks to signal when the modification state is set or reset.
// This is used by the viewer to only bind on `beforeunload` if forms
// are actually edited to prevent doing so unconditionally since that
// can have undesirable effects.
this.onSetModified = null;
this.onResetModified = null;
this.onAnnotationEditor = null;
// Callbacks to signal when the modification state is set or reset.
// This is used by the viewer to only bind on `beforeunload` if forms
// are actually edited to prevent doing so unconditionally since that
// can have undesirable effects.
onSetModified = null;
onResetModified = null;
onAnnotationEditor = null;
constructor() {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
// For testing purposes.
Object.defineProperty(this, "_setValues", {

View File

@ -14,132 +14,165 @@
*/
class PrintParams {
binaryOk = true;
bitmapDPI = 150;
booklet = {
binding: 0,
duplexMode: 0,
subsetFrom: 0,
subsetTo: -1,
};
colorOverride = 0;
colorProfile = "";
constants = Object.freeze({
bookletBindings: Object.freeze({
Left: 0,
Right: 1,
LeftTall: 2,
RightTall: 3,
}),
bookletDuplexMode: Object.freeze({
BothSides: 0,
FrontSideOnly: 1,
BasicSideOnly: 2,
}),
colorOverrides: Object.freeze({
auto: 0,
gray: 1,
mono: 2,
}),
fontPolicies: Object.freeze({
everyPage: 0,
jobStart: 1,
pageRange: 2,
}),
handling: Object.freeze({
none: 0,
fit: 1,
shrink: 2,
tileAll: 3,
tileLarge: 4,
nUp: 5,
booklet: 6,
}),
interactionLevel: Object.freeze({
automatic: 0,
full: 1,
silent: 2,
}),
nUpPageOrders: Object.freeze({
Horizontal: 0,
HorizontalReversed: 1,
Vertical: 2,
}),
printContents: Object.freeze({
doc: 0,
docAndComments: 1,
formFieldsOnly: 2,
}),
flagValues: Object.freeze({
applyOverPrint: 1,
applySoftProofSettings: 1 << 1,
applyWorkingColorSpaces: 1 << 2,
emitHalftones: 1 << 3,
emitPostScriptXObjects: 1 << 4,
emitFormsAsPSForms: 1 << 5,
maxJP2KRes: 1 << 6,
setPageSize: 1 << 7,
suppressBG: 1 << 8,
suppressCenter: 1 << 9,
suppressCJKFontSubst: 1 << 10,
suppressCropClip: 1 << 1,
suppressRotate: 1 << 12,
suppressTransfer: 1 << 13,
suppressUCR: 1 << 14,
useTrapAnnots: 1 << 15,
usePrintersMarks: 1 << 16,
}),
rasterFlagValues: Object.freeze({
textToOutline: 1,
strokesToOutline: 1 << 1,
allowComplexClip: 1 << 2,
preserveOverprint: 1 << 3,
}),
subsets: Object.freeze({
all: 0,
even: 1,
odd: 2,
}),
tileMarks: Object.freeze({
none: 0,
west: 1,
east: 2,
}),
usages: Object.freeze({
auto: 0,
use: 1,
noUse: 2,
}),
});
downloadFarEastFonts = false;
fileName = "";
firstPage = 0;
flags = 0;
fontPolicy = 0;
gradientDPI = 150;
interactive = 1;
npUpAutoRotate = false;
npUpNumPagesH = 2;
npUpNumPagesV = 2;
npUpPageBorder = false;
npUpPageOrder = 0;
pageHandling = 0;
pageSubset = 0;
printAsImage = false;
printContent = 0;
printerName = "";
psLevel = 0;
rasterFlags = 0;
reversePages = false;
tileLabel = false;
tileMark = 0;
tileOverlap = 0;
tileScale = 1.0;
transparencyLevel = 75;
usePrinterCRD = 0;
useT1Conversion = 0;
constructor(data) {
this.binaryOk = true;
this.bitmapDPI = 150;
this.booklet = {
binding: 0,
duplexMode: 0,
subsetFrom: 0,
subsetTo: -1,
};
this.colorOverride = 0;
this.colorProfile = "";
this.constants = Object.freeze({
bookletBindings: Object.freeze({
Left: 0,
Right: 1,
LeftTall: 2,
RightTall: 3,
}),
bookletDuplexMode: Object.freeze({
BothSides: 0,
FrontSideOnly: 1,
BasicSideOnly: 2,
}),
colorOverrides: Object.freeze({
auto: 0,
gray: 1,
mono: 2,
}),
fontPolicies: Object.freeze({
everyPage: 0,
jobStart: 1,
pageRange: 2,
}),
handling: Object.freeze({
none: 0,
fit: 1,
shrink: 2,
tileAll: 3,
tileLarge: 4,
nUp: 5,
booklet: 6,
}),
interactionLevel: Object.freeze({
automatic: 0,
full: 1,
silent: 2,
}),
nUpPageOrders: Object.freeze({
Horizontal: 0,
HorizontalReversed: 1,
Vertical: 2,
}),
printContents: Object.freeze({
doc: 0,
docAndComments: 1,
formFieldsOnly: 2,
}),
flagValues: Object.freeze({
applyOverPrint: 1,
applySoftProofSettings: 1 << 1,
applyWorkingColorSpaces: 1 << 2,
emitHalftones: 1 << 3,
emitPostScriptXObjects: 1 << 4,
emitFormsAsPSForms: 1 << 5,
maxJP2KRes: 1 << 6,
setPageSize: 1 << 7,
suppressBG: 1 << 8,
suppressCenter: 1 << 9,
suppressCJKFontSubst: 1 << 10,
suppressCropClip: 1 << 1,
suppressRotate: 1 << 12,
suppressTransfer: 1 << 13,
suppressUCR: 1 << 14,
useTrapAnnots: 1 << 15,
usePrintersMarks: 1 << 16,
}),
rasterFlagValues: Object.freeze({
textToOutline: 1,
strokesToOutline: 1 << 1,
allowComplexClip: 1 << 2,
preserveOverprint: 1 << 3,
}),
subsets: Object.freeze({
all: 0,
even: 1,
odd: 2,
}),
tileMarks: Object.freeze({
none: 0,
west: 1,
east: 2,
}),
usages: Object.freeze({
auto: 0,
use: 1,
noUse: 2,
}),
});
this.downloadFarEastFonts = false;
this.fileName = "";
this.firstPage = 0;
this.flags = 0;
this.fontPolicy = 0;
this.gradientDPI = 150;
this.interactive = 1;
this.lastPage = data.lastPage;
this.npUpAutoRotate = false;
this.npUpNumPagesH = 2;
this.npUpNumPagesV = 2;
this.npUpPageBorder = false;
this.npUpPageOrder = 0;
this.pageHandling = 0;
this.pageSubset = 0;
this.printAsImage = false;
this.printContent = 0;
this.printerName = "";
this.psLevel = 0;
this.rasterFlags = 0;
this.reversePages = false;
this.tileLabel = false;
this.tileMark = 0;
this.tileOverlap = 0;
this.tileScale = 1.0;
this.transparencyLevel = 75;
this.usePrinterCRD = 0;
this.useT1Conversion = 0;
}
}

View File

@ -29,9 +29,9 @@ class PDFFindBar {
#resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
constructor(options, mainContainer, eventBus) {
this.opened = false;
opened = false;
constructor(options, mainContainer, eventBus) {
this.bar = options.bar;
this.toggleButton = options.toggleButton;
this.findField = options.findField;

View File

@ -172,8 +172,7 @@ class PDFPageView extends BasePDFPageView {
constructor(options) {
super(options);
const container = options.container;
const defaultViewport = options.defaultViewport;
const { container, defaultViewport } = options;
this.renderingId = "page" + this.id;
this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;

View File

@ -27,19 +27,24 @@ const CLEANUP_TIMEOUT = 30000;
* Controls rendering of the views for pages and thumbnails.
*/
class PDFRenderingQueue {
constructor() {
this.pdfViewer = null;
this.pdfThumbnailViewer = null;
this.onIdle = null;
this.highestPriorityPage = null;
/** @type {number} */
this.idleTimeout = null;
this.printing = false;
this.isThumbnailViewEnabled = false;
#highestPriorityPage = null;
#idleTimeout = null;
#pdfThumbnailViewer = null;
#pdfViewer = null;
isThumbnailViewEnabled = false;
onIdle = null;
printing = false;
constructor() {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
Object.defineProperty(this, "hasViewer", {
value: () => !!this.pdfViewer,
value: () => !!this.#pdfViewer,
});
}
}
@ -48,14 +53,14 @@ class PDFRenderingQueue {
* @param {PDFViewer} pdfViewer
*/
setViewer(pdfViewer) {
this.pdfViewer = pdfViewer;
this.#pdfViewer = pdfViewer;
}
/**
* @param {PDFThumbnailViewer} pdfThumbnailViewer
*/
setThumbnailViewer(pdfThumbnailViewer) {
this.pdfThumbnailViewer = pdfThumbnailViewer;
this.#pdfThumbnailViewer = pdfThumbnailViewer;
}
/**
@ -63,26 +68,26 @@ class PDFRenderingQueue {
* @returns {boolean}
*/
isHighestPriority(view) {
return this.highestPriorityPage === view.renderingId;
return this.#highestPriorityPage === view.renderingId;
}
/**
* @param {Object} currentlyVisiblePages
*/
renderHighestPriority(currentlyVisiblePages) {
if (this.idleTimeout) {
clearTimeout(this.idleTimeout);
this.idleTimeout = null;
if (this.#idleTimeout) {
clearTimeout(this.#idleTimeout);
this.#idleTimeout = null;
}
// Pages have a higher priority than thumbnails, so check them first.
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
if (this.#pdfViewer.forceRendering(currentlyVisiblePages)) {
return;
}
// No pages needed rendering, so check thumbnails.
if (
this.isThumbnailViewEnabled &&
this.pdfThumbnailViewer?.forceRendering()
this.#pdfThumbnailViewer?.forceRendering()
) {
return;
}
@ -93,7 +98,7 @@ class PDFRenderingQueue {
}
if (this.onIdle) {
this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
this.#idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
}
}
@ -202,14 +207,14 @@ class PDFRenderingQueue {
case RenderingStates.FINISHED:
return false;
case RenderingStates.PAUSED:
this.highestPriorityPage = view.renderingId;
this.#highestPriorityPage = view.renderingId;
view.resume();
break;
case RenderingStates.RUNNING:
this.highestPriorityPage = view.renderingId;
this.#highestPriorityPage = view.renderingId;
break;
case RenderingStates.INITIAL:
this.highestPriorityPage = view.renderingId;
this.#highestPriorityPage = view.renderingId;
view
.draw()
.finally(() => {