Skip to content

Commit dd9de35

Browse files
committed
feat(core): add support for @typescript-eslint/parser 😎
1 parent b2dc39b commit dd9de35

File tree

57 files changed

+882
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+882
-373
lines changed

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"@typescript-eslint/eslint-plugin": "^5.16.0",
1616
"@typescript-eslint/parser": "^5.16.0",
1717
"babel-plugin-root-import": "^6.6.0",
18-
"dpdm": "^3.9.0",
1918
"eslint": "^7.11.0",
2019
"eslint-config-prettier": "^8.5.0",
2120
"eslint-plugin-jest": "^24.1.0",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getUniqueTokens, extractQueryNode } from '../src/parseQuery'
2+
import { getParserSettings } from './utils'
3+
4+
describe('parse query', () => {
5+
const parserSettings = getParserSettings()
6+
7+
it('should get unique tokens', () => {
8+
const queryCode = `
9+
require('some$$wildcard$$string')
10+
const a = 'b'
11+
const alpha = 'beta'
12+
type MyType = boolean
13+
123;
14+
{
15+
{
16+
() => {
17+
0x0;
18+
return 'test'
19+
}
20+
}
21+
}
22+
`
23+
const { queryNode } = extractQueryNode(
24+
parserSettings.parseCode(queryCode),
25+
parserSettings,
26+
)
27+
28+
const uniqueTokens = [...getUniqueTokens(queryNode, false, parserSettings)]
29+
30+
expect(uniqueTokens).toMatchObject([
31+
'require',
32+
'some',
33+
'wildcard',
34+
'string',
35+
'alpha',
36+
'beta',
37+
'MyType',
38+
'123',
39+
'test',
40+
])
41+
})
42+
})

‎packages/core/__tests__/search/JSX.test.ts‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ describe('JSX', () => {
245245
it('Should find all anonymous functions passed as a prop', () => {
246246
const queries = [
247247
`
248-
<$$$
249-
$$={() => $$$}
250-
/>
251-
`,
248+
<$$$
249+
$$={() => $$$}
250+
/>
251+
`,
252252
`
253-
<$$$
254-
$$={() => $$$}
255-
>
256-
</$$$>
257-
`,
253+
<$$$
254+
$$={() => $$$}
255+
>
256+
</$$$>
257+
`,
258258
]
259259

260260
const { matches, errors } = searchInFileSystem({
@@ -272,9 +272,9 @@ describe('JSX', () => {
272272
/>
273273
`
274274

275+
expect(errors).toHaveLength(0)
275276
expect(matches.length).toBe(190)
276277
expect(compareCode(matches[0].code, firstResultCode)).toBeTruthy()
277-
expect(errors).toHaveLength(0)
278278
})
279279

280280
it('Should find all anonymous functions passed as event listener handler', () => {
@@ -307,9 +307,9 @@ describe('JSX', () => {
307307
/>
308308
`
309309

310+
expect(errors).toHaveLength(0)
310311
expect(matches.length).toBe(164)
311312
expect(compareCode(matches[0].code, firstResultCode)).toBeTruthy()
312-
expect(errors).toHaveLength(0)
313313
})
314314

315315
it('Should find all Elements pretending to be a wrapper', () => {
@@ -329,8 +329,8 @@ describe('JSX', () => {
329329
queryCodes: queries,
330330
})
331331

332-
expect(matches.length).toBe(34)
333332
expect(errors).toHaveLength(0)
333+
expect(matches.length).toBe(34)
334334
})
335335

336336
it('Should find all title prop values which are strings', () => {
@@ -357,8 +357,8 @@ describe('JSX', () => {
357357
queryCodes: queries,
358358
})
359359

360-
expect(matches.length).toBe(78)
361360
expect(errors).toHaveLength(0)
361+
expect(matches.length).toBe(78)
362362
})
363363

364364
it('Should ignore all empty JSXText in search', () => {
@@ -451,8 +451,8 @@ describe('JSX', () => {
451451
],
452452
})
453453

454-
expect(matches.length).toBe(4)
455454
expect(errors.length).toBe(0)
455+
expect(matches.length).toBe(4)
456456
})
457457

458458
it('Not self-closing JSX tag in query should match also self-closing tags', () => {
@@ -483,8 +483,8 @@ describe('JSX', () => {
483483
],
484484
})
485485

486-
expect(matches.length).toBe(4)
487486
expect(errors.length).toBe(0)
487+
expect(matches.length).toBe(4)
488488
})
489489

490490
it('Not self-closing JSX tag with children in query should not match self-closing tags', () => {
@@ -544,8 +544,8 @@ describe('JSX', () => {
544544
],
545545
})
546546

547-
expect(matches.length).toBe(2)
548547
expect(errors.length).toBe(0)
548+
expect(matches.length).toBe(2)
549549
})
550550
})
551551

@@ -573,8 +573,8 @@ describe('JSX', () => {
573573
],
574574
})
575575

576-
expect(matches.length).toBe(2)
577576
expect(errors.length).toBe(0)
577+
expect(matches.length).toBe(2)
578578
})
579579

580580
it('Should match JSXIdentifier when looking for Identifier wildcard', () => {
@@ -600,8 +600,8 @@ describe('JSX', () => {
600600
],
601601
})
602602

603-
expect(matches.length).toBe(2)
604603
expect(errors.length).toBe(0)
604+
expect(matches.length).toBe(2)
605605
})
606606
})
607607

