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

fix(eslint-plugin): [no-extra-parens] handle ESLint 7.19.0 #2993

Merged
merged 4 commits into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 51 additions & 17 deletions packages/eslint-plugin/src/rules/no-extra-parens.ts
Expand Up @@ -164,23 +164,7 @@ export default util.createRule<Options, MessageIds>({
return rules.ConditionalExpression(node);
},
// DoWhileStatement
'ForInStatement, ForOfStatement'(
node: TSESTree.ForInStatement | TSESTree.ForOfStatement,
) {
if (util.isTypeAssertion(node.right)) {
// makes the rule skip checking of the right
return rules['ForInStatement, ForOfStatement']({
...node,
type: AST_NODE_TYPES.ForOfStatement as any,
right: {
...node.right,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}

return rules['ForInStatement, ForOfStatement'](node);
},
// ForIn and ForOf are guarded by eslint version
ForStatement(node) {
// make the rule skip the piece by removing it entirely
if (node.init && util.isTypeAssertion(node.init)) {
Expand Down Expand Up @@ -256,6 +240,56 @@ export default util.createRule<Options, MessageIds>({
}
},
};
if (rules.ForInStatement && rules.ForOfStatement) {
overrides.ForInStatement = function (node): void {
if (util.isTypeAssertion(node.right)) {
// makes the rule skip checking of the right
return rules.ForInStatement({
...node,
type: AST_NODE_TYPES.ForInStatement,
right: {
...node.right,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}

return rules.ForInStatement(node);
};
overrides.ForOfStatement = function (node): void {
if (util.isTypeAssertion(node.right)) {
// makes the rule skip checking of the right
return rules.ForOfStatement({
...node,
type: AST_NODE_TYPES.ForOfStatement,
right: {
...node.right,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}

return rules.ForOfStatement(node);
};
} else {
overrides['ForInStatement, ForOfStatement'] = function (
node: TSESTree.ForInStatement | TSESTree.ForOfStatement,
): void {
if (util.isTypeAssertion(node.right)) {
// makes the rule skip checking of the right
return rules['ForInStatement, ForOfStatement']({
...node,
type: AST_NODE_TYPES.ForOfStatement as any,
right: {
...node.right,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}

return rules['ForInStatement, ForOfStatement'](node);
};
}
return Object.assign({}, rules, overrides);
},
});
4 changes: 4 additions & 0 deletions packages/eslint-plugin/typings/eslint-rules.d.ts
Expand Up @@ -520,9 +520,13 @@ declare module 'eslint/lib/rules/no-extra-parens' {
ClassExpression(node: TSESTree.ClassExpression): void;
ConditionalExpression(node: TSESTree.ConditionalExpression): void;
DoWhileStatement(node: TSESTree.DoWhileStatement): void;
// eslint < 7.19.0
'ForInStatement, ForOfStatement'(
node: TSESTree.ForInStatement | TSESTree.ForOfStatement,
): void;
// eslint >= 7.19.0
ForInStatement(node: TSESTree.ForInStatement): void;
ForOfStatement(node: TSESTree.ForOfStatement): void;
ForStatement(node: TSESTree.ForStatement): void;
'ForStatement > *.init:exit'(node: TSESTree.Node): void;
IfStatement(node: TSESTree.IfStatement): void;
Expand Down