Skip to content

Commit

Permalink
fix(eslint-plugin): [space-infix-ops] correct PropertyDefinition with…
Browse files Browse the repository at this point in the history
… typeAnnotation (#5113)
  • Loading branch information
armano2 committed May 30, 2022
1 parent 90f3960 commit d320174
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/space-infix-ops.ts
Expand Up @@ -124,8 +124,8 @@ export default util.createRule<Options, MessageIds>({
function checkForPropertyDefinitionAssignmentSpace(
node: TSESTree.PropertyDefinition,
): void {
const leftNode = sourceCode.getTokenByRangeStart(
node.typeAnnotation?.range[0] ?? node.range[0],
const leftNode = sourceCode.getLastToken(
node.typeAnnotation ?? node.key,
)!;
const rightNode = node.value
? sourceCode.getTokenByRangeStart(node.value.range[0])
Expand Down
52 changes: 52 additions & 0 deletions packages/eslint-plugin/tests/rules/space-infix-ops.test.ts
Expand Up @@ -151,6 +151,20 @@ ruleTester.run('space-infix-ops', rule, {
}
`,
},
{
code: `
class Test {
value: { prop: string }[] = [];
}
`,
},
{
code: `
class Test {
value:{prop:string}[] = [];
}
`,
},
{
code: `
type Test =
Expand Down Expand Up @@ -473,6 +487,44 @@ ruleTester.run('space-infix-ops', rule, {
},
],
},
{
code: `
class Test {
value: { prop: string }[]= [];
}
`,
output: `
class Test {
value: { prop: string }[] = [];
}
`,
errors: [
{
messageId: 'missingSpace',
column: 36,
line: 3,
},
],
},
{
code: `
class Test {
value: { prop: string }[] =[];
}
`,
output: `
class Test {
value: { prop: string }[] = [];
}
`,
errors: [
{
messageId: 'missingSpace',
column: 37,
line: 3,
},
],
},
{
code: `
type Test= string | number;
Expand Down

0 comments on commit d320174

Please sign in to comment.