From dcd55a71647d9cfc4914a55a27c7df450f78c1b7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 25 Apr 2023 17:19:59 +0200 Subject: [PATCH] Enable `unicorn/prefer-at` unconditionally (PR 15014 follow-up) Now that Node.js version 18 is required, we should be able to use `Array.prototype.at()` everywhere in the code-base. --- external/.eslintrc | 4 ---- external/builder/builder.js | 2 +- external/builder/preprocessor2.js | 4 ++-- external/cmapscompress/compress.js | 2 +- external/cmapscompress/optimize.js | 5 +---- test/test.js | 6 ++---- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/external/.eslintrc b/external/.eslintrc index 0eb7db3175cb4..e3523dce526ed 100644 --- a/external/.eslintrc +++ b/external/.eslintrc @@ -6,8 +6,4 @@ "env": { "node": true, }, - - "rules": { - "unicorn/prefer-at": "off", - }, } diff --git a/external/builder/builder.js b/external/builder/builder.js index 5eb9d70bb08fd..cb56978d9b7f0 100644 --- a/external/builder/builder.js +++ b/external/builder/builder.js @@ -72,7 +72,7 @@ function preprocess(inFilename, outFilename, defines) { ? outFilename : function (line) { if (!line || AllWhitespaceRegexp.test(line)) { - const prevLine = out[out.length - 1]; + const prevLine = out.at(-1); if (!prevLine || AllWhitespaceRegexp.test(prevLine)) { return; // Avoid adding consecutive blank lines. } diff --git a/external/builder/preprocessor2.js b/external/builder/preprocessor2.js index 58177d09b9abc..8833cf323a5fd 100644 --- a/external/builder/preprocessor2.js +++ b/external/builder/preprocessor2.js @@ -244,8 +244,8 @@ function postprocessNode(ctx, node) { const block = node.body; if ( block.body.length > 0 && - block.body[block.body.length - 1].type === "ReturnStatement" && - !block.body[block.body.length - 1].argument + block.body.at(-1).type === "ReturnStatement" && + !block.body.at(-1).argument ) { // Function body ends with return without arg -- removing it. block.body.pop(); diff --git a/external/cmapscompress/compress.js b/external/cmapscompress/compress.js index 2fe83e0780c75..a0bf221bf243c 100644 --- a/external/cmapscompress/compress.js +++ b/external/cmapscompress/compress.js @@ -215,7 +215,7 @@ function parseCMap(binaryData) { }, readHexSigned(size) { const num = this.readHexNumber(size); - const sign = fromHexDigit(num[num.length - 1]) & 1 ? 15 : 0; + const sign = fromHexDigit(num.at(-1)) & 1 ? 15 : 0; let c = 0; let result = ""; for (const digit of num) { diff --git a/external/cmapscompress/optimize.js b/external/cmapscompress/optimize.js index 69840af7d2963..75716059ccdf5 100644 --- a/external/cmapscompress/optimize.js +++ b/external/cmapscompress/optimize.js @@ -151,10 +151,7 @@ exports.optimizeCMap = function (data) { const maxDistance = 100, minItems = 10, itemsPerBucket = 50; - if ( - subitems.length > minItems && - codes[codes.length - 1] - codes[0] > maxDistance - ) { + if (subitems.length > minItems && codes.at(-1) - codes[0] > maxDistance) { const gapsCount = Math.max(2, (subitems.length / itemsPerBucket) | 0); const gaps = []; for (let q = 0; q < gapsCount; q++) { diff --git a/test/test.js b/test/test.js index 4eae960f8865b..504c98e12ad01 100644 --- a/test/test.js +++ b/test/test.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable no-var, unicorn/prefer-at */ +/* eslint-disable no-var */ "use strict"; @@ -750,9 +750,7 @@ function refTestPostHandler(req, res) { }); } - var isDone = - taskResults[taskResults.length - 1] && - taskResults[taskResults.length - 1][lastPageNum - 1]; + var isDone = taskResults.at(-1) && taskResults.at(-1)[lastPageNum - 1]; if (isDone) { checkRefTestResults(browser, id, taskResults); session.remaining--;