Skip to content

Commit 86359a8

Browse files
committed
feat: string based search
1 parent 7a0a65c commit 86359a8

Some content is hidden

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

42 files changed

+1310
-1637
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"node/shebang": "off",
1919
"@typescript-eslint/no-unused-vars": "off",
2020
"node/no-unpublished-import": "off",
21-
"node/no-unpublished-require": "off"
21+
"node/no-unpublished-require": "off",
22+
"@typescript-eslint/no-var-requires":"off"
2223
}
2324
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ pkg.zip
99
.DS_Store
1010
crate/target
1111
crate/pkg
12-
crate-prod
12+
crate-prod
13+
ts-dist

LICENSE.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Sustainable Use License
2+
3+
Version 1.0
4+
5+
## Acceptance
6+
7+
By using the software, you agree to all of the terms and conditions below.
8+
9+
## Copyright License
10+
11+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations below.
12+
13+
## Limitations
14+
15+
You may use or modify the software only for your own internal business purposes or for non-commercial or personal use.
16+
You may distribute the software or provide it to others only if you do so free of charge for non-commercial purposes.
17+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
18+
19+
## Patents
20+
21+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
22+
23+
## Notices
24+
25+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
26+
If you modify the software, you must include in any modified copies of the software a prominent notice stating that you have modified the software.
27+
28+
## No Other Rights
29+
30+
These terms do not imply any licenses other than those expressly granted in these terms.
31+
32+
## Termination
33+
34+
If you use the software in violation of these terms, such use is not licensed, and your license will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your license will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your license to terminate automatically and permanently.
35+
36+
## No Liability
37+
38+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
39+
40+
## Definitions
41+
42+
The “licensor” is the entity offering these terms.
43+
44+
The “software” is the software the licensor makes available under these terms, including any portion of it.
45+
46+
“You” refers to the individual or entity agreeing to these terms.
47+
48+
“Your company” is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. Control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
49+
50+
“Your license” is the license granted to you for the software under these terms.
51+
52+
“Use” means anything you do with the software requiring your license.
53+
54+
“Trademark” means trademarks, service marks, and similar rights.

