@eslint-config-snapshot/api 0.1.0 → 0.1.4
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/CHANGELOG.md +25 -0
- package/package.json +9 -1
- package/project.json +2 -2
- package/src/config.ts +116 -116
- package/src/core.ts +1 -1
- package/src/diff.ts +1 -1
- package/src/extract.ts +119 -119
- package/src/sampling.ts +136 -136
- package/src/snapshot.ts +1 -1
- package/src/workspace.ts +130 -130
- package/test/api.test.ts +1 -1
- package/test/config.test.ts +100 -100
- package/test/core.test.ts +1 -1
- package/test/extract.test.ts +140 -140
- package/test/sampling.test.ts +91 -91
- package/test/snapshot.test.ts +64 -64
- package/test/workspace.test.ts +1 -1
- package/tsconfig.json +12 -12
package/test/sampling.test.ts
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import os from 'node:os'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
-
|
|
6
|
-
import { sampleWorkspaceFiles } from '../src/index.js'
|
|
7
|
-
|
|
8
|
-
const tmp = path.join(os.tmpdir(), `snapshot-sampling-${Date.now()}`)
|
|
9
|
-
|
|
10
|
-
afterAll(async () => {
|
|
11
|
-
await import('node:fs/promises').then((fs) => fs.rm(tmp, { recursive: true, force: true }))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('sampleWorkspaceFiles', () => {
|
|
15
|
-
it('returns deterministic sorted sample', async () => {
|
|
16
|
-
await mkdir(path.join(tmp, 'src'), { recursive: true })
|
|
17
|
-
await writeFile(path.join(tmp, 'src', 'b.ts'), '')
|
|
18
|
-
await writeFile(path.join(tmp, 'src', 'a.ts'), '')
|
|
19
|
-
|
|
20
|
-
const result = await sampleWorkspaceFiles(tmp, {
|
|
21
|
-
maxFilesPerWorkspace: 8,
|
|
22
|
-
includeGlobs: ['**/*.ts'],
|
|
23
|
-
excludeGlobs: [],
|
|
24
|
-
hintGlobs: []
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
expect(result).toEqual(['src/a.ts', 'src/b.ts'])
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('selects uniformly distributed files when candidates exceed max', async () => {
|
|
31
|
-
await mkdir(path.join(tmp, 'many'), { recursive: true })
|
|
32
|
-
for (let index = 0; index < 20; index += 1) {
|
|
33
|
-
const name = `file-${String(index).padStart(2, '0')}.ts`
|
|
34
|
-
await writeFile(path.join(tmp, 'many', name), '')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const result = await sampleWorkspaceFiles(tmp, {
|
|
38
|
-
maxFilesPerWorkspace: 8,
|
|
39
|
-
includeGlobs: ['many/**/*.ts'],
|
|
40
|
-
excludeGlobs: [],
|
|
41
|
-
hintGlobs: []
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
expect(result).toEqual([
|
|
45
|
-
'many/file-00.ts',
|
|
46
|
-
'many/file-01.ts',
|
|
47
|
-
'many/file-04.ts',
|
|
48
|
-
'many/file-07.ts',
|
|
49
|
-
'many/file-10.ts',
|
|
50
|
-
'many/file-13.ts',
|
|
51
|
-
'many/file-16.ts',
|
|
52
|
-
'many/file-19.ts'
|
|
53
|
-
])
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('prefers token-diverse hinted files before fallback spacing', async () => {
|
|
57
|
-
await mkdir(path.join(tmp, 'tokens'), { recursive: true })
|
|
58
|
-
const files = [
|
|
59
|
-
'tokens/auth.service.ts',
|
|
60
|
-
'tokens/billing.service.ts',
|
|
61
|
-
'tokens/catalog.service.ts',
|
|
62
|
-
'tokens/auth.controller.ts',
|
|
63
|
-
'tokens/billing.controller.ts',
|
|
64
|
-
'tokens/catalog.controller.ts',
|
|
65
|
-
'tokens/shared.util.ts',
|
|
66
|
-
'tokens/shared.helper.ts',
|
|
67
|
-
'tokens/shared.format.ts',
|
|
68
|
-
'tokens/shared.view.ts'
|
|
69
|
-
]
|
|
70
|
-
|
|
71
|
-
for (const file of files) {
|
|
72
|
-
await writeFile(path.join(tmp, file), '')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const result = await sampleWorkspaceFiles(tmp, {
|
|
76
|
-
maxFilesPerWorkspace: 6,
|
|
77
|
-
includeGlobs: ['tokens/**/*.ts'],
|
|
78
|
-
excludeGlobs: [],
|
|
79
|
-
hintGlobs: ['tokens/**/*.service.ts']
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
expect(result).toEqual([
|
|
83
|
-
'tokens/auth.controller.ts',
|
|
84
|
-
'tokens/auth.service.ts',
|
|
85
|
-
'tokens/billing.service.ts',
|
|
86
|
-
'tokens/catalog.service.ts',
|
|
87
|
-
'tokens/shared.format.ts',
|
|
88
|
-
'tokens/shared.view.ts'
|
|
89
|
-
])
|
|
90
|
-
})
|
|
91
|
-
})
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { sampleWorkspaceFiles } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
const tmp = path.join(os.tmpdir(), `snapshot-sampling-${Date.now()}`)
|
|
9
|
+
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
await import('node:fs/promises').then((fs) => fs.rm(tmp, { recursive: true, force: true }))
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('sampleWorkspaceFiles', () => {
|
|
15
|
+
it('returns deterministic sorted sample', async () => {
|
|
16
|
+
await mkdir(path.join(tmp, 'src'), { recursive: true })
|
|
17
|
+
await writeFile(path.join(tmp, 'src', 'b.ts'), '')
|
|
18
|
+
await writeFile(path.join(tmp, 'src', 'a.ts'), '')
|
|
19
|
+
|
|
20
|
+
const result = await sampleWorkspaceFiles(tmp, {
|
|
21
|
+
maxFilesPerWorkspace: 8,
|
|
22
|
+
includeGlobs: ['**/*.ts'],
|
|
23
|
+
excludeGlobs: [],
|
|
24
|
+
hintGlobs: []
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
expect(result).toEqual(['src/a.ts', 'src/b.ts'])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('selects uniformly distributed files when candidates exceed max', async () => {
|
|
31
|
+
await mkdir(path.join(tmp, 'many'), { recursive: true })
|
|
32
|
+
for (let index = 0; index < 20; index += 1) {
|
|
33
|
+
const name = `file-${String(index).padStart(2, '0')}.ts`
|
|
34
|
+
await writeFile(path.join(tmp, 'many', name), '')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = await sampleWorkspaceFiles(tmp, {
|
|
38
|
+
maxFilesPerWorkspace: 8,
|
|
39
|
+
includeGlobs: ['many/**/*.ts'],
|
|
40
|
+
excludeGlobs: [],
|
|
41
|
+
hintGlobs: []
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
expect(result).toEqual([
|
|
45
|
+
'many/file-00.ts',
|
|
46
|
+
'many/file-01.ts',
|
|
47
|
+
'many/file-04.ts',
|
|
48
|
+
'many/file-07.ts',
|
|
49
|
+
'many/file-10.ts',
|
|
50
|
+
'many/file-13.ts',
|
|
51
|
+
'many/file-16.ts',
|
|
52
|
+
'many/file-19.ts'
|
|
53
|
+
])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('prefers token-diverse hinted files before fallback spacing', async () => {
|
|
57
|
+
await mkdir(path.join(tmp, 'tokens'), { recursive: true })
|
|
58
|
+
const files = [
|
|
59
|
+
'tokens/auth.service.ts',
|
|
60
|
+
'tokens/billing.service.ts',
|
|
61
|
+
'tokens/catalog.service.ts',
|
|
62
|
+
'tokens/auth.controller.ts',
|
|
63
|
+
'tokens/billing.controller.ts',
|
|
64
|
+
'tokens/catalog.controller.ts',
|
|
65
|
+
'tokens/shared.util.ts',
|
|
66
|
+
'tokens/shared.helper.ts',
|
|
67
|
+
'tokens/shared.format.ts',
|
|
68
|
+
'tokens/shared.view.ts'
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
await writeFile(path.join(tmp, file), '')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = await sampleWorkspaceFiles(tmp, {
|
|
76
|
+
maxFilesPerWorkspace: 6,
|
|
77
|
+
includeGlobs: ['tokens/**/*.ts'],
|
|
78
|
+
excludeGlobs: [],
|
|
79
|
+
hintGlobs: ['tokens/**/*.service.ts']
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(result).toEqual([
|
|
83
|
+
'tokens/auth.controller.ts',
|
|
84
|
+
'tokens/auth.service.ts',
|
|
85
|
+
'tokens/billing.service.ts',
|
|
86
|
+
'tokens/catalog.service.ts',
|
|
87
|
+
'tokens/shared.format.ts',
|
|
88
|
+
'tokens/shared.view.ts'
|
|
89
|
+
])
|
|
90
|
+
})
|
|
91
|
+
})
|
package/test/snapshot.test.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
|
2
|
-
import os from 'node:os'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
-
|
|
6
|
-
import { aggregateRules, buildSnapshot, writeSnapshotFile } from '../src/index.js'
|
|
7
|
-
|
|
8
|
-
let tmpDir = ''
|
|
9
|
-
|
|
10
|
-
afterAll(async () => {
|
|
11
|
-
if (tmpDir) {
|
|
12
|
-
await rm(tmpDir, { recursive: true, force: true })
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe('snapshot', () => {
|
|
17
|
-
it('writes deterministic json', async () => {
|
|
18
|
-
tmpDir = await mkdtemp(path.join(os.tmpdir(), 'snapshot-snapshot-'))
|
|
19
|
-
|
|
20
|
-
const snapshot = buildSnapshot('default', ['packages/b', 'packages/a'], new Map([
|
|
21
|
-
['z-rule', ['warn']],
|
|
22
|
-
['a-rule', ['error', { b: 1, a: 2 }]]
|
|
23
|
-
]))
|
|
24
|
-
|
|
25
|
-
const output = await writeSnapshotFile(tmpDir, snapshot)
|
|
26
|
-
const content = await readFile(output, 'utf8')
|
|
27
|
-
|
|
28
|
-
expect(content).toContain('"formatVersion": 1')
|
|
29
|
-
expect(content.endsWith('\n')).toBe(true)
|
|
30
|
-
expect(content.indexOf('"a-rule"')).toBeLessThan(content.indexOf('"z-rule"'))
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('aggregates by highest severity', () => {
|
|
34
|
-
const result = aggregateRules([
|
|
35
|
-
new Map([['no-console', ['warn'] as const]]),
|
|
36
|
-
new Map([['no-console', ['error'] as const], ['eqeqeq', ['error', 'always'] as const]])
|
|
37
|
-
])
|
|
38
|
-
|
|
39
|
-
expect(Object.fromEntries(result.entries())).toEqual({
|
|
40
|
-
eqeqeq: ['error', 'always'],
|
|
41
|
-
'no-console': ['error']
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('uses options from highest severity when severities differ', () => {
|
|
46
|
-
const result = aggregateRules([
|
|
47
|
-
new Map([['no-unused-vars', ['warn', { args: 'none' }] as const]]),
|
|
48
|
-
new Map([['no-unused-vars', ['error', { argsIgnorePattern: '^_' }] as const]])
|
|
49
|
-
])
|
|
50
|
-
|
|
51
|
-
expect(Object.fromEntries(result.entries())).toEqual({
|
|
52
|
-
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }]
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('throws on conflicting options at same severity', () => {
|
|
57
|
-
expect(() =>
|
|
58
|
-
aggregateRules([
|
|
59
|
-
new Map([['no-restricted-imports', ['error', { paths: ['a'] }] as const]]),
|
|
60
|
-
new Map([['no-restricted-imports', ['error', { paths: ['b'] }] as const]])
|
|
61
|
-
])
|
|
62
|
-
).toThrow('Conflicting rule options for no-restricted-imports at severity error')
|
|
63
|
-
})
|
|
64
|
-
})
|
|
1
|
+
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { aggregateRules, buildSnapshot, writeSnapshotFile } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
let tmpDir = ''
|
|
9
|
+
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
if (tmpDir) {
|
|
12
|
+
await rm(tmpDir, { recursive: true, force: true })
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('snapshot', () => {
|
|
17
|
+
it('writes deterministic json', async () => {
|
|
18
|
+
tmpDir = await mkdtemp(path.join(os.tmpdir(), 'snapshot-snapshot-'))
|
|
19
|
+
|
|
20
|
+
const snapshot = buildSnapshot('default', ['packages/b', 'packages/a'], new Map([
|
|
21
|
+
['z-rule', ['warn']],
|
|
22
|
+
['a-rule', ['error', { b: 1, a: 2 }]]
|
|
23
|
+
]))
|
|
24
|
+
|
|
25
|
+
const output = await writeSnapshotFile(tmpDir, snapshot)
|
|
26
|
+
const content = await readFile(output, 'utf8')
|
|
27
|
+
|
|
28
|
+
expect(content).toContain('"formatVersion": 1')
|
|
29
|
+
expect(content.endsWith('\n')).toBe(true)
|
|
30
|
+
expect(content.indexOf('"a-rule"')).toBeLessThan(content.indexOf('"z-rule"'))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('aggregates by highest severity', () => {
|
|
34
|
+
const result = aggregateRules([
|
|
35
|
+
new Map([['no-console', ['warn'] as const]]),
|
|
36
|
+
new Map([['no-console', ['error'] as const], ['eqeqeq', ['error', 'always'] as const]])
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
expect(Object.fromEntries(result.entries())).toEqual({
|
|
40
|
+
eqeqeq: ['error', 'always'],
|
|
41
|
+
'no-console': ['error']
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('uses options from highest severity when severities differ', () => {
|
|
46
|
+
const result = aggregateRules([
|
|
47
|
+
new Map([['no-unused-vars', ['warn', { args: 'none' }] as const]]),
|
|
48
|
+
new Map([['no-unused-vars', ['error', { argsIgnorePattern: '^_' }] as const]])
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
expect(Object.fromEntries(result.entries())).toEqual({
|
|
52
|
+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }]
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('throws on conflicting options at same severity', () => {
|
|
57
|
+
expect(() =>
|
|
58
|
+
aggregateRules([
|
|
59
|
+
new Map([['no-restricted-imports', ['error', { paths: ['a'] }] as const]]),
|
|
60
|
+
new Map([['no-restricted-imports', ['error', { paths: ['b'] }] as const]])
|
|
61
|
+
])
|
|
62
|
+
).toThrow('Conflicting rule options for no-restricted-imports at severity error')
|
|
63
|
+
})
|
|
64
|
+
})
|
package/test/workspace.test.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
|
|
5
|
-
},
|
|
6
|
-
"include": [
|
|
7
|
-
"src/**/*.ts"
|
|
8
|
-
],
|
|
9
|
-
"references": [
|
|
10
|
-
|
|
11
|
-
]
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
|
|
5
|
+
},
|
|
6
|
+
"include": [
|
|
7
|
+
"src/**/*.ts"
|
|
8
|
+
],
|
|
9
|
+
"references": [
|
|
10
|
+
|
|
11
|
+
]
|
|
12
|
+
}
|