This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
/
typescript.spec.js
210 lines (196 loc) · 6.46 KB
/
typescript.spec.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"use strict";
const unpad = require("dedent");
const utils = require("./utils");
const verifyAndAssertMessages = utils.verifyAndAssertMessages;
const loadExternalFixture = utils.loadExternalFixture;
describe("TypeScript", () => {
it("should fundamentally work with `eslint:all`", () => {
verifyAndAssertMessages(
unpad(`
"use strict";
const foo: string = "bar";
`),
{},
["2:7 'foo' is assigned a value but never used. no-unused-vars"],
"script",
{
baseConfig: {
extends: ["eslint:all"],
rules: {
"eol-last": "off"
}
}
}
);
});
it("should not cause a RangeError within the indent rule (#333)", () => {
verifyAndAssertMessages(
loadExternalFixture("range-error-indent"),
{
indent: "error"
},
[]
);
});
it("should not throw in any rules on method overloads (#389)", () => {
verifyAndAssertMessages(
unpad(`
export class Test {
public test(param1: Number): Test;
public test(param1: Test): Test;
public test(param1: any): Test {
return new Test();
}
}
`),
{
"array-callback-return": "error",
"getter-return": "error",
strict: "error",
"lines-around-directive": "error",
"no-empty-function": "error"
},
[]
);
});
it("should not throw in any rules on abstract class methods (#400)", () => {
verifyAndAssertMessages(
unpad(`
export abstract class TestAbstract {
onCreated?(): Promise<void> | any;
}
export abstract class AbstractSocket {
abstract createSocket(): Promise<string>;
}
`),
{
"array-callback-return": "error",
"getter-return": "error",
strict: "error",
"lines-around-directive": "error",
"no-empty-function": "error"
},
[]
);
});
it("should not produce any lint errors on valid JSDoc indentation (#344)", () => {
verifyAndAssertMessages(
loadExternalFixture("jsdoc-indent"),
{
indent: "error"
},
[]
);
});
it("should not produce a parse error (#403)", () => {
verifyAndAssertMessages(
unpad(`
class X {
data() {
return {
form: {
startDate: <Date | undefined> undefined
}
};
}
}
`),
{},
[],
"script",
{
parserOptions: {
jsx: false
}
}
);
});
it("should not produce any lint errors for no-declare on overloaded functions (#402)", () => {
verifyAndAssertMessages(
loadExternalFixture("no-redeclare-overloaded-functions"),
{
"no-redeclare": "error"
},
[]
);
});
it("should not throw any TypeErrors when parsing declared empty body functions using eslint:all (#162)", () => {
verifyAndAssertMessages(
loadExternalFixture("declared-empty-body-functions"),
{},
[
"3:19 'FF' is not defined. no-undef",
"4:11 'Foo' is defined but never used. no-unused-vars",
"4:23 'Bar' is not defined. no-undef",
"4:31 Block must be padded by blank lines. padded-blocks",
"6:5 Block must be padded by blank lines. padded-blocks",
"10:11 'Foo' is already defined. no-redeclare",
"10:23 'Bar' is not defined. no-undef",
"10:31 Block must be padded by blank lines. padded-blocks",
"12:5 Block must be padded by blank lines. padded-blocks",
"15:15 'Foo' is already defined. no-redeclare",
"15:27 'Bar' is not defined. no-undef",
"15:35 Block must be padded by blank lines. padded-blocks",
"17:1 Block must be padded by blank lines. padded-blocks",
"19:19 'd3' is not defined. no-undef",
"20:21 'select' is not defined. no-undef",
"20:28 'selector' is not defined. no-undef",
"20:47 'Selection' is not defined. no-undef",
"21:2 Newline required at end of file but not found. eol-last"
],
"script",
{
baseConfig: {
extends: ["eslint:all"]
}
}
);
});
it("should correctly apply no-unreachable on TS-constructs (#127)", () => {
verifyAndAssertMessages(
unpad(`
export namespace foo {
export function bar() {
return;
}
}
export type Qux = true;
`),
{
"no-unreachable": 2
},
[]
);
});
// it("should not produce a false positive for no-restricted-globals rule (#350)", () => {
// verifyAndAssertMessages(
// unpad(`
// type foo = {
// location: any;
// };
// `),
// {
// "no-restricted-globals": [2, "location"]
// },
// []
// );
// });
// it("should not throw a TypeError in the indent rule for invalid code (#309)", () => {
// verifyAndAssertMessages(
// unpad(`
// const
// `),
// {
// indent: "error"
// },
// []
// );
// });
// it("class properties and no-undef", () => {
// verifyAndAssertMessages(
// "class Lol { foo = 'bar'; }",
// { "no-undef": 1 },
// []
// );
// });
});