@@ -628,7 +628,7 @@ describe('JSX', () => {
628628
],
629629
})
630630

631-
expect(matches.length).toBe(0)
632631
expect(errors.length).toBe(0)
632+
expect(matches.length).toBe(0)
633633
})
634634
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { searchInStrings } from '../../src/searchInStrings'
2+
3+
describe('Basic queries', () => {
4+
it('Should match identifier in file', () => {
5+
const fileContent = `const someId = 'aaa'`
6+
7+
const queries = [`someId`]
8+
9+
const { matches, errors } = searchInStrings({
10+
mode: 'include',
11+
caseInsensitive: true,
12+
queryCodes: queries,
13+
files: [
14+
{
15+
path: 'mock',
16+
content: fileContent,
17+
},
18+
],
19+
})
20+
21+
expect(errors.length).toBe(0)
22+
expect(matches.length).toBe(1)
23+
})
24+
})

‎packages/core/__tests__/search/blocks.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,33 @@ describe('blocks', () => {
120120
expect(errors.length).toBe(0)
121121
expect(matches.length).toBe(2)
122122
})
123+
124+
it('should match arrow function block using tree wildcard', () => {
125+
const fileContent = `
126+
const a = () => {
127+
console.log()
128+
}
129+
`
130+
131+
const queries = [
132+
`
133+
() => $$$
134+
`,
135+
]
136+
137+
const { matches, errors } = searchInStrings({
138+
mode: 'exact',
139+
caseInsensitive: true,
140+
queryCodes: queries,
141+
files: [
142+
{
143+
path: 'mock',
144+
content: fileContent,
145+
},
146+
],
147+
})
148+
149+
expect(errors.length).toBe(0)
150+
expect(matches.length).toBe(1)
151+
})
123152
})

‎packages/core/__tests__/search/literals.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path'
33
import fs from 'fs'
44
import { searchInStrings } from '../../src/searchInStrings'
55

6-
describe('Types', () => {
6+
describe('Literals', () => {
77
const tempFilePath = path.join(
88
__dirname,
99
'__fixtures__',
@@ -110,9 +110,9 @@ describe('Types', () => {
110110
queryCodes: queries2,
111111
})
112112

113-
expect(results2.length).toBe(2)
114113
expect(errors1).toHaveLength(0)
115114
expect(errors2).toHaveLength(0)
115+
expect(results2.length).toBe(2)
116116
})
117117

118118
it('should match string using pattern', () => {
@@ -202,8 +202,8 @@ describe('Types', () => {
202202
queryCodes: queries,
203203
})
204204

205-
expect(matches.length).toBe(0)
206205
expect(errors.length).toBe(0)
206+
expect(matches.length).toBe(0)
207207
})
208208

209209
it('should match template literals with quasis', () => {
@@ -278,8 +278,8 @@ describe('Types', () => {
278278
],
279279
})
280280

281-
expect(matches1.length).toBe(1)
282281
expect(errors1.length).toBe(0)
282+
expect(matches1.length).toBe(1)
283283

284284
const { matches: matches2, errors: errors2 } = searchInStrings({
285285
mode: 'include',
@@ -293,8 +293,8 @@ describe('Types', () => {
293293
],
294294
})
295295

296-
expect(matches2.length).toBe(1)
297296
expect(errors2.length).toBe(0)
297+
expect(matches2.length).toBe(1)
298298

299299
const { matches: matches3, errors: errors3 } = searchInStrings({
300300
mode: 'include',
@@ -308,8 +308,8 @@ describe('Types', () => {
308308
],
309309
})
310310

311-
expect(matches3.length).toBe(1)
312311
expect(errors3.length).toBe(0)
312+
expect(matches3.length).toBe(1)
313313
})
314314

315315
it('should match multiline template literals with include mode', () => {

‎packages/core/__tests__/search/objects.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { searchInFileSystem } from '/searchInFs'
22
import { compareCode } from '../utils'
33
import path from 'path'
4-
import fs from 'fs'
54
import { getFilesList } from '/getFilesList'
65
import { searchInStrings } from '../../src/searchInStrings'
76

8-
describe('Types', () => {
7+
describe('Objects', () => {
98
const testFile = `
109
({
1110
a : {
@@ -226,8 +225,8 @@ describe('Types', () => {
226225
queryCodes: queries,
227226
})
228227

229-
expect(matches.length).toBe(1) // It used to be 0, but now `{}` matches program as a block matches program
230228
expect(errors.length).toBe(0)
229+
expect(matches.length).toBe(1) // It used to be 0, but now `{}` matches program as a block matches program
231230
})
232231

233232
it('should match function in object', () => {
@@ -374,10 +373,10 @@ describe('Types', () => {
374373
queryCodes: [query2],
375374
})
376375

377-
expect(matches1.length).toBe(4)
378376
expect(errors1.length).toBe(0)
377+
expect(matches1.length).toBe(4)
379378

380-
expect(matches2.length).toBe(4)
381379
expect(errors2.length).toBe(0)
380+
expect(matches2.length).toBe(4)
382381
})
383382
})

‎packages/core/__tests__/search/other.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ describe('Other', () => {
8282
queryCodes: queries,
8383
})
8484

85-
expect(matches.length).toBe(17149)
8685
expect(errors.length).toBe(0)
86+
expect(matches.length).toBe(17149)
8787
})
8888

8989
it('Should properly match identifiers with multiple wildcard sections', () => {

0 commit comments

Comments
 (0)