From 71ff1a233b3047f69e77fdf7f91a6228c19630ef Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Fri, 22 Apr 2022 23:22:26 +0530 Subject: [PATCH 1/2] 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. --- .../src/rules/space-infix-ops.ts | 7 +- .../tests/rules/space-infix-ops.test.ts | 919 +++++++++++++++--- 2 files changed, 809 insertions(+), 117 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..69280d2ae59 100644 --- a/packages/eslint-plugin/src/rules/space-infix-ops.ts +++ b/packages/eslint-plugin/src/rules/space-infix-ops.ts @@ -142,7 +142,12 @@ export default util.createRule({ const types = typeAnnotation.types; types.forEach(type => { - const operator = sourceCode.getTokenBefore(type); + const skipFunctionParenthesize = + type.type === TSESTree.AST_NODE_TYPES.TSFunctionType ? 1 : 0; + const operator = sourceCode.getTokenBefore( + type, + skipFunctionParenthesize, + ); 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..0d680ee5184 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,26 @@ ruleTester.run('space-infix-ops', rule, { type Test = string & boolean; `, }, + { + code: ` + type Test = string | (() => void); + `, + }, + { + code: ` + type Test = string & (() => void); + `, + }, + { + code: ` + type Test = (() => boolean) | (() => void); + `, + }, + { + code: ` + type Test = (() => boolean) & (() => void); + `, + }, { code: ` class Test { @@ -83,6 +103,20 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + class Test { + private value:number | (() => void) = 1; + } + `, + }, + { + code: ` + class Test { + private value:number & (() => void) = 1; + } + `, + }, { code: ` type Test = @@ -97,6 +131,34 @@ 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: ` interface Test { @@ -115,6 +177,24 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + interface Test { + prop: + & string + & (() => void); + } + `, + }, + { + code: ` + interface Test { + prop: + | string + | (() => void); + } + `, + }, { code: ` interface Test { @@ -136,11 +216,37 @@ 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: ` const x: string & number; `, }, + { + code: ` + const x: string & (() => void); + `, + }, { code: ` class Test { @@ -278,22 +384,22 @@ ruleTester.run('space-infix-ops', rule, { }, { code: ` - type Test =string | number; + type Test= (() => void) | number; `, output: ` - type Test = string | number; + type Test = (() => void) | number; `, errors: [ { messageId: 'missingSpace', - column: 19, + column: 18, line: 2, }, ], }, { code: ` - type Test = string| number; + type Test =string | number; `, output: ` type Test = string | number; @@ -301,309 +407,740 @@ ruleTester.run('space-infix-ops', rule, { errors: [ { messageId: 'missingSpace', - column: 27, + column: 19, line: 2, }, ], }, { code: ` - type Test = string |number; + type Test =(() => void) | number; `, output: ` - type Test = string | number; + type Test = (() => void) | number; `, errors: [ { messageId: 'missingSpace', - column: 28, + column: 19, line: 2, }, ], }, { code: ` - type Test = string &number; + type Test = string| number; `, output: ` - type Test = string & number; + type Test = string | number; `, errors: [ { messageId: 'missingSpace', - column: 28, + column: 27, line: 2, }, ], }, { code: ` - type Test = string& number; + type Test = string |number; `, output: ` - type Test = string & number; + type Test = string | number; `, errors: [ { messageId: 'missingSpace', - column: 27, + column: 28, line: 2, }, ], }, { code: ` - type Test = - |string - | number; + type Test = string| (() => void); `, output: ` - type Test = - | string - | number; + type Test = string | (() => void); `, errors: [ { messageId: 'missingSpace', - column: 9, - line: 3, + column: 27, + line: 2, }, ], }, { code: ` - type Test = - &string - & number; + type Test = string |(() => void); `, output: ` - type Test = - & string - & number; + type Test = string | (() => void); `, errors: [ { messageId: 'missingSpace', - column: 9, - line: 3, + column: 28, + line: 2, }, ], }, { code: ` - interface Test { - prop: string| number; - } + type Test = string &number; `, output: ` - interface Test { - prop: string | number; - } + type Test = string & number; `, errors: [ { messageId: 'missingSpace', - column: 23, - line: 3, + column: 28, + line: 2, }, ], }, { code: ` - interface Test { - prop: string |number; - } + type Test = string& number; `, output: ` - interface Test { - prop: string | number; - } + type Test = string & number; `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 27, + line: 2, }, ], }, { code: ` - interface Test { - prop: string &number; - } + type Test = string &(() => void); `, output: ` - interface Test { - prop: string & number; - } + type Test = string & (() => void); `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 3, + column: 28, + line: 2, }, ], }, { code: ` - interface Test { - prop: string& number; - } + type Test = string& (() => void); `, output: ` - interface Test { - prop: string & number; - } + type Test = string & (() => void); `, errors: [ { messageId: 'missingSpace', - column: 23, - line: 3, + column: 27, + line: 2, }, ], }, { code: ` - interface Test { - prop: - |string - | number; - } + type Test = (() => boolean)| (() => void); `, output: ` - interface Test { - prop: - | string - | number; - } + type Test = (() => boolean) | (() => void); `, errors: [ { messageId: 'missingSpace', - column: 13, - line: 4, + column: 36, + line: 2, }, ], }, { code: ` - interface Test { - prop: - &string - & number; - } + type Test = (() => boolean)& (() => void); `, output: ` - interface Test { - prop: - & string - & number; - } + type Test = (() => boolean) & (() => void); `, errors: [ { messageId: 'missingSpace', - column: 13, - line: 4, + column: 36, + line: 2, }, ], }, { code: ` - const x: string &number; + type Test = (() => boolean)|(() => void); `, output: ` - const x: string & number; + type Test = (() => boolean) | (() => void); `, errors: [ { messageId: 'missingSpace', - column: 25, + column: 36, line: 2, }, ], }, { code: ` - const x: string& number; + type Test = (() => boolean)&(() => void); `, output: ` - const x: string & number; + type Test = (() => boolean) & (() => void); `, errors: [ { messageId: 'missingSpace', - column: 24, + column: 36, line: 2, }, ], }, { code: ` - const x: string| number; + type Test = + |string + | number; `, output: ` - const x: string | number; + type Test = + | string + | number; `, errors: [ { messageId: 'missingSpace', - column: 24, - line: 2, + column: 9, + line: 3, }, ], }, { code: ` - class Test { - value: string |number; - } + type Test = + |string + | (() => void); `, output: ` - class Test { - value: string | number; - } + type Test = + | string + | (() => void); `, errors: [ { messageId: 'missingSpace', - column: 25, + column: 9, line: 3, }, ], }, { code: ` - class Test { - value: string& number; - } + type Test = + &string + & number; `, output: ` - class Test { - value: string & number; - } + type Test = + & string + & number; `, errors: [ { messageId: 'missingSpace', - column: 24, + column: 9, line: 3, }, ], }, { code: ` - class Test { - value: string| number; - } + type Test = + &string + & (() => void); `, output: ` - class Test { - value: string | number; - } + 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 |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: (() => void) |(() => void); + } + `, + output: ` + interface Test { + prop: (() => void) | (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 30, + 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& 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 + | 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 + & 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: ` + 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& 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| 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: ` + 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& number; + } + `, + output: ` + class Test { + value: string & number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string& (() => void); + } + `, + output: ` + class Test { + value: string & (() => void); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string| number; + } + `, + output: ` + class Test { + value: string | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, + { + code: ` + class Test { + value: string| (() => void); + } + `, + output: ` + class Test { + value: string | (() => void); + } `, errors: [ { @@ -628,6 +1165,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)>() {} + `, + output: ` + function foo void)>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 39, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -643,6 +1195,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)>() {} + `, + output: ` + function foo void)>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 38, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -658,6 +1225,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)>() {} + `, + output: ` + function foo void)>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 39, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -673,6 +1255,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)>() {} + `, + output: ` + function foo void)>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 38, + line: 2, + }, + ], + }, { code: ` function bar(): string &number {} @@ -688,6 +1285,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string &(() => void) {} + `, + output: ` + function bar(): string & (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 32, + line: 2, + }, + ], + }, { code: ` function bar(): string& number {} @@ -703,6 +1315,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string& (() => void) {} + `, + output: ` + function bar(): string & (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 31, + line: 2, + }, + ], + }, { code: ` function bar(): string |number {} @@ -718,6 +1345,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string |(() => void) {} + `, + output: ` + function bar(): string | (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 32, + line: 2, + }, + ], + }, { code: ` function bar(): string| number {} @@ -733,5 +1375,50 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string| (() => void) {} + `, + output: ` + function bar(): string | (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 31, + line: 2, + }, + ], + }, + { + code: ` + function bar(): (() => boolean)| (() => void) {} + `, + output: ` + function bar(): (() => boolean) | (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, + { + code: ` + function bar(): (() => boolean)& (() => void) {} + `, + output: ` + function bar(): (() => boolean) & (() => void) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, ], }); From c4807f0cf7d04306ebe3c0a4aaddd368ffab8a18 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Sun, 24 Apr 2022 00:04:41 +0530 Subject: [PATCH 2/2] fix: edge case where function has multiple parenthesis --- .../src/rules/space-infix-ops.ts | 8 +- .../tests/rules/space-infix-ops.test.ts | 699 +++++++++++++++++- 2 files changed, 698 insertions(+), 9 deletions(-) diff --git a/packages/eslint-plugin/src/rules/space-infix-ops.ts b/packages/eslint-plugin/src/rules/space-infix-ops.ts index 69280d2ae59..ff6e15ac340 100644 --- a/packages/eslint-plugin/src/rules/space-infix-ops.ts +++ b/packages/eslint-plugin/src/rules/space-infix-ops.ts @@ -142,11 +142,13 @@ export default util.createRule({ const types = typeAnnotation.types; types.forEach(type => { - const skipFunctionParenthesize = - type.type === TSESTree.AST_NODE_TYPES.TSFunctionType ? 1 : 0; + const skipFunctionParenthesis = + type.type === TSESTree.AST_NODE_TYPES.TSFunctionType + ? util.isNotOpeningParenToken + : 0; const operator = sourceCode.getTokenBefore( type, - skipFunctionParenthesize, + skipFunctionParenthesis, ); if (operator != null && UNIONS.includes(operator.value)) { 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 0d680ee5184..72f71d00358 100644 --- a/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts +++ b/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts @@ -79,6 +79,16 @@ ruleTester.run('space-infix-ops', rule, { type Test = string & (() => void); `, }, + { + code: ` + type Test = string | (((() => void))); + `, + }, + { + code: ` + type Test = string & (((() => void))); + `, + }, { code: ` type Test = (() => boolean) | (() => void); @@ -89,6 +99,16 @@ ruleTester.run('space-infix-ops', rule, { type Test = (() => boolean) & (() => void); `, }, + { + code: ` + type Test = (((() => boolean))) | (((() => void))); + `, + }, + { + code: ` + type Test = (((() => boolean))) & (((() => void))); + `, + }, { code: ` class Test { @@ -117,6 +137,20 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + class Test { + private value:number | (((() => void))) = 1; + } + `, + }, + { + code: ` + class Test { + private value:number & (((() => void))) = 1; + } + `, + }, { code: ` type Test = @@ -159,6 +193,34 @@ ruleTester.run('space-infix-ops', rule, { & (() => void); `, }, + { + code: ` + type Test = + | string + | (((() => void))); + `, + }, + { + code: ` + type Test = + & string + & (((() => void))); + `, + }, + { + code: ` + type Test = + | (((() => boolean))) + | (((() => void))); + `, + }, + { + code: ` + type Test = + & (((() => boolean))) + & (((() => void))); + `, + }, { code: ` interface Test { @@ -195,6 +257,24 @@ ruleTester.run('space-infix-ops', rule, { } `, }, + { + code: ` + interface Test { + prop: + & string + & (((() => void))); + } + `, + }, + { + code: ` + interface Test { + prop: + | string + | (((() => void))); + } + `, + }, { code: ` interface Test { @@ -237,6 +317,27 @@ 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: ` const x: string & number; @@ -247,6 +348,11 @@ ruleTester.run('space-infix-ops', rule, { const x: string & (() => void); `, }, + { + code: ` + const x: string & (((() => void))); + `, + }, { code: ` class Test { @@ -397,6 +503,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test= (((() => void))) | number; + `, + output: ` + type Test = (((() => void))) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 18, + line: 2, + }, + ], + }, { code: ` type Test =string | number; @@ -427,6 +548,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test =(((() => void))) | number; + `, + output: ` + type Test = (((() => void))) | number; + `, + errors: [ + { + messageId: 'missingSpace', + column: 19, + line: 2, + }, + ], + }, { code: ` type Test = string| number; @@ -472,6 +608,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = string| (((() => void))); + `, + output: ` + type Test = string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, { code: ` type Test = string |(() => void); @@ -487,6 +638,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = string |(((() => void))); + `, + output: ` + type Test = string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, { code: ` type Test = string &number; @@ -532,6 +698,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = string &(((() => void))); + `, + output: ` + type Test = string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 28, + line: 2, + }, + ], + }, { code: ` type Test = string& (() => void); @@ -547,6 +728,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = string& (((() => void))); + `, + output: ` + type Test = string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 27, + line: 2, + }, + ], + }, { code: ` type Test = (() => boolean)| (() => void); @@ -562,6 +758,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = (((() => boolean)))| (((() => void))); + `, + output: ` + type Test = (((() => boolean))) | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, { code: ` type Test = (() => boolean)& (() => void); @@ -577,6 +788,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = (((() => boolean)))& (((() => void))); + `, + output: ` + type Test = (((() => boolean))) & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, { code: ` type Test = (() => boolean)|(() => void); @@ -592,6 +818,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = (((() => boolean)))|(((() => void))); + `, + output: ` + type Test = (((() => boolean))) | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, { code: ` type Test = (() => boolean)&(() => void); @@ -607,6 +848,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = (((() => boolean)))&(((() => void))); + `, + output: ` + type Test = (((() => boolean))) & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 40, + line: 2, + }, + ], + }, { code: ` type Test = @@ -645,6 +901,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = + |string + | (((() => void))); + `, + output: ` + type Test = + | string + | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, { code: ` type Test = @@ -683,6 +958,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = + &string + & (((() => void))); + `, + output: ` + type Test = + & string + & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 9, + line: 3, + }, + ], + }, { code: ` interface Test { @@ -724,18 +1018,37 @@ ruleTester.run('space-infix-ops', rule, { { code: ` interface Test { - prop: string |number; + prop: string| (((() => void))); } `, output: ` interface Test { - prop: string | number; + prop: string | (((() => void))); } `, errors: [ { messageId: 'missingSpace', - column: 24, + column: 23, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: string |number; + } + `, + output: ` + interface Test { + prop: string | number; + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, line: 3, }, ], @@ -762,18 +1075,56 @@ ruleTester.run('space-infix-ops', rule, { { code: ` interface Test { - prop: (() => void) |(() => void); + 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: (() => void) | (() => void); + prop: (() => boolean) | (() => void); } `, errors: [ { messageId: 'missingSpace', - column: 30, + column: 33, + line: 3, + }, + ], + }, + { + code: ` + interface Test { + prop: (((() => boolean))) |(((() => void))); + } + `, + output: ` + interface Test { + prop: (((() => boolean))) | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 37, line: 3, }, ], @@ -816,6 +1167,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + interface Test { + prop: string &(((() => void))); + } + `, + output: ` + interface Test { + prop: string & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, { code: ` interface Test { @@ -854,6 +1224,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + interface Test { + prop: string& (((() => void))); + } + `, + output: ` + interface Test { + prop: string & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 23, + line: 3, + }, + ], + }, { code: ` interface Test { @@ -900,6 +1289,29 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + interface Test { + prop: + |string + | (((() => void))); + } + `, + output: ` + interface Test { + prop: + | string + | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, { code: ` interface Test { @@ -946,6 +1358,29 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + interface Test { + prop: + &string + & (((() => void))); + } + `, + output: ` + interface Test { + prop: + & string + & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 13, + line: 4, + }, + ], + }, { code: ` const x: string &number; @@ -976,6 +1411,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + const x: string &(((() => void))); + `, + output: ` + const x: string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 2, + }, + ], + }, { code: ` const x: string& number; @@ -1006,6 +1456,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + const x: string& (((() => void))); + `, + output: ` + const x: string & (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, { code: ` const x: string| number; @@ -1036,6 +1501,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + const x: string| (((() => void))); + `, + output: ` + const x: string | (((() => void))); + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 2, + }, + ], + }, { code: ` class Test { @@ -1074,6 +1554,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + class Test { + value: string |(((() => void))); + } + `, + output: ` + class Test { + value: string | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 25, + line: 3, + }, + ], + }, { code: ` class Test { @@ -1112,6 +1611,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + class Test { + value: string& (((() => void))); + } + `, + output: ` + class Test { + value: string & (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, { code: ` class Test { @@ -1150,6 +1668,25 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + class Test { + value: string| (((() => void))); + } + `, + output: ` + class Test { + value: string | (((() => void))); + } + `, + errors: [ + { + messageId: 'missingSpace', + column: 24, + line: 3, + }, + ], + }, { code: ` function foo() {} @@ -1180,6 +1717,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)))>() {} + `, + output: ` + function foo void)))>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 39, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -1210,6 +1762,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)))>() {} + `, + output: ` + function foo void)))>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 38, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -1240,6 +1807,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)))>() {} + `, + output: ` + function foo void)))>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 39, + line: 2, + }, + ], + }, { code: ` function foo() {} @@ -1270,6 +1852,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function foo void)))>() {} + `, + output: ` + function foo void)))>() {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 38, + line: 2, + }, + ], + }, { code: ` function bar(): string &number {} @@ -1300,6 +1897,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string &(((() => void))) {} + `, + output: ` + function bar(): string & (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 32, + line: 2, + }, + ], + }, { code: ` function bar(): string& number {} @@ -1330,6 +1942,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string& (((() => void))) {} + `, + output: ` + function bar(): string & (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 31, + line: 2, + }, + ], + }, { code: ` function bar(): string |number {} @@ -1360,6 +1987,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string |(((() => void))) {} + `, + output: ` + function bar(): string | (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 32, + line: 2, + }, + ], + }, { code: ` function bar(): string| number {} @@ -1390,6 +2032,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): string| (((() => void))) {} + `, + output: ` + function bar(): string | (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 31, + line: 2, + }, + ], + }, { code: ` function bar(): (() => boolean)| (() => void) {} @@ -1405,6 +2062,21 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): (((() => boolean)))| (((() => void))) {} + `, + output: ` + function bar(): (((() => boolean))) | (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 44, + line: 2, + }, + ], + }, { code: ` function bar(): (() => boolean)& (() => void) {} @@ -1420,5 +2092,20 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + function bar(): (((() => boolean)))& (((() => void))) {} + `, + output: ` + function bar(): (((() => boolean))) & (((() => void))) {} + `, + errors: [ + { + messageId: 'missingSpace', + column: 44, + line: 2, + }, + ], + }, ], }); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy