From 96e34fbb7d7bb556392646a7a6720182953ac275 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 21 Mar 2023 11:37:46 +0100 Subject: [PATCH] Enable the `unicorn/prefer-negative-index` ESLint plugin rule Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-negative-index.md --- .eslintrc | 1 + src/core/core_utils.js | 4 ++-- src/core/type1_parser.js | 2 +- src/core/xfa/utils.js | 2 +- src/core/xfa/xfa_object.js | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5418053e4..69e14e7c8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -59,6 +59,7 @@ "unicorn/prefer-dom-node-remove": "error", "unicorn/prefer-logical-operator-over-ternary": "error", "unicorn/prefer-modern-dom-apis": "error", + "unicorn/prefer-negative-index": "error", "unicorn/prefer-regexp-test": "error", "unicorn/prefer-string-replace-all": "error", "unicorn/prefer-string-starts-ends-with": "error", diff --git a/src/core/core_utils.js b/src/core/core_utils.js index 3e6f64adf..fd16b2373 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -471,12 +471,12 @@ function validateCSSFont(cssFontInfo) { // See https://developer.mozilla.org/en-US/docs/Web/CSS/string. if (/^".*"$/.test(fontFamily)) { - if (/[^\\]"/.test(fontFamily.slice(1, fontFamily.length - 1))) { + if (/[^\\]"/.test(fontFamily.slice(1, -1))) { warn(`XFA - FontFamily contains some unescaped ": ${fontFamily}.`); return false; } } else if (/^'.*'$/.test(fontFamily)) { - if (/[^\\]'/.test(fontFamily.slice(1, fontFamily.length - 1))) { + if (/[^\\]'/.test(fontFamily.slice(1, -1))) { warn(`XFA - FontFamily contains some unescaped ': ${fontFamily}.`); return false; } diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js index ca5c78bba..13d04396f 100644 --- a/src/core/type1_parser.js +++ b/src/core/type1_parser.js @@ -265,7 +265,7 @@ class Type1CharString { subrNumber = this.stack.pop(); const numArgs = this.stack.pop(); if (subrNumber === 0 && numArgs === 3) { - const flexArgs = this.stack.splice(this.stack.length - 17, 17); + const flexArgs = this.stack.splice(-17, 17); this.stack.push( flexArgs[2] + flexArgs[0], // bcp1x + rpx flexArgs[3] + flexArgs[1], // bcp1y + rpy diff --git a/src/core/xfa/utils.js b/src/core/xfa/utils.js index 5d5cf4cc7..5f93bd458 100644 --- a/src/core/xfa/utils.js +++ b/src/core/xfa/utils.js @@ -26,7 +26,7 @@ const measurementPattern = /([+-]?\d+\.?\d*)(.*)/; function stripQuotes(str) { if (str.startsWith("'") || str.startsWith('"')) { - return str.slice(1, str.length - 1); + return str.slice(1, -1); } return str; } diff --git a/src/core/xfa/xfa_object.js b/src/core/xfa/xfa_object.js index 30f6cfd2a..ee49d2b3c 100644 --- a/src/core/xfa/xfa_object.js +++ b/src/core/xfa/xfa_object.js @@ -481,9 +481,9 @@ class XFAObject { // - URI // For now we don't handle URI other than "." (current document). if (usehref.startsWith("#som(") && usehref.endsWith(")")) { - somExpression = usehref.slice("#som(".length, usehref.length - 1); + somExpression = usehref.slice("#som(".length, -1); } else if (usehref.startsWith(".#som(") && usehref.endsWith(")")) { - somExpression = usehref.slice(".#som(".length, usehref.length - 1); + somExpression = usehref.slice(".#som(".length, -1); } else if (usehref.startsWith("#")) { id = usehref.slice(1); } else if (usehref.startsWith(".#")) {