Skip to content

Commit

Permalink
Merge 2a56d10 into cfb749d
Browse files Browse the repository at this point in the history
  • Loading branch information
midgleyc committed Feb 2, 2021
2 parents cfb749d + 2a56d10 commit 982bb74
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
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

0 comments on commit 982bb74

Please sign in to comment.