From d74d559c25e336c3ebe917bf5c43e14ffa2de694 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Mon, 25 Apr 2022 03:10:09 +0530 Subject: [PATCH] fix(eslint-plugin): [space-infix-ops] fix no error when right type is 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 --- .../src/rules/space-infix-ops.ts | 9 +- .../tests/rules/space-infix-ops.test.ts | 1728 +++++++++++++++-- 2 files changed, 1559 insertions(+), 178 deletions(-) diff --git a/packages/eslint-plugin/src/rules/space-infix-ops.ts b/packages/eslint-plugin/src/rules/space-infix-ops.ts index a38b57825f2..ff6e15ac340 100644 --- a/packages/eslint-plugin/src/rules/space-infix-ops.ts +++ b/packages/eslint-plugin/src/rules/space-infix-ops.ts @@ -142,7 +142,14 @@ export default util.createRule({ 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); diff --git a/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts b/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts index 5ad92555d88..72f71d00358 100644 --- a/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts +++ b/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts @@ -69,6 +69,46 @@ ruleTester.run('space-infix-ops', rule, { type Test = string & boolean; `, }, + { + code: ` + type Test = string | (() => void); + `, + }, + { + code: ` + type Test = string & (() => void); + `, + }, + { + code: ` + type Test = string | (((() => void))); + `, + }, + { + code: ` + type Test = string & (((() => void))); + `, + }, + { + code: ` + type Test = (() => boolean) | (() => void); + `, + }, + { + code: ` + type Test = (() => boolean) & (() => void); + `, + }, + { + code: ` + type Test = (((() => boolean))) | (((() => void))); + `, + }, + { + code: ` + type Test = (((() => boolean))) & (((() => void))); + `, + }, { code: ` class Test { @@ -83,6 +123,34 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + class Test { + private value:number | (() => void) = 1; + } + `, + }, + { + code: ` + class Test { + private value:number & (() => void) = 1; + } + `, + }, + { + code: ` + class Test { + private value:number | (((() => void))) = 1; + } + `, + }, + { + code: ` + class Test { + private value:number & (((() => void))) = 1; + } + `, + }, { code: ` type Test = @@ -97,6 +165,62 @@ ruleTester.run('space-infix-ops', rule, { & boolean; `, }, + { + code: ` + type Test = + | string + | (() => void); + `, + }, + { + code: ` + type Test = + & string + & (() => void); + `, + }, + { + code: ` + type Test = + | (() => boolean) + | (() => void); + `, + }, + { + code: ` + type Test = + & (() => boolean) + & (() => void); + `, + }, + { + code: ` + type Test = + | string + | (((() => void))); + `, + }, + { + code: ` + type Test = + & string + & (((() => void))); + `, + }, + { + code: ` + type Test = + | (((() => boolean))) + | (((() => void))); + `, + }, + { + code: ` + type Test = + & (((() => boolean))) + & (((() => void))); + `, + }, { code: ` interface Test { @@ -115,6 +239,42 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + interface Test { + prop: + & string + & (() => void); + } + `, + }, + { + code: ` + interface Test { + prop: + | string + | (() => void); + } + `, + }, + { + code: ` + interface Test { + prop: + & string + & (((() => void))); + } + `, + }, + { + code: ` + interface Test { + prop: + | string + | (((() => void))); + } + `, + }, { code: ` interface Test { @@ -136,11 +296,63 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + interface Test { + props: string | (() => void); + } + `, + }, + { + code: ` + interface Test { + props: string & (() => void); + } + `, + }, + { + code: ` + interface Test { + props: (() => boolean) & (() => void); + } + `, + }, + { + code: ` + interface Test { + props: string | (((() => void))); + } + `, + }, + { + code: ` + interface Test { + props: string & (((() => void))); + } + `, + }, + { + code: ` + interface Test { + props: (((() => boolean))) & (((() => void))); + } + `, + }, { code: ` const x: string & number; `, }, + { + code: ` + const x: string & (() => void); + `, + }, + { + code: ` + const x: string & (((() => void))); + `, + }, { code: ` class Test { @@ -155,70 +367,1284 @@ ruleTester.run('space-infix-ops', rule, { }, { code: ` - function bar(): string & number {} + function bar(): string & number {} + `, + }, + ], + invalid: [ + { + code: ` + enum Test { + A= 2, + B = 1, + } + `, + output: ` + enum Test { + A = 2, + B = 1, + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 12, + line: 3, + }, + ], + }, + { + code: ` + enum Test { + KEY1= "value1", + KEY2 = "value2", + } + `, + output: ` + enum Test { + KEY1 = "value1", + KEY2 = "value2", + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 15, + line: 3, + }, + ], + }, + { + code: ` + enum Test { + A =2, + B = 1, + } + `, + output: ` + enum Test { + A = 2, + B = 1, + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 3, + }, + ], + }, + { + code: ` + class Test { + public readonly value= 2; + } + `, + output: ` + class Test { + public readonly value = 2; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 32, + line: 3, + }, + ], + }, + { + code: ` + class Test { + public readonly value =2; + } + `, + output: ` + class Test { + public readonly value = 2; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 33, + line: 3, + }, + ], + }, + { + code: ` + type Test= string | number; + `, + output: ` + type Test = string | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 18, + line: 2, + }, + ], + }, + { + code: ` + type Test= (() => void) | number; + `, + output: ` + type Test = (() => void) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 18, + line: 2, + }, + ], + }, + { + code: ` + type Test= (((() => void))) | number; + `, + output: ` + type Test = (((() => void))) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 18, + line: 2, + }, + ], + }, + { + code: ` + type Test =string | number; + `, + output: ` + type Test = string | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 19, + line: 2, + }, + ], + }, + { + code: ` + type Test =(() => void) | number; + `, + output: ` + type Test = (() => void) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 19, + line: 2, + }, + ], + }, + { + code: ` + type Test =(((() => void))) | number; + `, + output: ` + type Test = (((() => void))) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 19, + line: 2, + }, + ], + }, + { + code: ` + type Test = string| number; + `, + output: ` + type Test = string | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = string |number; + `, + output: ` + type Test = string | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string| (() => void); + `, + output: ` + type Test = string | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = string| (((() => void))); + `, + output: ` + type Test = string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = string |(() => void); + `, + output: ` + type Test = string | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string |(((() => void))); + `, + output: ` + type Test = string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string &number; + `, + output: ` + type Test = string & number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string& number; + `, + output: ` + type Test = string & number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = string &(() => void); + `, + output: ` + type Test = string & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string &(((() => void))); + `, + output: ` + type Test = string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, + { + code: ` + type Test = string& (() => void); + `, + output: ` + type Test = string & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = string& (((() => void))); + `, + output: ` + type Test = string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, + { + code: ` + type Test = (() => boolean)| (() => void); + `, + output: ` + type Test = (() => boolean) | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 36, + line: 2, + }, + ], + }, + { + code: ` + type Test = (((() => boolean)))| (((() => void))); + `, + output: ` + type Test = (((() => boolean))) | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, + { + code: ` + type Test = (() => boolean)& (() => void); + `, + output: ` + type Test = (() => boolean) & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 36, + line: 2, + }, + ], + }, + { + code: ` + type Test = (((() => boolean)))& (((() => void))); + `, + output: ` + type Test = (((() => boolean))) & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, + { + code: ` + type Test = (() => boolean)|(() => void); + `, + output: ` + type Test = (() => boolean) | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 36, + line: 2, + }, + ], + }, + { + code: ` + type Test = (((() => boolean)))|(((() => void))); + `, + output: ` + type Test = (((() => boolean))) | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, + { + code: ` + type Test = (() => boolean)&(() => void); + `, + output: ` + type Test = (() => boolean) & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 36, + line: 2, + }, + ], + }, + { + code: ` + type Test = (((() => boolean)))&(((() => void))); + `, + output: ` + type Test = (((() => boolean))) & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, + { + code: ` + type Test = + |string + | number; + `, + output: ` + type Test = + | string + | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + type Test = + |string + | (() => void); + `, + output: ` + type Test = + | string + | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + type Test = + |string + | (((() => void))); + `, + output: ` + type Test = + | string + | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + type Test = + &string + & number; + `, + output: ` + type Test = + & string + & number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + type Test = + &string + & (() => void); + `, + output: ` + type Test = + & string + & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + type Test = + &string + & (((() => void))); + `, + output: ` + type Test = + & string + & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string| number; + } + `, + output: ` + interface Test { + prop: string | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string| (() => void); + } + `, + output: ` + interface Test { + prop: string | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string| (((() => void))); + } + `, + output: ` + interface Test { + prop: string | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string |number; + } + `, + output: ` + interface Test { + prop: string | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string |(() => void); + } + `, + output: ` + interface Test { + prop: string | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string |(((() => void))); + } + `, + output: ` + interface Test { + prop: string | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: (() => boolean) |(() => void); + } + `, + output: ` + interface Test { + prop: (() => boolean) | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 33, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: (((() => boolean))) |(((() => void))); + } + `, + output: ` + interface Test { + prop: (((() => boolean))) | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 37, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string &number; + } + `, + output: ` + interface Test { + prop: string & number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string &(() => void); + } + `, + output: ` + interface Test { + prop: string & (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string &(((() => void))); + } + `, + output: ` + interface Test { + prop: string & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string& number; + } + `, + output: ` + interface Test { + prop: string & number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string& (() => void); + } + `, + output: ` + interface Test { + prop: string & (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string& (((() => void))); + } + `, + output: ` + interface Test { + prop: string & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: + |string + | number; + } + `, + output: ` + interface Test { + prop: + | string + | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + interface Test { + prop: + |string + | (() => void); + } + `, + output: ` + interface Test { + prop: + | string + | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + interface Test { + prop: + |string + | (((() => void))); + } + `, + output: ` + interface Test { + prop: + | string + | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + interface Test { + prop: + &string + & number; + } + `, + output: ` + interface Test { + prop: + & string + & number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + interface Test { + prop: + &string + & (() => void); + } + `, + output: ` + interface Test { + prop: + & string + & (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + interface Test { + prop: + &string + & (((() => void))); + } + `, + output: ` + interface Test { + prop: + & string + & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, + { + code: ` + const x: string &number; + `, + output: ` + const x: string & number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 2, + }, + ], + }, + { + code: ` + const x: string &(() => void); + `, + output: ` + const x: string & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 2, + }, + ], + }, + { + code: ` + const x: string &(((() => void))); + `, + output: ` + const x: string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 2, + }, + ], + }, + { + code: ` + const x: string& number; + `, + output: ` + const x: string & number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + const x: string& (() => void); + `, + output: ` + const x: string & (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + const x: string& (((() => void))); + `, + output: ` + const x: string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + const x: string| number; + `, + output: ` + const x: string | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + const x: string| (() => void); + `, + output: ` + const x: string | (() => void); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + const x: string| (((() => void))); + `, + output: ` + const x: string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, + { + code: ` + class Test { + value: string |number; + } + `, + output: ` + class Test { + value: string | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string |(() => void); + } + `, + output: ` + class Test { + value: string | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string |(((() => void))); + } + `, + output: ` + class Test { + value: string | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string& number; + } + `, + output: ` + class Test { + value: string & number; + } `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], }, - ], - invalid: [ { code: ` - enum Test { - A= 2, - B = 1, + class Test { + value: string& (() => void); } `, output: ` - enum Test { - A = 2, - B = 1, + class Test { + value: string & (() => void); } `, errors: [ { messageId: 'missingSpace', - column: 12, + column: 24, line: 3, }, ], }, { code: ` - enum Test { - KEY1= "value1", - KEY2 = "value2", + class Test { + value: string& (((() => void))); } `, output: ` - enum Test { - KEY1 = "value1", - KEY2 = "value2", + class Test { + value: string & (((() => void))); } `, errors: [ { messageId: 'missingSpace', - column: 15, + column: 24, line: 3, }, ], }, { code: ` - enum Test { - A =2, - B = 1, + class Test { + value: string| number; } `, output: ` - enum Test { - A = 2, - B = 1, + class Test { + value: string | number; } `, errors: [ { messageId: 'missingSpace', - column: 13, + column: 24, line: 3, }, ], @@ -226,18 +1652,18 @@ ruleTester.run('space-infix-ops', rule, { { code: ` class Test { - public readonly value= 2; + value: string| (() => void); } `, output: ` class Test { - public readonly value = 2; + value: string | (() => void); } `, errors: [ { messageId: 'missingSpace', - column: 32, + column: 24, line: 3, }, ], @@ -245,490 +1671,438 @@ ruleTester.run('space-infix-ops', rule, { { code: ` class Test { - public readonly value =2; + value: string| (((() => void))); } `, output: ` class Test { - public readonly value = 2; + value: string | (((() => void))); } `, errors: [ { messageId: 'missingSpace', - column: 33, + column: 24, line: 3, }, ], }, { code: ` - type Test= string | number; + function foo() {} `, output: ` - type Test = string | number; + function foo() {} `, errors: [ { messageId: 'missingSpace', - column: 18, + column: 39, line: 2, }, ], }, { code: ` - type Test =string | number; + function foo void)>() {} `, output: ` - type Test = string | number; + function foo void)>() {} `, errors: [ { messageId: 'missingSpace', - column: 19, + column: 39, line: 2, }, ], }, { code: ` - type Test = string| number; + function foo void)))>() {} `, output: ` - type Test = string | number; + function foo void)))>() {} `, errors: [ { messageId: 'missingSpace', - column: 27, + column: 39, line: 2, }, ], }, { code: ` - type Test = string |number; + function foo() {} `, output: ` - type Test = string | number; + function foo() {} `, errors: [ { messageId: 'missingSpace', - column: 28, + column: 38, line: 2, }, ], }, { code: ` - type Test = string &number; + function foo void)>() {} `, output: ` - type Test = string & number; + function foo void)>() {} `, errors: [ { messageId: 'missingSpace', - column: 28, + column: 38, line: 2, }, ], }, { code: ` - type Test = string& number; + function foo void)))>() {} `, output: ` - type Test = string & number; + function foo void)))>() {} `, errors: [ { messageId: 'missingSpace', - column: 27, + column: 38, line: 2, }, ], }, { code: ` - type Test = - |string - | number; + function foo() {} `, output: ` - type Test = - | string - | number; + function foo() {} `, errors: [ { messageId: 'missingSpace', - column: 9, - line: 3, + column: 39, + line: 2, }, ], }, { code: ` - type Test = - &string - & number; + function foo void)>() {} `, output: ` - type Test = - & string - & number; + function foo void)>() {} `, errors: [ { messageId: 'missingSpace', - column: 9, - line: 3, + column: 39, + line: 2, }, ], }, { code: ` - interface Test { - prop: string| number; - } + function foo void)))>() {} `, output: ` - interface Test { - prop: string | number; - } + function foo void)))>() {} `, errors: [ { messageId: 'missingSpace', - column: 23, - line: 3, + column: 39, + line: 2, }, ], }, { code: ` - interface Test { - prop: string |number; - } + function foo() {} `, output: ` - interface Test { - prop: string | number; - } + function foo() {} `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 38, + line: 2, }, ], }, { code: ` - interface Test { - prop: string &number; - } + function foo void)>() {} `, output: ` - interface Test { - prop: string & number; - } + function foo void)>() {} `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 38, + line: 2, }, ], }, { code: ` - interface Test { - prop: string& number; - } + function foo void)))>() {} `, output: ` - interface Test { - prop: string & number; - } + function foo void)))>() {} `, errors: [ { messageId: 'missingSpace', - column: 23, - line: 3, + column: 38, + line: 2, }, ], }, { code: ` - interface Test { - prop: - |string - | number; - } + function bar(): string &number {} `, output: ` - interface Test { - prop: - | string - | number; - } + function bar(): string & number {} `, errors: [ { messageId: 'missingSpace', - column: 13, - line: 4, + column: 32, + line: 2, }, ], }, { code: ` - interface Test { - prop: - &string - & number; - } + function bar(): string &(() => void) {} `, output: ` - interface Test { - prop: - & string - & number; - } + function bar(): string & (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 13, - line: 4, + column: 32, + line: 2, }, ], }, { code: ` - const x: string &number; + function bar(): string &(((() => void))) {} `, output: ` - const x: string & number; + function bar(): string & (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 25, + column: 32, line: 2, }, ], }, { code: ` - const x: string& number; + function bar(): string& number {} `, output: ` - const x: string & number; + function bar(): string & number {} `, errors: [ { messageId: 'missingSpace', - column: 24, + column: 31, line: 2, }, ], }, { code: ` - const x: string| number; + function bar(): string& (() => void) {} `, output: ` - const x: string | number; + function bar(): string & (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 24, + column: 31, line: 2, }, ], }, { code: ` - class Test { - value: string |number; - } + function bar(): string& (((() => void))) {} `, output: ` - class Test { - value: string | number; - } + function bar(): string & (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 25, - line: 3, + column: 31, + line: 2, }, ], }, { code: ` - class Test { - value: string& number; - } + function bar(): string |number {} `, output: ` - class Test { - value: string & number; - } + function bar(): string | number {} `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 32, + line: 2, }, ], }, { code: ` - class Test { - value: string| number; - } + function bar(): string |(() => void) {} `, output: ` - class Test { - value: string | number; - } + function bar(): string | (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 32, + line: 2, }, ], }, { code: ` - function foo() {} + function bar(): string |(((() => void))) {} `, output: ` - function foo() {} + function bar(): string | (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 39, + column: 32, line: 2, }, ], }, { code: ` - function foo() {} + function bar(): string| number {} `, output: ` - function foo() {} + function bar(): string | number {} `, errors: [ { messageId: 'missingSpace', - column: 38, + column: 31, line: 2, }, ], }, { code: ` - function foo() {} + function bar(): string| (() => void) {} `, output: ` - function foo() {} + function bar(): string | (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 39, + column: 31, line: 2, }, ], }, { code: ` - function foo() {} + function bar(): string| (((() => void))) {} `, output: ` - function foo() {} + function bar(): string | (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 38, + column: 31, line: 2, }, ], }, { code: ` - function bar(): string &number {} + function bar(): (() => boolean)| (() => void) {} `, output: ` - function bar(): string & number {} + function bar(): (() => boolean) | (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 32, + column: 40, line: 2, }, ], }, { code: ` - function bar(): string& number {} + function bar(): (((() => boolean)))| (((() => void))) {} `, output: ` - function bar(): string & number {} + function bar(): (((() => boolean))) | (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 31, + column: 44, line: 2, }, ], }, { code: ` - function bar(): string |number {} + function bar(): (() => boolean)& (() => void) {} `, output: ` - function bar(): string | number {} + function bar(): (() => boolean) & (() => void) {} `, errors: [ { messageId: 'missingSpace', - column: 32, + column: 40, line: 2, }, ], }, { code: ` - function bar(): string| number {} + function bar(): (((() => boolean)))& (((() => void))) {} `, output: ` - function bar(): string | number {} + function bar(): (((() => boolean))) & (((() => void))) {} `, errors: [ { messageId: 'missingSpace', - column: 31, + column: 44, line: 2, }, ],