Skip to content

Commit

Permalink
fix(eslint-plugin): [space-infix-ops] fix no error when right type is…
Browse files Browse the repository at this point in the history
… function (#4848)

* fix(eslint-plugin): [space-infix-ops] no error when right type
is function

No errors were thrown when the right type is a function when no
space between union or intersection operator. Function types are
wrapped inside parenthesize. If the right type is function, instead of
getting the operator, it was always getting the function parenthesize.
The fix providedd skips wrapped parenthesize for function type, so that
operator will be properly identified.

* fix: edge case where function has multiple
parenthesis
  • Loading branch information
tapanprakasht committed Apr 24, 2022
1 parent 5ad70db commit d74d559
Show file tree
Hide file tree
Showing 2 changed files with 1,559 additions and 178 deletions.
9 changes: 8 additions & 1 deletion packages/eslint-plugin/src/rules/space-infix-ops.ts
Expand Up @@ -142,7 +142,14 @@ export default util.createRule<Options, MessageIds>({
const types = typeAnnotation.types;

types.forEach(type => {
const operator = sourceCode.getTokenBefore(type);
const skipFunctionParenthesis =
type.type === TSESTree.AST_NODE_TYPES.TSFunctionType
? util.isNotOpeningParenToken
: 0;
const operator = sourceCode.getTokenBefore(
type,
skipFunctionParenthesis,
);

if (operator != null && UNIONS.includes(operator.value)) {
const prev = sourceCode.getTokenBefore(operator);
Expand Down

0 comments on commit d74d559

Please sign in to comment.