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.
This commit is contained in:
Jonas Jenwald 2023-04-25 17:19:59 +02:00
parent f79f48c2b4
commit dcd55a7164
6 changed files with 7 additions and 16 deletions

4
external/.eslintrc vendored
View File

@ -6,8 +6,4 @@
"env": { "env": {
"node": true, "node": true,
}, },
"rules": {
"unicorn/prefer-at": "off",
},
} }

View File

@ -72,7 +72,7 @@ function preprocess(inFilename, outFilename, defines) {
? outFilename ? outFilename
: function (line) { : function (line) {
if (!line || AllWhitespaceRegexp.test(line)) { if (!line || AllWhitespaceRegexp.test(line)) {
const prevLine = out[out.length - 1]; const prevLine = out.at(-1);
if (!prevLine || AllWhitespaceRegexp.test(prevLine)) { if (!prevLine || AllWhitespaceRegexp.test(prevLine)) {
return; // Avoid adding consecutive blank lines. return; // Avoid adding consecutive blank lines.
} }

View File

@ -244,8 +244,8 @@ function postprocessNode(ctx, node) {
const block = node.body; const block = node.body;
if ( if (
block.body.length > 0 && block.body.length > 0 &&
block.body[block.body.length - 1].type === "ReturnStatement" && block.body.at(-1).type === "ReturnStatement" &&
!block.body[block.body.length - 1].argument !block.body.at(-1).argument
) { ) {
// Function body ends with return without arg -- removing it. // Function body ends with return without arg -- removing it.
block.body.pop(); block.body.pop();

View File

@ -215,7 +215,7 @@ function parseCMap(binaryData) {
}, },
readHexSigned(size) { readHexSigned(size) {
const num = this.readHexNumber(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 c = 0;
let result = ""; let result = "";
for (const digit of num) { for (const digit of num) {

View File

@ -151,10 +151,7 @@ exports.optimizeCMap = function (data) {
const maxDistance = 100, const maxDistance = 100,
minItems = 10, minItems = 10,
itemsPerBucket = 50; itemsPerBucket = 50;
if ( if (subitems.length > minItems && codes.at(-1) - codes[0] > maxDistance) {
subitems.length > minItems &&
codes[codes.length - 1] - codes[0] > maxDistance
) {
const gapsCount = Math.max(2, (subitems.length / itemsPerBucket) | 0); const gapsCount = Math.max(2, (subitems.length / itemsPerBucket) | 0);
const gaps = []; const gaps = [];
for (let q = 0; q < gapsCount; q++) { for (let q = 0; q < gapsCount; q++) {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-var, unicorn/prefer-at */ /* eslint-disable no-var */
"use strict"; "use strict";
@ -750,9 +750,7 @@ function refTestPostHandler(req, res) {
}); });
} }
var isDone = var isDone = taskResults.at(-1) && taskResults.at(-1)[lastPageNum - 1];
taskResults[taskResults.length - 1] &&
taskResults[taskResults.length - 1][lastPageNum - 1];
if (isDone) { if (isDone) {
checkRefTestResults(browser, id, taskResults); checkRefTestResults(browser, id, taskResults);
session.remaining--; session.remaining--;