__tests__/search/JSX.test.ts

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { search } from '/search'
1+
import { searchInFileSystem } from '/searchInFs'
22
import { compareCode } from '/astUtils'
33
import path from 'path'
44
import { getFilesList } from '/getFilesList'
@@ -32,6 +32,11 @@ describe('JSX', () => {
3232
Press to
3333
Download
3434
</Button>
35+
36+
<Button>
37+
Click
38+
<Icon />
39+
</Button>
3540
</>
3641
`
3742
)
@@ -43,7 +48,7 @@ describe('JSX', () => {
4348

4449
it('Should find all self-closing JSX', () => {
4550
const query = `<$$ />`
46-
const { matches } = search({
51+
const { matches } = searchInFileSystem({
4752
mode: 'include',
4853
filePaths: filesList,
4954
queryCodes: [query]
@@ -56,7 +61,7 @@ describe('JSX', () => {
5661
<Drawer.Section title="Preferences">
5762
</Drawer.Section>
5863
`
59-
const { matches } = search({
64+
const { matches } = searchInFileSystem({
6065
mode: 'include',
6166
filePaths: filesList,
6267
queryCodes: [query]
@@ -88,7 +93,7 @@ describe('JSX', () => {
8893

8994
it('Should find JSX by prop name', () => {
9095
const query = `<$$ value={$$$} />`
91-
const { matches } = search({
96+
const { matches } = searchInFileSystem({
9297
mode: 'include',
9398
filePaths: filesList,
9499
queryCodes: [query]
@@ -98,7 +103,7 @@ describe('JSX', () => {
98103

99104
it('Should find JSX by text content', () => {
100105
const query = `<Text>RTL</Text>`
101-
const { matches } = search({
106+
const { matches } = searchInFileSystem({
102107
mode: 'include',
103108
filePaths: filesList,
104109
queryCodes: [query]
@@ -113,7 +118,7 @@ describe('JSX', () => {
113118
Download
114119
</Button>
115120
`
116-
const { matches } = search({
121+
const { matches } = searchInFileSystem({
117122
mode: 'include',
118123
filePaths: mockedFilesList,
119124
queryCodes: [query]
@@ -123,7 +128,7 @@ describe('JSX', () => {
123128

124129
it('Should find JSX by text content with wildcard case insensitive', () => {
125130
const query = `<Text>r$$L</Text>`
126-
const { matches } = search({
131+
const { matches } = searchInFileSystem({
127132
mode: 'include',
128133
filePaths: filesList,
129134
queryCodes: [query],
@@ -134,7 +139,7 @@ describe('JSX', () => {
134139

135140
it('Should find JSX by text content case insensitive', () => {
136141
const query = `<Text>rtl</Text>`
137-
const { matches } = search({
142+
const { matches } = searchInFileSystem({
138143
mode: 'include',
139144
filePaths: filesList,
140145
caseInsensitive: true,
@@ -155,7 +160,7 @@ describe('JSX', () => {
155160
/>
156161
</View>
157162
`
158-
const { matches } = search({
163+
const { matches } = searchInFileSystem({
159164
mode: 'exact',
160165
filePaths: filesList,
161166
queryCodes: [query]
@@ -175,13 +180,13 @@ describe('JSX', () => {
175180
} from 'react-native-paper';
176181
`
177182

178-
const { matches: resultsUsage } = search({
183+
const { matches: resultsUsage } = searchInFileSystem({
179184
mode: 'include',
180185
filePaths: filesList,
181186
queryCodes: [usageQuery]
182187
})
183188

184-
const { matches: resultsImport } = search({
189+
const { matches: resultsImport } = searchInFileSystem({
185190
mode: 'include',
186191
filePaths: filesList,
187192
queryCodes: [importQuery]
@@ -205,7 +210,7 @@ describe('JSX', () => {
205210
$$={IconButton}
206211
/>
207212
`
208-
const { matches } = search({
213+
const { matches } = searchInFileSystem({
209214
mode: 'include',
210215
filePaths: filesList,
211216
queryCodes: [query1, query2]
@@ -229,7 +234,7 @@ describe('JSX', () => {
229234
`
230235
]
231236

232-
const { matches } = search({
237+
const { matches } = searchInFileSystem({
233238
mode: 'include',
234239
filePaths: filesList,
235240
queryCodes: queries
@@ -263,7 +268,7 @@ describe('JSX', () => {
263268
`
264269
]
265270

266-
const { matches } = search({
271+
const { matches } = searchInFileSystem({
267272
mode: 'include',
268273
filePaths: filesList,
269274
queryCodes: queries
@@ -293,7 +298,7 @@ describe('JSX', () => {
293298
`
294299
]
295300

296-
const { matches } = search({
301+
const { matches } = searchInFileSystem({
297302
mode: 'include',
298303
filePaths: filesList,
299304
queryCodes: queries
@@ -320,7 +325,7 @@ describe('JSX', () => {
320325
`
321326
]
322327

323-
const { matches } = search({
328+
const { matches } = searchInFileSystem({
324329
mode: 'include',
325330
filePaths: filesList,
326331
queryCodes: queries
@@ -338,13 +343,13 @@ describe('JSX', () => {
338343
`
339344
]
340345

341-
const { matches } = search({
346+
const { matches } = searchInFileSystem({
342347
mode: 'include',
343348
filePaths: mockedFilesList,
344349
queryCodes: queries
345350
})
346351

347-
expect(matches.length).toBe(2)
352+
expect(matches.length).toBe(3)
348353
expect(
349354
compareCode(
350355
matches[0].code,
@@ -356,4 +361,33 @@ describe('JSX', () => {
356361
)
357362
).toBeTruthy()
358363
})
364+
365+
it('Should match code with nested JSX when using wildcard on text content', () => {
366+
const queries = [
367+
`
368+
<Button>
369+
c$$$
370+
</Button>;
371+
`
372+
]
373+
374+
const { matches } = searchInFileSystem({
375+
mode: 'include',
376+
caseInsensitive: true,
377+
filePaths: mockedFilesList,
378+
queryCodes: queries
379+
})
380+
381+
expect(matches.length).toBe(1)
382+
expect(
383+
compareCode(
384+
matches[0].code,
385+
` <Button>
386+
Click
387+
<Icon />
388+
</Button>
389+
`
390+
)
391+
).toBeTruthy()
392+
})
359393
})

__tests__/search/blocks.test.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,71 @@
1-
2-
import { search } from '/search'
3-
import { compareCode } from '/astUtils';
1+
import { searchInFileSystem } from '/searchInFs'
2+
import { compareCode } from '/astUtils'
43
import path from 'path'
54
import { getFilesList } from '/getFilesList'
65

7-
86
describe('blocks', () => {
97
let filesList = [] as string[]
108

119
beforeAll(async () => {
12-
filesList = await getFilesList(path.resolve(__dirname, '__fixtures__'))
10+
filesList = await getFilesList(path.resolve(__dirname, '__fixtures__'))
1311
})
1412

1513
it('should match exact whole block', () => {
16-
const queries = [`
17-
{
14+
const queries = [
15+
`
16+
() => {
1817
toggleRTL();
1918
I18nManager.forceRTL(!isRTL);
2019
Updates.reloadAsync();
2120
}
2221
`
2322
]
2423

25-
const { matches } = search({
24+
const { matches } = searchInFileSystem({
2625
mode: 'exact',
2726
filePaths: filesList,
28-
queryCodes: queries,
27+
queryCodes: queries
2928
})
3029

3130
expect(matches.length).toBe(1)
3231
expect(compareCode(matches[0].code, queries[0])).toBeTruthy()
3332
})
3433

34+
it('should match block using query without all statements and different order', () => {
35+
const queries = [
36+
`
37+
() => {
38+
Updates.reloadAsync();
39+
toggleRTL();
40+
}
41+
`
42+
]
43+
44+
const { matches } = searchInFileSystem({
45+
mode: 'include',
46+
filePaths: filesList,
47+
queryCodes: queries
48+
})
3549

36-
})
50+
expect(matches.length).toBe(1)
51+
})
52+
53+
it('should match block using query without all statements, but with order', () => {
54+
const queries = [
55+
`
56+
() => {
57+
toggleRTL();
58+
Updates.reloadAsync();
59+
}
60+
`
61+
]
62+
63+
const { matches } = searchInFileSystem({
64+
mode: 'include-with-order',
65+
filePaths: filesList,
66+
queryCodes: queries
67+
})
68+
69+
expect(matches.length).toBe(1)
70+
})
71+
})

0 commit comments

Comments
 (0)