-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
166 lines (163 loc) · 3.45 KB
/
index.spec.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
import { ruleTester } from '../../testUtil';
import { rule } from '../../no-implicit-any';
ruleTester.run('return-statement', rule, {
valid: [
{
code: 'const foo = () => { return 1 }',
},
{
code: 'const foo = (): any => { return null }',
},
{
code: 'const foo: any = () => { return null }',
},
{
code: 'const foo = () => { return null as any }',
},
{
code: 'const foo = () => {}',
},
{
code: `
const foo = (arg: boolean) => {
if (arg) return;
return 'bar';
}
`,
},
{
code: `
const foo = (arg1: boolean, arg2: boolean) => {
if (arg1) {
return null;
};
if (arg2) {
return 'bar';
}
}
`,
},
{
code: `
const foo = (arg: string) => {
switch (arg) {
case 'first':
return 'first';
case 'second': {
return 'second';
}
case 'third and forth':
return 'third and forth';
default:
return null;
}
}
`,
},
{
code: `
function foo (arg: boolean) {
while (true) {
if (arg) {
return null;
} else {
break;
}
}
return 'bar';
}
`,
},
{
code: `
const foo = (arg: any) => {
return undefined || null || arg;
}
`,
},
{
code: `
const foo = (arg: any) => {
return arg?.name;
}
`,
},
{
code: `
const fn = (): any => {}
const foo = (hoge?: () => void, arg?: any) => {
if (hoge) {
hoge();
} else if (arg) {
return fn() + arg;
} else {
return fn();
}
}
`,
},
{
code: `
function foo () {
try {
return doSomethingMightHaveError();
} catch {
throw new Error('error');
} finally {
return null;
}
}
`,
},
{
code: `
function foo () {
try {
doSomethingMightHaveError();
return null;
} catch {
return 'error'
}
}
`,
},
],
invalid: [
{
code: 'const foo = () => { return null }',
output: 'const foo = () => { return null as null }',
errors: [{ messageId: 'missingAnyType' }],
},
{
code: 'const foo = () => { return undefined }',
output: 'const foo = () => { return undefined as undefined }',
errors: [{ messageId: 'missingAnyType' }],
},
{
code: `
const foo = () => {
return undefined || null || undefined;
}
`,
output: `
const foo = () => {
return undefined || null || undefined as any;
}
`,
errors: [{ messageId: 'missingAnyType' }],
},
{
code: `
const foo = () => {
return undefined && null && undefined;
}
`,
output: `
const foo = () => {
return undefined && null && undefined as any;
}
`,
errors: [{ messageId: 'missingAnyType' }],
},
],
});