/
no-empty-interface.test.ts
174 lines (168 loc) · 3.03 KB
/
no-empty-interface.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import rule from '../../src/rules/no-empty-interface';
import { RuleTester, noFormat } from '../RuleTester';
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});
ruleTester.run('no-empty-interface', rule, {
valid: [
`
interface Foo {
name: string;
}
`,
`
interface Foo {
name: string;
}
interface Bar {
age: number;
}
// valid because extending multiple interfaces can be used instead of a union type
interface Baz extends Foo, Bar {}
`,
{
code: `
interface Foo {
name: string;
}
interface Bar extends Foo {}
`,
options: [{ allowSingleExtends: true }],
},
],
invalid: [
{
code: 'interface Foo {}',
errors: [
{
messageId: 'noEmpty',
line: 1,
column: 11,
},
],
},
{
code: noFormat`interface Foo extends {}`,
errors: [
{
messageId: 'noEmpty',
line: 1,
column: 11,
},
],
},
{
code: `
interface Foo {
name: string;
}
interface Bar extends Foo {}
`,
options: [{ allowSingleExtends: false }],
errors: [
{
messageId: 'noEmptyWithSuper',
line: 6,
column: 11,
},
],
},
{
code: 'interface Foo extends Array<number> {}',
output: noFormat`type Foo = Array<number>`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 1,
column: 11,
},
],
},
{
code: 'interface Foo extends Array<number | {}> {}',
output: noFormat`type Foo = Array<number | {}>`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 1,
column: 11,
},
],
},
{
code: `
interface Bar {
bar: string;
}
interface Foo extends Array<Bar> {}
`,
output: noFormat`
interface Bar {
bar: string;
}
type Foo = Array<Bar>
`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 5,
column: 11,
},
],
},
{
code: `
type R = Record<string, unknown>;
interface Foo extends R {}
`,
output: noFormat`
type R = Record<string, unknown>;
type Foo = R
`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 3,
column: 11,
},
],
},
{
code: `
interface Foo<T> extends Bar<T> {}
`,
output: noFormat`
type Foo<T> = Bar<T>
`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 2,
column: 11,
},
],
},
{
filename: 'test.d.ts',
code: `
declare module FooBar {
type Baz = typeof baz;
export interface Bar extends Baz {}
}
`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 4,
},
],
// output matches input because a suggestion was made
output: `
declare module FooBar {
type Baz = typeof baz;
export interface Bar extends Baz {}
}
`,
},
],
});