Skip to content

Commit 20305fb

Browse files
authored
Update eslint-plugin-unicorn to v49 (#1974)
1 parent 372f6b8 commit 20305fb

18 files changed

+71
-70
lines changed

lib/rules/no-array-prototype-extensions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function variableNameToWords(name) {
148148

149149
// camelCase, PascalCase.
150150
return name
151-
.replace(/([A-Z])/g, ' $1')
151+
.replaceAll(/([A-Z])/g, ' $1')
152152
.toLowerCase()
153153
.trim()
154154
.split(' ');
@@ -686,7 +686,7 @@ module.exports = {
686686
const nameParts = name.split('.');
687687
if (
688688
KNOWN_NON_ARRAY_FUNCTION_CALLS.has(name) ||
689-
KNOWN_NON_ARRAY_OBJECTS.has(nameParts[nameParts.length - 2])
689+
KNOWN_NON_ARRAY_OBJECTS.has(nameParts.at(-2))
690690
) {
691691
// Ignore any known non-array objects/function calls to reduce false positives.
692692
return;
@@ -695,8 +695,8 @@ module.exports = {
695695
for (const functionName of FN_NAMES_TO_KNOWN_NON_ARRAY_WORDS.keys()) {
696696
const words = FN_NAMES_TO_KNOWN_NON_ARRAY_WORDS.get(functionName);
697697
if (
698-
nameParts[nameParts.length - 1] === `${functionName}()` &&
699-
variableNameToWords(nameParts[nameParts.length - 2]).some((word) => words.has(word))
698+
nameParts.at(-1) === `${functionName}()` &&
699+
variableNameToWords(nameParts.at(-2)).some((word) => words.has(word))
700700
) {
701701
// We found a function call on a variable whose name contains a word that indicates this variable is not an array.
702702
return;

lib/rules/no-arrow-function-computed-properties.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = {
6666
includeMacro: true,
6767
}) &&
6868
node.arguments.length > 0 &&
69-
types.isArrowFunctionExpression(node.arguments[node.arguments.length - 1]);
69+
types.isArrowFunctionExpression(node.arguments.at(-1));
7070

7171
if (!isComputedArrow) {
7272
return;
@@ -75,13 +75,13 @@ module.exports = {
7575
if (onlyThisContexts) {
7676
if (isThisPresent) {
7777
context.report({
78-
node: node.arguments[node.arguments.length - 1],
78+
node: node.arguments.at(-1),
7979
message: ERROR_MESSAGE,
8080
});
8181
}
8282
} else {
8383
context.report({
84-
node: node.arguments[node.arguments.length - 1],
84+
node: node.arguments.at(-1),
8585
message: ERROR_MESSAGE,
8686
});
8787
}

lib/rules/no-deprecated-router-transition-methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module.exports = {
141141
ClassExpression: onClassEnter,
142142
CallExpression(node) {
143143
if (emberUtils.isAnyEmberCoreModule(context, node)) {
144-
const lastExtendArg = node.arguments[node.arguments.length - 1];
144+
const lastExtendArg = node.arguments.at(-1);
145145

146146
if (lastExtendArg && lastExtendArg.type === 'ObjectExpression') {
147147
const classMembers = lastExtendArg.properties;

lib/rules/no-get.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,23 @@ function convertLiteralTypePath({
505505
return null;
506506
}
507507

508-
let replacementPath = shouldIgnoreOptionalChaining ? path : path.replace(/\./g, '?.');
508+
let replacementPath = shouldIgnoreOptionalChaining ? path : path.replaceAll('.', '?.');
509509

510510
// Replace any array element access (foo.1 => foo[1] or foo?.[1]).
511511
replacementPath = replacementPath
512-
.replace(/\.(\d+)/g, shouldIgnoreOptionalChaining ? '[$1]' : '.[$1]') // Usages in middle of path.
512+
.replaceAll(/\.(\d+)/g, shouldIgnoreOptionalChaining ? '[$1]' : '.[$1]') // Usages in middle of path.
513513
.replace(/^(\d+)\??\./, shouldIgnoreOptionalChaining ? '[$1].' : '[$1]?.') // Usage at beginning of path.
514514
.replace(/^(\d+)$/, '[$1]'); // Usage as entire string.
515515

516516
// Replace any array element access using `firstObject` and `lastObject` (foo.firstObject => foo[0] or foo?.[0]).
517517
replacementPath = replacementPath
518-
.replace(/\.firstObject/g, shouldIgnoreOptionalChaining ? '[0]' : '.[0]') // When `firstObject` is used in the middle of the path. e.g. foo.firstObject
518+
.replaceAll('.firstObject', shouldIgnoreOptionalChaining ? '[0]' : '.[0]') // When `firstObject` is used in the middle of the path. e.g. foo.firstObject
519519
.replace(/^firstObject\??\./, shouldIgnoreOptionalChaining ? '[0].' : '[0]?.') // When `firstObject` is used at the beginning of the path. e.g. firstObject.bar
520520
.replace(/^firstObject$/, '[0]'); // When `firstObject` is used as the entire path.
521521

522522
// eslint-disable-next-line unicorn/prefer-ternary
523523
if (useAt) {
524-
replacementPath = replacementPath.replace(/lastObject/g, 'at(-1)');
524+
replacementPath = replacementPath.replaceAll('lastObject', 'at(-1)');
525525
} else {
526526
replacementPath = replacementPath
527527
.replace(

lib/rules/no-implicit-injections.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ module.exports = {
143143
});
144144

145145
const modulePropertyDeclarations =
146-
node.type === 'CallExpression'
147-
? node.arguments[node.arguments.length - 1].properties
148-
: node.body.body;
146+
node.type === 'CallExpression' ? node.arguments.at(-1).properties : node.body.body;
149147

150148
// Get Services that don't have properties/service injections declared
151149
configToCheckFor = modulePropertyDeclarations.reduce((accum, n) => {
@@ -192,7 +190,7 @@ module.exports = {
192190
ClassExpression: onClassEnter,
193191
CallExpression(node) {
194192
if (emberUtils.isAnyEmberCoreModule(context, node) && emberUtils.isExtendObject(node)) {
195-
const lastExtendArg = node.arguments[node.arguments.length - 1];
193+
const lastExtendArg = node.arguments.at(-1);
196194

197195
if (lastExtendArg && lastExtendArg.type === 'ObjectExpression') {
198196
onModuleFound(node);

lib/rules/no-invalid-dependent-keys.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ module.exports = {
107107
message: ERROR_MESSAGE_UNNECESSARY_BRACES,
108108
fix(fixer) {
109109
const nodeText = sourceCode.getText(node);
110-
return fixer.replaceText(node, nodeText.replace(REGEXP_UNNECESSARY_BRACES, '$1'));
110+
return fixer.replaceText(
111+
node,
112+
nodeText.replaceAll(REGEXP_UNNECESSARY_BRACES, '$1')
113+
);
111114
},
112115
});
113116
}
@@ -151,7 +154,7 @@ module.exports = {
151154
message: ERROR_MESSAGE_INVALID_CHARACTER,
152155
fix(fixer) {
153156
const nodeText = sourceCode.getText(node);
154-
return fixer.replaceText(node, nodeText.replace(/ /g, '')); // Remove all spaces.
157+
return fixer.replaceText(node, nodeText.replaceAll(' ', '')); // Remove all spaces.
155158
},
156159
});
157160
}

lib/rules/no-restricted-resolver-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function getLastArgument(node) {
6565
(ancestor) => ancestor.type === 'CallExpression'
6666
);
6767
const args = ancestorMethodCall.arguments;
68-
const lastArgument = args[args.length - 1];
68+
const lastArgument = args.at(-1);
6969

7070
return lastArgument;
7171
}

lib/rules/no-shadow-route-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function getPropertyByKeyName(objectExpression, keyName) {
190190
}
191191

192192
function trimRootLevelNestedRoutes(routesPath) {
193-
return routesPath.replace(ROOT_PATH_TRIM_REGEX, URL_CHUNK_SEPARATOR);
193+
return routesPath.replaceAll(ROOT_PATH_TRIM_REGEX, URL_CHUNK_SEPARATOR);
194194
}
195195

196196
function convertPathToGenericForMatching(routePathInfos) {

lib/rules/require-computed-macros.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,9 @@ module.exports = {
255255

256256
let getterBody;
257257
let nodeToReport;
258-
if (
259-
node.arguments.length > 0 &&
260-
types.isFunctionExpression(node.arguments[node.arguments.length - 1])
261-
) {
258+
if (node.arguments.length > 0 && types.isFunctionExpression(node.arguments.at(-1))) {
262259
// Example: computed('dependentKey', function() { return this.x })
263-
getterBody = node.arguments[node.arguments.length - 1].body.body;
260+
getterBody = node.arguments.at(-1).body.body;
264261
nodeToReport = node;
265262
} else if (
266263
includeNativeGetters &&

lib/rules/require-computed-property-dependencies.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ module.exports = {
365365
].join(', ');
366366

367367
if (nodeArguments.length > 0) {
368-
const lastArg = node.arguments[node.arguments.length - 1];
368+
const lastArg = node.arguments.at(-1);
369369
if (computedPropertyUtils.isComputedPropertyBodyArg(lastArg)) {
370370
if (node.arguments.length > 1) {
371371
const firstDependency = node.arguments[0];
372-
const lastDependency = node.arguments[node.arguments.length - 2];
372+
const lastDependency = node.arguments.at(-2);
373373

374374
// Replace the dependent keys before the function body argument.
375375
// Before: computed('first', function() {})

0 commit comments

Comments
 (0)