/
named-tuple-spacing.test.ts
98 lines (95 loc) · 2.78 KB
/
named-tuple-spacing.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { RuleTester } from '../../vendor/rule-tester/src/RuleTester'
import rule, { RULE_NAME } from './named-tuple-spacing'
const valids = [
'type T = [i: number]',
'type T = [i?: number]',
'type T = [i: number, j: number]',
'type T = [i: number, j: () => string]',
`const emit = defineEmits<{
change: [id: number]
update: [value: string]
}>()`,
]
const ruleTester: RuleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
})
ruleTester.run(RULE_NAME, rule as any, {
valid: valids,
invalid: [
{
code: 'type T = [i:number]',
output: 'type T = [i: number]',
errors: [{ messageId: 'expectedSpaceAfter' }],
},
{
code: 'type T = [i: number]',
output: 'type T = [i: number]',
errors: [{ messageId: 'expectedSpaceAfter' }],
},
{
code: 'type T = [i?:number]',
output: 'type T = [i?: number]',
errors: [{ messageId: 'expectedSpaceAfter' }],
},
{
code: 'type T = [i? :number]',
output: 'type T = [i?: number]',
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'expectedSpaceAfter' }],
},
{
code: 'type T = [i : number]',
output: 'type T = [i: number]',
errors: [{ messageId: 'unexpectedSpaceBefore' }],
},
{
code: 'type T = [i : number]',
output: 'type T = [i: number]',
errors: [{ messageId: 'unexpectedSpaceBefore' }],
},
{
code: 'type T = [i ? : number]',
output: 'type T = [i?: number]',
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'unexpectedSpaceBefore' }],
},
{
code: 'type T = [i:number, j:number]',
output: 'type T = [i: number, j: number]',
errors: [{ messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }],
},
{
code: 'type T = [i:()=>void, j:number]',
output: 'type T = [i: ()=>void, j: number]',
errors: [{ messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }],
},
{
code: `
const emit = defineEmits<{
change: [id:number]
update: [value:string]
}>()
`,
output: `
const emit = defineEmits<{
change: [id: number]
update: [value: string]
}>()
`,
errors: [{ messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }],
},
{
code: `
const emit = defineEmits<{
change: [id? :number]
update: [value:string]
}>()
`,
output: `
const emit = defineEmits<{
change: [id?: number]
update: [value: string]
}>()
`,
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }],
},
],
})