1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Enable the unicorn/prefer-at ESLint plugin rule (PR 15008 follow-up)

Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-at.md
This commit is contained in:
Jonas Jenwald 2022-06-09 12:53:39 +02:00
parent 5d88233fbb
commit 9ac4536693
32 changed files with 56 additions and 46 deletions

View file

@ -182,7 +182,7 @@ class Builder {
}
const prefixStack = this._namespacePrefixes.get(prefix);
if (prefixStack && prefixStack.length > 0) {
return prefixStack[prefixStack.length - 1];
return prefixStack.at(-1);
}
warn(`Unknown namespace prefix: ${prefix}.`);

View file

@ -32,7 +32,7 @@ class DataHandler {
const stack = [[-1, this.data[$getChildren]()]];
while (stack.length > 0) {
const last = stack[stack.length - 1];
const last = stack.at(-1);
const [i, children] = last;
if (i + 1 === children.length) {
stack.pop();

View file

@ -354,7 +354,7 @@ class SimpleExprParser {
return [tok, this.getNode()];
case TOKEN.leftParen:
if (this.last === OPERAND) {
const lastOperand = this.operands[this.operands.length - 1];
const lastOperand = this.operands.at(-1);
if (!(lastOperand instanceof AstIdentifier)) {
return [tok, this.getNode()];
}
@ -525,7 +525,7 @@ class SimpleExprParser {
flushWithOperator(op) {
while (true) {
const top = this.operators[this.operators.length - 1];
const top = this.operators.at(-1);
if (top) {
if (top.id >= 0 && SimpleExprParser.checkPrecedence(top, op)) {
this.operators.pop();

View file

@ -562,7 +562,7 @@ function isPrintOnly(node) {
function getCurrentPara(node) {
const stack = node[$getTemplateRoot]()[$extra].paraStack;
return stack.length ? stack[stack.length - 1] : null;
return stack.length ? stack.at(-1) : null;
}
function setPara(node, nodeStyle, value) {

View file

@ -100,7 +100,7 @@ function parseExpression(expr, dotDotAllowed, noExpr = true) {
warn("XFA - Invalid index in SOM expression");
return null;
}
parsed[parsed.length - 1].index = parseIndex(match[0]);
parsed.at(-1).index = parseIndex(match[0]);
pos += match[0].length + 1;
continue;
}

View file

@ -910,7 +910,7 @@ class Border extends XFAObject {
if (!this[$extra]) {
const edges = this.edge.children.slice();
if (edges.length < 4) {
const defaultEdge = edges[edges.length - 1] || new Edge({});
const defaultEdge = edges.at(-1) || new Edge({});
for (let i = edges.length; i < 4; i++) {
edges.push(defaultEdge);
}
@ -950,7 +950,7 @@ class Border extends XFAObject {
if (this.corner.children.some(node => node.radius !== 0)) {
const cornerStyles = this.corner.children.map(node => node[$toStyle]());
if (cornerStyles.length === 2 || cornerStyles.length === 3) {
const last = cornerStyles[cornerStyles.length - 1];
const last = cornerStyles.at(-1);
for (let i = cornerStyles.length; i < 4; i++) {
cornerStyles.push(last);
}

View file

@ -102,7 +102,7 @@ class FontSelector {
}
pushData(xfaFont, margin, lineHeight) {
const lastFont = this.stack[this.stack.length - 1];
const lastFont = this.stack.at(-1);
for (const name of [
"typeface",
"posture",
@ -139,7 +139,7 @@ class FontSelector {
}
topFont() {
return this.stack[this.stack.length - 1];
return this.stack.at(-1);
}
}

View file

@ -500,7 +500,7 @@ class P extends XhtmlObject {
[$text]() {
const siblings = this[$getParent]()[$getChildren]();
if (siblings[siblings.length - 1] === this) {
if (siblings.at(-1) === this) {
return super[$text]();
}
return super[$text]() + "\n";