Skip to content

Commit

Permalink
Enable unicorn/prefer-at unconditionally (PR 15014 follow-up)
Browse files Browse the repository at this point in the history
Now that Node.js version 18 is required, we should be able to use `Array.prototype.at()` everywhere in the code-base.
  • Loading branch information
Snuffleupagus committed May 7, 2023
1 parent f79f48c commit dcd55a7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
4 changes: 0 additions & 4 deletions external/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
"env": {
"node": true,
},

"rules": {
"unicorn/prefer-at": "off",
},
}
2 changes: 1 addition & 1 deletion external/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
4 changes: 2 additions & 2 deletions external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion external/cmapscompress/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions external/cmapscompress/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
6 changes: 2 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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--;
Expand Down

0 comments on commit dcd55a7

Please sign in to comment.