Skip to content

Commit

Permalink
Refactor: prefer Array.prototype.at() (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Oct 11, 2023
1 parent 2095c42 commit 1402e78
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@
// ***** Functions *****
"unicorn/prefer-default-parameters": "error",

// ***** Loops *****
"unicorn/prefer-array-find": "error",

// ***** Operands *****
"@typescript-eslint/prefer-nullish-coalescing": "error",

// ***** Arrays *****
"unicorn/prefer-array-find": "error",
"unicorn/prefer-at": "error",

// ***** Numbers *****
"unicorn/no-zero-fractions": "error",
"unicorn/number-literal-case": "error",
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu, macos, windows ]
node-version: [ lts/*, lts/-1, 16.3.0 ]
node-version: [ lts/*, lts/-1, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
Expand All @@ -81,7 +81,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ lts/*, lts/-1, 16.3.0 ]
node-version: [ lts/*, lts/-1, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ lts/*, lts/-1, 16.3.0 ]
node-version: [ lts/*, lts/-1, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@
"which": "4.0.0"
},
"//engines": [
"Requires >=14.17.0 for TypeScript v5.1.",
"Requires ^12.20.0 || ^14.13.1 || >=16.0.0 for ES6 modules, even though `tsc` can target ES5 or lower.",
"Requires ^14.18.0 || >=16.0.0 for `node:` prefixed built-in modules that many dependencies use.",
"Requires >=15.0.0 for npm v7 for package-lock.json v3 because Renovate stopped respecting the existing version in August 2023.",
"Requires ^14.18.0 || >=16.3.0 for `os.devNull`."
"Requires ^14.18.0 || >=16.3.0 for `os.devNull`.",
"Requires >=16.16.0 for `Array.prototype.at()`."
],
"engines": {
"node": ">=16.3.0"
"node": ">=16.6.0"
}
}
2 changes: 1 addition & 1 deletion src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class ArgumentsParser {

private static getLastValue<T>(arr: T | T[]): T {
if (Array.isArray(arr) && arr.length) {
return arr[arr.length - 1];
return arr.at(-1) as T;
}
return arr as T;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/datGameInferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class DATGameInferrer extends Module {
}

private static getDatName(file: File): string {
return path.dirname(file.getFilePath()).split(/[\\/]/).slice(-1)[0];
return path.dirname(file.getFilePath()).split(/[\\/]/).at(-1) ?? file.getFilePath();
}

private static createDAT(datName: string, romFiles: File[]): DAT {
Expand Down
2 changes: 1 addition & 1 deletion test/console/progressBarCliSpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class ProgressBarCLISpy {
}

getLastLine(): string {
return this.outputLines[this.outputLines.length - 1];
return this.outputLines.at(-1) ?? '';
}

getLogLine(): string | undefined {
Expand Down

0 comments on commit 1402e78

Please sign in to comment.