@toptal/davinci-syntax 8.0.3 → 8.0.4-alpha-tph-1237-github-test-results.1302
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/dist-package/package.json +0 -79
- package/src/__snapshots__/eslint.test.ts.snap +0 -1091
- package/src/eslint.test.ts +0 -309
package/src/eslint.test.ts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { ESLint, Linter } from 'eslint'
|
|
3
|
-
import json5 from 'json5'
|
|
4
|
-
|
|
5
|
-
const getConfig = () => {
|
|
6
|
-
const pathToEslintrc = path.join(__dirname, '../src/configs/.eslintrc')
|
|
7
|
-
|
|
8
|
-
return new ESLint({
|
|
9
|
-
useEslintrc: false, // don't use any other eslintrc files (higher in the folder tree)
|
|
10
|
-
overrideConfigFile: pathToEslintrc // use this exact eslintrc file
|
|
11
|
-
}).calculateConfigForFile(pathToEslintrc)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Eslint config file snapshot file to prevent unexpected updates
|
|
15
|
-
describe('eslint config', () => {
|
|
16
|
-
let fileConfig: Record<string, any>
|
|
17
|
-
|
|
18
|
-
beforeAll(async () => {
|
|
19
|
-
fileConfig = await getConfig()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('verifies eslint rules are not updated silently', () => {
|
|
23
|
-
const serializedRules = json5.stringify(fileConfig.rules, null, 2)
|
|
24
|
-
|
|
25
|
-
expect(serializedRules).toMatchSnapshot()
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
/* eslint-disable max-statements */
|
|
30
|
-
/* eslint-disable max-lines-per-function */
|
|
31
|
-
// Testing basic rules with the davinci eslint
|
|
32
|
-
describe('eslint rules', () => {
|
|
33
|
-
let engine: ESLint
|
|
34
|
-
|
|
35
|
-
beforeAll(async () => {
|
|
36
|
-
engine = new ESLint({ baseConfig: await getConfig() })
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const findMessage = (ruleId: string, results: ESLint.LintResult[]) => {
|
|
40
|
-
return results.reduce<Linter.LintMessage | undefined>(
|
|
41
|
-
(_, result) => result.messages.find(message => message.ruleId === ruleId),
|
|
42
|
-
undefined
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface TestRulesArgs {
|
|
47
|
-
ruleId: string
|
|
48
|
-
validCases?: string[]
|
|
49
|
-
invalidCases?: string[]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const testRule = ({
|
|
53
|
-
ruleId,
|
|
54
|
-
validCases = [],
|
|
55
|
-
invalidCases = []
|
|
56
|
-
}: TestRulesArgs) => {
|
|
57
|
-
it(`verifies that ${ruleId} works`, async () => {
|
|
58
|
-
for (const validText of validCases) {
|
|
59
|
-
const results = await engine.lintText(validText)
|
|
60
|
-
|
|
61
|
-
expect(findMessage(ruleId, results)).not.toBeDefined()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (const invalidText of invalidCases) {
|
|
65
|
-
const results = await engine.lintText(invalidText)
|
|
66
|
-
|
|
67
|
-
expect(findMessage(ruleId, results)).toBeDefined()
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
testRule({
|
|
73
|
-
ruleId: 'space-before-function-paren',
|
|
74
|
-
invalidCases: [
|
|
75
|
-
'function withoutSpace (x) {}',
|
|
76
|
-
'var anonymousWithoutSpace = function () {};'
|
|
77
|
-
],
|
|
78
|
-
validCases: [
|
|
79
|
-
'function withoutSpace(x) {}',
|
|
80
|
-
'var anonymousWithoutSpace = function() {};'
|
|
81
|
-
]
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
testRule({
|
|
85
|
-
ruleId: 'padding-line-between-statements',
|
|
86
|
-
invalidCases: [
|
|
87
|
-
`
|
|
88
|
-
function foo() {
|
|
89
|
-
bar();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
`
|
|
93
|
-
],
|
|
94
|
-
validCases: [
|
|
95
|
-
`
|
|
96
|
-
function foo() {
|
|
97
|
-
bar();
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
`
|
|
102
|
-
]
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
testRule({
|
|
106
|
-
ruleId: 'prefer-const',
|
|
107
|
-
invalidCases: [
|
|
108
|
-
`
|
|
109
|
-
let a = 3
|
|
110
|
-
console.log(a)
|
|
111
|
-
`
|
|
112
|
-
],
|
|
113
|
-
validCases: [
|
|
114
|
-
`
|
|
115
|
-
let a = 3
|
|
116
|
-
a = 0
|
|
117
|
-
console.log(a)
|
|
118
|
-
`
|
|
119
|
-
]
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
testRule({
|
|
123
|
-
ruleId: 'id-length',
|
|
124
|
-
invalidCases: ['const x = 5'],
|
|
125
|
-
validCases: [
|
|
126
|
-
'var ok = 5',
|
|
127
|
-
'const foo = { ok: 1 }',
|
|
128
|
-
`const _ = 'unused'`,
|
|
129
|
-
`
|
|
130
|
-
try {
|
|
131
|
-
throw new Error();
|
|
132
|
-
} catch (e) {
|
|
133
|
-
console.error(e)
|
|
134
|
-
}
|
|
135
|
-
`
|
|
136
|
-
]
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
testRule({
|
|
140
|
-
ruleId: 'quotes',
|
|
141
|
-
invalidCases: ['const foo = "bar"'],
|
|
142
|
-
validCases: [`const foo = 'bar'`]
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
testRule({
|
|
146
|
-
ruleId: 'no-else-return',
|
|
147
|
-
invalidCases: [
|
|
148
|
-
`
|
|
149
|
-
function foo() {
|
|
150
|
-
if (x) {
|
|
151
|
-
return y
|
|
152
|
-
} else {
|
|
153
|
-
return z
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
`
|
|
157
|
-
],
|
|
158
|
-
validCases: [
|
|
159
|
-
`
|
|
160
|
-
function foo() {
|
|
161
|
-
if (x) {
|
|
162
|
-
return y
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return z
|
|
166
|
-
}
|
|
167
|
-
`
|
|
168
|
-
]
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
testRule({
|
|
172
|
-
ruleId: 'import/no-extraneous-dependencies',
|
|
173
|
-
invalidCases: [`import { ESLint } from 'eslint'`],
|
|
174
|
-
validCases: [`import fs from 'fs'`]
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
testRule({
|
|
178
|
-
ruleId: '@typescript-eslint/array-type',
|
|
179
|
-
invalidCases: [`const foo: Array<string> = ['a', 'b']`],
|
|
180
|
-
validCases: [`const foo: string[] = ['a', 'b']`]
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
testRule({
|
|
184
|
-
ruleId: '@typescript-eslint/array-type',
|
|
185
|
-
invalidCases: [`const foo: Array<string> = ['a', 'b']`],
|
|
186
|
-
validCases: [`const foo: string[] = ['a', 'b']`]
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
testRule({
|
|
190
|
-
ruleId: '@typescript-eslint/array-type',
|
|
191
|
-
invalidCases: [`const foo: Array<string> = ['a', 'b']`],
|
|
192
|
-
validCases: [`const foo: string[] = ['a', 'b']`]
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
testRule({
|
|
196
|
-
ruleId: '@typescript-eslint/explicit-function-return-type',
|
|
197
|
-
validCases: [`const foo = (): number => 1`, `const foo = () => 1`]
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
testRule({
|
|
201
|
-
ruleId: '@typescript-eslint/no-use-before-define',
|
|
202
|
-
invalidCases: [
|
|
203
|
-
`
|
|
204
|
-
foo()
|
|
205
|
-
|
|
206
|
-
const foo = () => {}
|
|
207
|
-
`
|
|
208
|
-
],
|
|
209
|
-
validCases: [
|
|
210
|
-
`
|
|
211
|
-
const foo = () => {}
|
|
212
|
-
|
|
213
|
-
foo()
|
|
214
|
-
`
|
|
215
|
-
]
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
testRule({
|
|
219
|
-
ruleId: '@typescript-eslint/no-unused-vars',
|
|
220
|
-
invalidCases: ['const foo = 1'],
|
|
221
|
-
validCases: [
|
|
222
|
-
`
|
|
223
|
-
const foo = 1
|
|
224
|
-
|
|
225
|
-
console.log(foo)
|
|
226
|
-
`
|
|
227
|
-
]
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
testRule({
|
|
231
|
-
ruleId: '@typescript-eslint/func-call-spacing',
|
|
232
|
-
invalidCases: ['foo ()', 'foo<T> ()'],
|
|
233
|
-
validCases: ['foo()', 'foo<T>()']
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
testRule({
|
|
237
|
-
ruleId: '@typescript-eslint/no-unused-expressions',
|
|
238
|
-
invalidCases: ['if (0) null'],
|
|
239
|
-
validCases: ['if (0) return null']
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
testRule({
|
|
243
|
-
ruleId: '@typescript-eslint/ban-types',
|
|
244
|
-
invalidCases: [`const foo: String = 'foo'`, 'const foo: Number = 1'],
|
|
245
|
-
validCases: [
|
|
246
|
-
'const foo: Function = () => 1',
|
|
247
|
-
'const foo: object = {}',
|
|
248
|
-
'const foo: {} = {}'
|
|
249
|
-
]
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
testRule({
|
|
253
|
-
ruleId: 'func-style',
|
|
254
|
-
invalidCases: ['function foo() {}'],
|
|
255
|
-
validCases: ['const foo = function() {}']
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
testRule({
|
|
259
|
-
ruleId: 'curly',
|
|
260
|
-
invalidCases: ['if (foo) foo++'],
|
|
261
|
-
validCases: ['if (foo) { foo++ }']
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
testRule({
|
|
265
|
-
ruleId: 'todo-plz/ticket-ref',
|
|
266
|
-
invalidCases: [
|
|
267
|
-
'// TODO:',
|
|
268
|
-
'// TODO: lorem',
|
|
269
|
-
'// TODO :',
|
|
270
|
-
'// TODO: [FX-]',
|
|
271
|
-
'// TODO: [-000]',
|
|
272
|
-
'// TODO: [-AAA]',
|
|
273
|
-
'// TODO [FX-000]',
|
|
274
|
-
'// TODO:[FX-000]',
|
|
275
|
-
'// TODO: FX-000',
|
|
276
|
-
'// TODO: lorem FX-000 ipsum',
|
|
277
|
-
`/**
|
|
278
|
-
* TODO:
|
|
279
|
-
*/`,
|
|
280
|
-
`/**
|
|
281
|
-
* TODO: lorem
|
|
282
|
-
*/`
|
|
283
|
-
],
|
|
284
|
-
validCases: [
|
|
285
|
-
'// TODO: [FX-000]',
|
|
286
|
-
'// TODO: [SPC-000]',
|
|
287
|
-
'// TODO: [FX-000] [SPC-000]',
|
|
288
|
-
'// TODO: [FX-000], [SPC-000]',
|
|
289
|
-
'// TODO: [FX-000], [SPC-000],',
|
|
290
|
-
'// TODO: [FX-000] [SPC-000],',
|
|
291
|
-
'// TODO: lorem [FX-000] [SPC-000],',
|
|
292
|
-
'// TODO: [FX-000] [SPC-000], lorem',
|
|
293
|
-
`/**
|
|
294
|
-
* TODO: [FX-000] lorem
|
|
295
|
-
*/`,
|
|
296
|
-
`/**
|
|
297
|
-
* TODO: lorem [FX-000] ipsum
|
|
298
|
-
*/`,
|
|
299
|
-
`/**
|
|
300
|
-
* TODO: lorem ipsum
|
|
301
|
-
* lorem [FX-000]
|
|
302
|
-
*/`,
|
|
303
|
-
`/**
|
|
304
|
-
* TODO: lorem ipsum
|
|
305
|
-
* [FX-000]
|
|
306
|
-
*/`
|
|
307
|
-
]
|
|
308
|
-
})
|
|
309
|
-
})
|