Skip to content

Commit

Permalink
Update dependencies, fix expiring-todo-comments (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 22, 2023
1 parent 6d15a02 commit fa431ff
Show file tree
Hide file tree
Showing 32 changed files with 61 additions and 56 deletions.
30 changes: 15 additions & 15 deletions package.json
Expand Up @@ -46,7 +46,7 @@
"xo"
],
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"@eslint-community/eslint-utils": "^4.4.0",
"ci-info": "^3.8.0",
"clean-regexp": "^1.0.0",
Expand All @@ -63,37 +63,37 @@
"strip-indent": "^3.0.0"
},
"devDependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/core": "^7.22.8",
"@babel/eslint-parser": "^7.22.7",
"@babel/code-frame": "^7.22.13",
"@babel/core": "^7.22.20",
"@babel/eslint-parser": "^7.22.15",
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^6.2.0",
"@typescript-eslint/parser": "^6.7.2",
"ava": "^3.15.0",
"c8": "^8.0.0",
"c8": "^8.0.1",
"chalk": "^5.3.0",
"enquirer": "^2.3.6",
"eslint": "^8.44.0",
"enquirer": "^2.4.1",
"eslint": "^8.49.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-doc-generator": "^1.4.3",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-eslint-plugin": "^5.1.1",
"eslint-plugin-internal-rules": "file:./scripts/internal-rules/",
"eslint-remote-tester": "^3.0.0",
"eslint-remote-tester-repositories": "^1.0.1",
"execa": "^7.1.1",
"execa": "^8.0.1",
"listr": "^0.14.3",
"lodash-es": "^4.17.21",
"markdownlint-cli": "^0.35.0",
"markdownlint-cli": "^0.37.0",
"mem": "^9.0.2",
"npm-package-json-lint": "^7.0.0",
"npm-run-all": "^4.1.5",
"outdent": "^0.8.0",
"typescript": "^5.1.6",
"typescript": "^5.2.2",
"vue-eslint-parser": "^9.3.1",
"xo": "^0.54.2",
"yaml": "^2.3.1"
"xo": "^0.56.0",
"yaml": "^2.3.2"
},
"peerDependencies": {
"eslint": ">=8.44.0"
"eslint": ">=8.49.0"
},
"ava": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion rules/catch-error-name.js
Expand Up @@ -62,7 +62,7 @@ const create = context => {

if (
isNameAllowed(originalName)
|| isNameAllowed(originalName.replace(/_+$/g, ''))
|| isNameAllowed(originalName.replaceAll(/_+$/g, ''))
) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/consistent-destructuring.js
Expand Up @@ -89,7 +89,7 @@ const create = context => {
&& property.key.type === 'Identifier'
&& property.value.type === 'Identifier',
);
const lastProperty = objectPattern.properties[objectPattern.properties.length - 1];
const lastProperty = objectPattern.properties.at(-1);

const hasRest = lastProperty && lastProperty.type === 'RestElement';

Expand Down Expand Up @@ -134,7 +134,7 @@ const create = context => {
},
* fix(fixer) {
const {properties} = objectPattern;
const lastProperty = properties[properties.length - 1];
const lastProperty = properties.at(-1);

yield fixer.replaceText(node, newMember);

Expand Down
19 changes: 12 additions & 7 deletions rules/expiring-todo-comments.js
Expand Up @@ -284,13 +284,18 @@ const create = context => {
// This is highly dependable on ESLint's `no-warning-comments` implementation.
// What we do is patch the parts we know the rule will use, `getAllComments`.
// Since we have priority, we leave only the comments that we didn't use.
const fakeContext = {
...context,
sourceCode: {
...sourceCode,
getAllComments: () => options.allowWarningComments ? [] : unusedComments,
const fakeContext = new Proxy(context, {
get(target, property, receiver) {
if (property === 'sourceCode') {
return {
...sourceCode,
getAllComments: () => options.allowWarningComments ? [] : unusedComments,
};
}

return Reflect.get(target, property, receiver);
},
};
});
const rules = baseRule.create(fakeContext);

function processComment(comment) {
Expand Down Expand Up @@ -485,7 +490,7 @@ const create = context => {
}
}

const withoutWhitespace = unknown.replace(/ /g, '');
const withoutWhitespace = unknown.replaceAll(' ', '');

if (parseArgument(withoutWhitespace).type !== 'unknowns') {
uses++;
Expand Down
2 changes: 1 addition & 1 deletion rules/fix/remove-argument.js
Expand Up @@ -7,7 +7,7 @@ function removeArgument(fixer, node, sourceCode) {
const index = callExpression.arguments.indexOf(node);
const parentheses = getParentheses(node, sourceCode);
const firstToken = parentheses[0] || node;
const lastToken = parentheses[parentheses.length - 1] || node;
const lastToken = parentheses.at(-1) || node;

let [start] = firstToken.range;
let [, end] = lastToken.range;
Expand Down
2 changes: 1 addition & 1 deletion rules/no-array-for-each.js
Expand Up @@ -400,7 +400,7 @@ const create = context => {
});

context.on('ReturnStatement', node => {
const currentFunction = functionStack[functionStack.length - 1];
const currentFunction = functionStack.at(-1);
if (!currentFunction) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-array-method-this-argument.js
Expand Up @@ -83,7 +83,7 @@ function useBoundFunction(callExpression, sourceCode) {
const callbackParentheses = getParentheses(callback, sourceCode);
const isParenthesized = callbackParentheses.length > 0;
const callbackLastToken = isParenthesized
? callbackParentheses[callbackParentheses.length - 1]
? callbackParentheses.at(-1)
: callback;
if (
!isParenthesized
Expand Down
2 changes: 1 addition & 1 deletion rules/no-console-spaces.js
Expand Up @@ -11,7 +11,7 @@ const messages = {
const hasLeadingSpace = value => value.length > 1 && value.charAt(0) === ' ' && value.charAt(1) !== ' ';

// Find exactly one trailing space, allow exactly one space
const hasTrailingSpace = value => value.length > 1 && value.charAt(value.length - 1) === ' ' && value.charAt(value.length - 2) !== ' ';
const hasTrailingSpace = value => value.length > 1 && value.at(-1) === ' ' && value.at(-2) !== ' ';

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
Expand Down
2 changes: 1 addition & 1 deletion rules/no-hex-escape.js
Expand Up @@ -8,7 +8,7 @@ const messages = {
};

function checkEscape(context, node, value) {
const fixedValue = value.replace(/(?<=(?:^|[^\\])(?:\\\\)*\\)x/g, 'u00');
const fixedValue = value.replaceAll(/(?<=(?:^|[^\\])(?:\\\\)*\\)x/g, 'u00');

if (value !== fixedValue) {
return {
Expand Down
2 changes: 1 addition & 1 deletion rules/no-unnecessary-await.js
Expand Up @@ -30,7 +30,7 @@ function notPromise(node) {
}

case 'SequenceExpression': {
return notPromise(node.expressions[node.expressions.length - 1]);
return notPromise(node.expressions.at(-1));
}

// No default
Expand Down
2 changes: 1 addition & 1 deletion rules/no-useless-switch-case.js
Expand Up @@ -25,7 +25,7 @@ const create = context => ({
const [defaultCase] = defaultCases;

// We only check cases where the last case is the `default` case
if (defaultCase !== cases[cases.length - 1]) {
if (defaultCase !== cases.at(-1)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/no-useless-undefined.js
Expand Up @@ -236,7 +236,7 @@ const create = context => {
}

const firstUndefined = undefinedArguments[0];
const lastUndefined = undefinedArguments[undefinedArguments.length - 1];
const lastUndefined = undefinedArguments.at(-1);

return {
messageId,
Expand Down
2 changes: 1 addition & 1 deletion rules/no-zero-fractions.js
Expand Up @@ -28,7 +28,7 @@ const create = context => ({
}

const {before, dotAndFractions, after} = match.groups;
const fixedDotAndFractions = dotAndFractions.replace(/[.0_]+$/g, '');
const fixedDotAndFractions = dotAndFractions.replaceAll(/[.0_]+$/g, '');
const formatted = ((before + fixedDotAndFractions) || '0') + after;

if (formatted === raw) {
Expand Down
2 changes: 1 addition & 1 deletion rules/numeric-separators-style.js
Expand Up @@ -111,7 +111,7 @@ const create = context => {
suffix = 'n';
}

const strippedNumber = number.replace(/_/g, '');
const strippedNumber = number.replaceAll('_', '');
const {prefix, data} = numeric.getPrefix(strippedNumber);

const {onlyIfContainsSeparator} = options[prefix.toLowerCase()];
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-default-parameters.js
Expand Up @@ -72,7 +72,7 @@ const hasExtraReferences = (assignment, references, left) => {
};

const isLastParameter = (parameters, parameter) => {
const lastParameter = parameters[parameters.length - 1];
const lastParameter = parameters.at(-1);

// See 'default-param-last' rule
return parameter && parameter === lastParameter;
Expand Down Expand Up @@ -122,7 +122,7 @@ const create = context => {
const functionStack = [];

const checkExpression = (node, left, right, assignment) => {
const currentFunction = functionStack[functionStack.length - 1];
const currentFunction = functionStack.at(-1);

if (!currentFunction || !isDefaultExpression(left, right)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-dom-node-dataset.js
Expand Up @@ -12,7 +12,7 @@ const messages = {
[MESSAGE_ID]: 'Prefer `.dataset` over `{{method}}(…)`.',
};

const dashToCamelCase = string => string.replace(/-[a-z]/g, s => s[1].toUpperCase());
const dashToCamelCase = string => string.replaceAll(/-[a-z]/g, s => s[1].toUpperCase());

function getFix(callExpression, context) {
const method = callExpression.callee.property.name;
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-export-from.js
Expand Up @@ -148,7 +148,7 @@ function getFixFunction({
}

if (exportDeclaration) {
const lastSpecifier = exportDeclaration.specifiers[exportDeclaration.specifiers.length - 1];
const lastSpecifier = exportDeclaration.specifiers.at(-1);

// `export {} from 'foo';`
if (lastSpecifier) {
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-object-from-entries.js
Expand Up @@ -99,7 +99,7 @@ function fixReduceAssignOrSpread({sourceCode, callExpression, property}) {
const initObject = callExpression.arguments[1];
const parentheses = getParentheses(initObject, sourceCode);
const firstToken = parentheses[0] || initObject;
const lastToken = parentheses[parentheses.length - 1] || initObject;
const lastToken = parentheses.at(-1) || initObject;
const startToken = sourceCode.getTokenBefore(firstToken);
const [start] = startToken.range;
const [, end] = lastToken.range;
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-query-selector.js
Expand Up @@ -18,7 +18,7 @@ const getReplacementForClass = value => value.match(/\S+/g).map(className => `.$

const getQuotedReplacement = (node, value) => {
const leftQuote = node.raw.charAt(0);
const rightQuote = node.raw.charAt(node.raw.length - 1);
const rightQuote = node.raw.at(-1);
return `${leftQuote}${value}${rightQuote}`;
};

Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-spread.js
Expand Up @@ -74,7 +74,7 @@ function fixConcat(node, sourceCode, fixableArguments) {
const getFixedText = () => {
const nonEmptyArguments = fixableArguments
.filter(({node, isArrayLiteral}) => (!isArrayLiteral || node.elements.length > 0));
const lastArgument = nonEmptyArguments[nonEmptyArguments.length - 1];
const lastArgument = nonEmptyArguments.at(-1);

let text = nonEmptyArguments
.map(({node, isArrayLiteral, isSpreadable, testArgument}) => {
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-switch.js
Expand Up @@ -191,7 +191,7 @@ function fix({discriminant, ifStatements}, sourceCode, options) {
const indent = getIndentString(firstStatement, sourceCode);
yield fixer.insertTextBefore(firstStatement, `switch (${discriminantText}) {`);

const lastStatement = ifStatements[ifStatements.length - 1].statement;
const lastStatement = ifStatements.at(-1).statement;
if (lastStatement.alternate) {
const {alternate} = lastStatement;
yield fixer.insertTextBefore(alternate, `\n${indent}default: `);
Expand Down
2 changes: 1 addition & 1 deletion rules/template-indent.js
Expand Up @@ -79,7 +79,7 @@ const create = context => {
}

const dedented = stripIndent(joined);
const trimmed = dedented.replace(new RegExp(`^${eol}|${eol}[ \t]*$`, 'g'), '');
const trimmed = dedented.replaceAll(new RegExp(`^${eol}|${eol}[ \t]*$`, 'g'), '');

const fixed
= eol
Expand Down
2 changes: 1 addition & 1 deletion rules/utils/escape-template-element-raw.js
@@ -1,6 +1,6 @@
'use strict';

module.exports = string => string.replace(
module.exports = string => string.replaceAll(
/(?<=(?:^|[^\\])(?:\\\\)*)(?<symbol>(?:`|\$(?={)))/g,
'\\$<symbol>',
);
2 changes: 1 addition & 1 deletion rules/utils/is-number.js
Expand Up @@ -209,7 +209,7 @@ function isNumber(node, scope) {
}

case 'SequenceExpression': {
if (isNumber(node.expressions[node.expressions.length - 1], scope)) {
if (isNumber(node.expressions.at(-1), scope)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/utils/parentheses.js
Expand Up @@ -48,7 +48,7 @@ Get the parenthesized range of the node.
function getParenthesizedRange(node, sourceCode) {
const parentheses = getParentheses(node, sourceCode);
const [start] = (parentheses[0] || node).range;
const [, end] = (parentheses[parentheses.length - 1] || node).range;
const [, end] = (parentheses.at(-1) || node).range;
return [start, end];
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/create-rule.mjs
Expand Up @@ -55,7 +55,7 @@ function updateRecommended(id) {
let insertIndex;
if (ruleContent.localeCompare(unicornRuleLines[0]) === -1) {
insertIndex = 0;
} else if (ruleContent.localeCompare(unicornRuleLines[unicornRuleLines.length - 1]) === 1) {
} else if (ruleContent.localeCompare(unicornRuleLines.at(-1)) === 1) {
insertIndex = lines.length;
lines[lines.length - 1] += ',';
ruleContent = ruleContent.slice(0, -1);
Expand Down
2 changes: 1 addition & 1 deletion test/expiring-todo-comments.mjs
Expand Up @@ -35,7 +35,7 @@ const avoidMultiplePackageVersionsError = (versions, message) => ({
});

const removeWhitespaceError = (argument, message) => ({
message: `Avoid using whitespace on TODO argument. On '${argument}' use '${argument.replace(/ /g, '')}'. ${message}`,
message: `Avoid using whitespace on TODO argument. On '${argument}' use '${argument.replaceAll(' ', '')}'. ${message}`,
});

const missingAtSymbolError = (bad, good, message) => ({
Expand Down
2 changes: 1 addition & 1 deletion test/package.mjs
Expand Up @@ -135,7 +135,7 @@ test('validate configuration', async t => {
const recommendedEnvironments = Object.keys(eslintPluginUnicorn.configs.recommended.env);
t.is(recommendedEnvironments.length, 1);
t.is(
availableEnvironments[availableEnvironments.length - 1],
availableEnvironments.at(-1),
recommendedEnvironments[0],
'env should be the latest es version',
);
Expand Down
2 changes: 1 addition & 1 deletion test/prefer-modern-math-apis.mjs
Expand Up @@ -7,7 +7,7 @@ const {test} = getTester(import.meta);
const duplicateLog10Test = code => [
code,
// `Math.log2()` test
code.replace(/Math\.LOG10E/g, 'Math.LOG2E').replace(/Math\.LN10/g, 'Math.LN2'),
code.replaceAll('Math.LOG10E', 'Math.LOG2E').replaceAll('Math.LN10', 'Math.LN2'),
];
test.snapshot({
valid: [
Expand Down
4 changes: 2 additions & 2 deletions test/prefer-ternary.mjs
Expand Up @@ -523,13 +523,13 @@ test({
throw new TypeError('a');
}
}
`.replace(/\t/g, ' '),
`.replaceAll('\t', ' '),
output: outdent`
function unicorn() {
const error = test ? new Error('a') : new TypeError('a');
throw error;
}
`.replace(/\t/g, ' '),
`.replaceAll('\t', ' '),
errors,
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/template-indent.mjs
Expand Up @@ -9,8 +9,8 @@ import {getTester} from './utils/test.mjs';
* @param {string} text
*/
const fixInput = text => stripIndent(text)
.replace(//g, ' ')
.replace(/→→/g, '\t');
.replaceAll('•', ' ')
.replaceAll('→→', '\t');

const {test} = getTester(import.meta);

Expand Down
2 changes: 1 addition & 1 deletion test/utils/snapshot-rule-tester.mjs
Expand Up @@ -41,7 +41,7 @@ function visualizeEslintMessage(text, result) {

const printCode = code => codeFrameColumns(code, {start: {line: 0, column: 0}}, codeFrameColumnsOptions);
const INDENT = ' '.repeat(4);
const indentCode = code => code.replace(/^/gm, INDENT);
const indentCode = code => code.replaceAll(/^/gm, INDENT);
const getAdditionalProperties = (object, properties) =>
Object.keys(object).filter(property => !properties.includes(property));

Expand Down

0 comments on commit fa431ff

Please sign in to comment.