Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: upgrade eslint-plugin-eslint-plugin #14590

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 1 addition & 16 deletions .eslintrc.js
Expand Up @@ -71,22 +71,7 @@ module.exports = {
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-docs-description": "error",
"eslint-plugin/require-meta-type": "error",
"eslint-plugin/test-case-property-ordering": [
"error",

// https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/79
[
"filename",
"code",
"output",
"options",
"parser",
"parserOptions",
"globals",
"env",
"errors"
]
],
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-shorthand-strings": "error",
"internal-rules/multiline-comment-style": "error"
},
Expand Down
28 changes: 16 additions & 12 deletions lib/rules/dot-notation.js
Expand Up @@ -87,36 +87,38 @@ module.exports = {
data: {
key: formattedValue
},
*fix(fixer) {
fix(fixer) {
const fixes = [];
const leftBracket = sourceCode.getTokenAfter(node.object, astUtils.isOpeningBracketToken);
const rightBracket = sourceCode.getLastToken(node);
const nextToken = sourceCode.getTokenAfter(node);

// Don't perform any fixes if there are comments inside the brackets.
if (sourceCode.commentsExistBetween(leftBracket, rightBracket)) {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bug that should be fixed in eslint-plugin-eslint-plugin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created an issue eslint-community/eslint-plugin-eslint-plugin#117 to track it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the changes; let's make another PR when it is fixed in the plugin.

}

// Replace the brackets by an identifier.
if (!node.optional) {
yield fixer.insertTextBefore(
fixes.push(fixer.insertTextBefore(
leftBracket,
astUtils.isDecimalInteger(node.object) ? " ." : "."
);
));
}
yield fixer.replaceTextRange(
fixes.push(fixer.replaceTextRange(
[leftBracket.range[0], rightBracket.range[1]],
value
);
));

// Insert a space after the property if it will be connected to the next token.
if (
nextToken &&
rightBracket.range[1] === nextToken.range[0] &&
!astUtils.canTokensBeAdjacent(String(value), nextToken)
) {
yield fixer.insertTextAfter(node, " ");
fixes.push(fixer.insertTextAfter(node, " "));
}
return fixes;
}
});
}
Expand Down Expand Up @@ -149,24 +151,26 @@ module.exports = {
data: {
key: node.property.name
},
*fix(fixer) {
fix(fixer) {
const fixes = [];
const dotToken = sourceCode.getTokenBefore(node.property);

// A statement that starts with `let[` is parsed as a destructuring variable declaration, not a MemberExpression.
if (node.object.type === "Identifier" && node.object.name === "let" && !node.optional) {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

// Don't perform any fixes if there are comments between the dot and the property name.
if (sourceCode.commentsExistBetween(dotToken, node.property)) {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

// Replace the identifier to brackets.
if (!node.optional) {
yield fixer.remove(dotToken);
fixes.push(fixer.remove(dotToken));
}
yield fixer.replaceText(node.property, `["${node.property.name}"]`);
fixes.push(fixer.replaceText(node.property, `["${node.property.name}"]`));
return fixes;
}
});
}
Expand Down
27 changes: 15 additions & 12 deletions lib/rules/prefer-arrow-callback.js
Expand Up @@ -286,7 +286,9 @@ module.exports = {
context.report({
node,
messageId: "preferArrowCallback",
*fix(fixer) {
fix(fixer) {
const fixes = [];

if ((!callbackInfo.isLexicalThis && scopeInfo.this) || hasDuplicateParams(node.params)) {

/*
Expand All @@ -295,7 +297,7 @@ module.exports = {
* If the callback function has duplicates in its list of parameters (possible in sloppy mode),
* don't replace it with an arrow function, because this is a SyntaxError with arrow functions.
*/
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

// Remove `.bind(this)` if exists.
Expand All @@ -307,7 +309,7 @@ module.exports = {
* E.g. `(foo || function(){}).bind(this)`
*/
if (memberNode.type !== "MemberExpression") {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

const callNode = memberNode.parent;
Expand All @@ -320,15 +322,15 @@ module.exports = {
* ^^^^^^^^^^^^
*/
if (astUtils.isParenthesised(sourceCode, memberNode)) {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

// If comments exist in the `.bind(this)`, don't remove those.
if (sourceCode.commentsExistBetween(firstTokenToRemove, lastTokenToRemove)) {
return; // eslint-disable-line eslint-plugin/fixer-return -- false positive
return null;
}

yield fixer.removeRange([firstTokenToRemove.range[0], lastTokenToRemove.range[1]]);
fixes.push(fixer.removeRange([firstTokenToRemove.range[0], lastTokenToRemove.range[1]]));
}

// Convert the function expression to an arrow function.
Expand All @@ -338,16 +340,16 @@ module.exports = {
if (sourceCode.commentsExistBetween(functionToken, leftParenToken)) {

// Remove only extra tokens to keep comments.
yield fixer.remove(functionToken);
fixes.push(fixer.remove(functionToken));
if (node.id) {
yield fixer.remove(node.id);
fixes.push(fixer.remove(node.id));
}
} else {

// Remove extra tokens and spaces.
yield fixer.removeRange([functionToken.range[0], leftParenToken.range[0]]);
fixes.push(fixer.removeRange([functionToken.range[0], leftParenToken.range[0]]));
}
yield fixer.insertTextBefore(node.body, "=> ");
fixes.push(fixer.insertTextBefore(node.body, "=> "));

// Get the node that will become the new arrow function.
let replacedNode = callbackInfo.isLexicalThis ? node.parent.parent : node;
Expand All @@ -367,9 +369,10 @@ module.exports = {
!astUtils.isParenthesised(sourceCode, replacedNode) &&
!astUtils.isParenthesised(sourceCode, node)
) {
yield fixer.insertTextBefore(replacedNode, "(");
yield fixer.insertTextAfter(replacedNode, ")");
fixes.push(fixer.insertTextBefore(replacedNode, "("));
fixes.push(fixer.insertTextAfter(replacedNode, ")"));
}
return fixes;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -94,7 +94,7 @@
"escape-string-regexp": "^3.0.0",
"eslint": "file:.",
"eslint-config-eslint": "file:packages/eslint-config-eslint",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-eslint-plugin": "^3.0.3",
"eslint-plugin-internal-rules": "file:tools/internal-rules",
"eslint-plugin-jsdoc": "^25.4.3",
"eslint-plugin-node": "^11.1.0",
Expand Down