@kristijorgji/code-analysis 0.1.0
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/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/analyzers/test-mocks/analyze-test-mocks.d.ts +76 -0
- package/dist/analyzers/test-mocks/analyze-test-mocks.d.ts.map +1 -0
- package/dist/analyzers/test-mocks/analyze-test-mocks.js +273 -0
- package/dist/analyzers/test-mocks/analyze-test-mocks.js.map +1 -0
- package/dist/analyzers/test-mocks/format-report.d.ts +8 -0
- package/dist/analyzers/test-mocks/format-report.d.ts.map +1 -0
- package/dist/analyzers/test-mocks/format-report.js +62 -0
- package/dist/analyzers/test-mocks/format-report.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +92 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/test-mocks.d.ts +3 -0
- package/dist/commands/test-mocks.d.ts.map +1 -0
- package/dist/commands/test-mocks.js +36 -0
- package/dist/commands/test-mocks.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +45 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +67 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/detect-scan-paths.d.ts +9 -0
- package/dist/lib/detect-scan-paths.d.ts.map +1 -0
- package/dist/lib/detect-scan-paths.js +43 -0
- package/dist/lib/detect-scan-paths.js.map +1 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +10 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/tsconfig-path-aliases.d.ts +27 -0
- package/dist/lib/tsconfig-path-aliases.d.ts.map +1 -0
- package/dist/lib/tsconfig-path-aliases.js +126 -0
- package/dist/lib/tsconfig-path-aliases.js.map +1 -0
- package/dist/lib/walk-directory.d.ts +5 -0
- package/dist/lib/walk-directory.d.ts.map +1 -0
- package/dist/lib/walk-directory.js +20 -0
- package/dist/lib/walk-directory.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kristijorgji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @kristijorgji/code-analysis
|
|
2
|
+
|
|
3
|
+
Repository code-analysis CLI (`kj-analyze`) for TypeScript/JavaScript codebases — starting with test-mock duplication detection, with room to grow into more analyzers.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @kristijorgji/code-analysis
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -D @kristijorgji/code-analysis
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx kj-analyze test-mocks
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This scans your test files for `vi.mock(...)` / `jest.mock(...)` calls, groups occurrences of the same mocked module across files, and flags groups whose inline factories are identical or near-duplicate — good candidates for extracting into a shared mock helper. A markdown report is written to `reports/test-mock-usage/report.md` by default.
|
|
20
|
+
|
|
21
|
+
### Synopsis
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
kj-analyze <command> [options]
|
|
25
|
+
|
|
26
|
+
Commands:
|
|
27
|
+
test-mocks Find near-duplicate vi.mock/jest.mock factories
|
|
28
|
+
|
|
29
|
+
Options for test-mocks:
|
|
30
|
+
--root <path>
|
|
31
|
+
--scan <path> (repeatable)
|
|
32
|
+
--out <path>
|
|
33
|
+
--min-occurrences <n>
|
|
34
|
+
--min-lines <n>
|
|
35
|
+
--similarity <0-1>
|
|
36
|
+
--ignore <dirname> (repeatable, appends to defaults)
|
|
37
|
+
--help
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Flags
|
|
41
|
+
|
|
42
|
+
| Flag | Description | Default |
|
|
43
|
+
| ---- | ----------- | ------- |
|
|
44
|
+
| `--root <path>` | Repository root to analyze. | `process.cwd()` |
|
|
45
|
+
| `--scan <path>` | A path (relative to `--root`) to scan for test files. Repeatable. | Auto-detected (see below), else `src` |
|
|
46
|
+
| `--out <path>` | Where to write the markdown report (relative to `--root`). | `reports/test-mock-usage/report.md` |
|
|
47
|
+
| `--min-occurrences <n>` | Minimum number of non-delegating occurrences of a mocked module required to report it. | `2` |
|
|
48
|
+
| `--min-lines <n>` | Minimum number of lines a `mock(...)` call must span to be considered. | `8` |
|
|
49
|
+
| `--similarity <0-1>` | Jaccard similarity threshold above which two factories are considered near-duplicate. | `0.8` |
|
|
50
|
+
| `--ignore <dirname>` | A directory name to skip while walking. Repeatable; appends to the defaults. | `node_modules`, `dist`, `coverage` |
|
|
51
|
+
| `--help` | Print usage and exit. | |
|
|
52
|
+
|
|
53
|
+
When `--scan` is omitted and no config file specifies `scanPaths`, `kj-analyze` looks for a `pnpm-workspace.yaml` at the repo root. If it declares workspace packages, it scans for existing `apps/*/src` and `packages/*/src` directories. Otherwise it falls back to `src` if present, or scans nothing.
|
|
54
|
+
|
|
55
|
+
### Environment variables
|
|
56
|
+
|
|
57
|
+
Flags win over environment variables, which win over the config file, which wins over built-in defaults:
|
|
58
|
+
|
|
59
|
+
| Variable | Maps to |
|
|
60
|
+
| -------- | ------- |
|
|
61
|
+
| `MIN_OCCURRENCES` | `--min-occurrences` |
|
|
62
|
+
| `MIN_LINES` | `--min-lines` |
|
|
63
|
+
| `SIMILARITY_THRESHOLD` | `--similarity` |
|
|
64
|
+
|
|
65
|
+
## Config file
|
|
66
|
+
|
|
67
|
+
Drop a `code-analysis.config.json` at your repo root to set defaults without passing flags every time:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"scanPaths": ["src"],
|
|
72
|
+
"minOccurrences": 2,
|
|
73
|
+
"minLines": 8,
|
|
74
|
+
"similarityThreshold": 0.8,
|
|
75
|
+
"out": "reports/test-mock-usage/report.md",
|
|
76
|
+
"ignoreDirectories": ["node_modules", "dist", "coverage", "e2e"],
|
|
77
|
+
"pathAliases": {
|
|
78
|
+
"~/": "src/"
|
|
79
|
+
},
|
|
80
|
+
"delegatePatterns": [
|
|
81
|
+
"\\bcreate[A-Z]\\w*Mock\\w*\\s*\\(",
|
|
82
|
+
"\\buseSharedMock\\("
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| Key | Type | Description |
|
|
88
|
+
| --- | ---- | ----------- |
|
|
89
|
+
| `root` | `string` | Repository root override. |
|
|
90
|
+
| `scanPaths` | `string[]` | Paths (relative to root) to scan for `*.test.ts(x)` / `*.spec.ts(x)` files. |
|
|
91
|
+
| `minOccurrences` | `number` | Minimum non-delegating occurrences to report a group. |
|
|
92
|
+
| `minLines` | `number` | Minimum lines per `mock(...)` call to be considered. |
|
|
93
|
+
| `similarityThreshold` | `number` | Jaccard similarity threshold for "near-duplicate". |
|
|
94
|
+
| `out` | `string` | Report output path, relative to root. |
|
|
95
|
+
| `ignoreDirectories` | `string[]` | Directory names to skip while walking (replaces the built-in defaults; use `--ignore` to append instead). |
|
|
96
|
+
| `pathAliases` | `Record<string, string>` | Extra `prefix -> target` path aliases, used as a fallback when a scan root has no tsconfig `paths`. |
|
|
97
|
+
| `delegatePatterns` | `string[]` | Extra regex source strings identifying factories that delegate to a shared mock helper. |
|
|
98
|
+
|
|
99
|
+
**Precedence** (highest to lowest): **CLI flags > environment variables > config file > built-in defaults**.
|
|
100
|
+
|
|
101
|
+
## Programmatic API
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { analyzeTestMocks, formatReport } from '@kristijorgji/code-analysis';
|
|
105
|
+
|
|
106
|
+
const result = analyzeTestMocks({
|
|
107
|
+
repoRoot: process.cwd(),
|
|
108
|
+
scanPaths: ['src'],
|
|
109
|
+
minOccurrences: 2,
|
|
110
|
+
minLines: 8,
|
|
111
|
+
similarityThreshold: 0.8,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const report = formatReport(result, {
|
|
115
|
+
repoRoot: process.cwd(),
|
|
116
|
+
minOccurrences: 2,
|
|
117
|
+
minLines: 8,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
console.log(report);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Other exports include `resolveMockModuleKey`, `factoryDelegatesToHelper`, `factoryJaccardSimilarity`, `hashFactoryBody`, `tokenizeFactory`, `jaccardSimilarity`, `listTestFiles`, `detectScanPaths`, `loadConfig`/`loadConfigFile`, `resolveConfig`/`resolveTestMocksConfig`, and the underlying path-alias and directory-walking helpers — see `src/index.ts` for the full surface.
|
|
124
|
+
|
|
125
|
+
## Example report (trimmed)
|
|
126
|
+
|
|
127
|
+
```markdown
|
|
128
|
+
# Test mock usage report
|
|
129
|
+
|
|
130
|
+
Scanned **42** test files.
|
|
131
|
+
Thresholds: >= **2** non-delegating occurrences, >= **8** lines per mock, near-duplicate >= **80%** similarity.
|
|
132
|
+
|
|
133
|
+
## expo-notifications
|
|
134
|
+
|
|
135
|
+
- Kind: package
|
|
136
|
+
- Status: **near-duplicate (max 92%)**
|
|
137
|
+
- Occurrences: 3 (3 non-delegating)
|
|
138
|
+
- Max lines: 6
|
|
139
|
+
- Closest pair (92%): `src/screens/a/A.test.ts:4` ↔ `src/screens/b/B.test.ts:4`
|
|
140
|
+
|
|
141
|
+
| File | Line | Lines | Delegates | Factory hash |
|
|
142
|
+
| ---- | ---- | ----- | --------- | ------------ |
|
|
143
|
+
| `src/screens/a/A.test.ts` | 4 | 6 | no | 3f9a1c2b9d0e |
|
|
144
|
+
| `src/screens/b/B.test.ts` | 4 | 6 | no | 7b2e0a44f1aa |
|
|
145
|
+
| `src/screens/c/C.test.ts` | 9 | 6 | no | 7b2e0a44f1aa |
|
|
146
|
+
|
|
147
|
+
## Already using shared mock helpers
|
|
148
|
+
|
|
149
|
+
These module groups have fewer than the required non-delegating inline mocks.
|
|
150
|
+
|
|
151
|
+
### react-i18next
|
|
152
|
+
|
|
153
|
+
- Kind: package
|
|
154
|
+
- Total occurrences: 5
|
|
155
|
+
- Delegating to shared helper: 5
|
|
156
|
+
|
|
157
|
+
| File | Line | Lines | Delegates |
|
|
158
|
+
| ---- | ---- | ----- | --------- |
|
|
159
|
+
| `src/hooks/useFoo.test.ts` | 3 | 1 | yes |
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT © kristijorgji
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DEFAULT_IGNORE_DIRECTORIES } from '../../lib/walk-directory.js';
|
|
2
|
+
export declare const DEFAULT_SCAN_PATHS: readonly ["src"];
|
|
3
|
+
export declare const DEFAULT_SIMILARITY_THRESHOLD = 0.8;
|
|
4
|
+
export { DEFAULT_IGNORE_DIRECTORIES };
|
|
5
|
+
/** Union of the delegate-detection patterns used by prior host-repo scripts. */
|
|
6
|
+
export declare const DEFAULT_DELEGATE_PATTERNS: RegExp[];
|
|
7
|
+
export type MockGroupStatus = 'identical' | 'near-duplicate' | 'divergent';
|
|
8
|
+
export interface AnalyzeTestMocksOptions {
|
|
9
|
+
repoRoot: string;
|
|
10
|
+
scanPaths?: readonly string[];
|
|
11
|
+
minOccurrences?: number;
|
|
12
|
+
minLines?: number;
|
|
13
|
+
similarityThreshold?: number;
|
|
14
|
+
/** Default: union of both source repos' patterns, see {@link DEFAULT_DELEGATE_PATTERNS}. */
|
|
15
|
+
delegatePatterns?: RegExp[];
|
|
16
|
+
/** Directory names to skip while walking. Default: node_modules, dist, coverage. */
|
|
17
|
+
ignoreDirectories?: string[];
|
|
18
|
+
/** Extra path aliases (prefix -> target relative to a scan root). */
|
|
19
|
+
pathAliases?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface MockOccurrence {
|
|
22
|
+
filePath: string;
|
|
23
|
+
line: number;
|
|
24
|
+
lineCount: number;
|
|
25
|
+
factoryHash: string | null;
|
|
26
|
+
rawSpecifier: string;
|
|
27
|
+
delegatesToHelper: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface SimilarPairRef {
|
|
30
|
+
filePath: string;
|
|
31
|
+
line: number;
|
|
32
|
+
}
|
|
33
|
+
export interface TopSimilarPair {
|
|
34
|
+
left: SimilarPairRef;
|
|
35
|
+
right: SimilarPairRef;
|
|
36
|
+
score: number;
|
|
37
|
+
}
|
|
38
|
+
export interface MockModuleGroup {
|
|
39
|
+
groupKey: string;
|
|
40
|
+
specifierKind: 'package' | 'resolved-path';
|
|
41
|
+
occurrences: MockOccurrence[];
|
|
42
|
+
nonDelegatingOccurrences: MockOccurrence[];
|
|
43
|
+
identical: boolean;
|
|
44
|
+
status: MockGroupStatus;
|
|
45
|
+
maxLineCount: number;
|
|
46
|
+
topSimilarPair?: TopSimilarPair;
|
|
47
|
+
}
|
|
48
|
+
export interface AlreadyUsingHelperGroup {
|
|
49
|
+
groupKey: string;
|
|
50
|
+
specifierKind: 'package' | 'resolved-path';
|
|
51
|
+
delegatingOccurrences: MockOccurrence[];
|
|
52
|
+
allOccurrences: MockOccurrence[];
|
|
53
|
+
}
|
|
54
|
+
export interface AnalyzeTestMocksResult {
|
|
55
|
+
groups: MockModuleGroup[];
|
|
56
|
+
alreadyUsingHelpers: AlreadyUsingHelperGroup[];
|
|
57
|
+
scannedFiles: number;
|
|
58
|
+
}
|
|
59
|
+
export interface ResolveMockModuleKeyOptions {
|
|
60
|
+
scanPaths?: readonly string[];
|
|
61
|
+
pathAliases?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
export declare function factoryDelegatesToHelper(factoryText: string | null, patterns?: readonly RegExp[]): boolean;
|
|
64
|
+
export declare function tokenizeFactory(text: string): Set<string>;
|
|
65
|
+
export declare function jaccardSimilarity(left: Set<string>, right: Set<string>): number;
|
|
66
|
+
export declare function factoryJaccardSimilarity(leftFactory: string, rightFactory: string): number;
|
|
67
|
+
export declare function hashFactoryBody(factoryText: string | null): string | null;
|
|
68
|
+
export declare function resolveMockModuleKey(rawSpecifier: string, sourceFilePath: string, repoRoot: string, options?: ResolveMockModuleKeyOptions): {
|
|
69
|
+
groupKey: string;
|
|
70
|
+
specifierKind: 'package' | 'resolved-path';
|
|
71
|
+
};
|
|
72
|
+
export declare function listTestFiles(repoRoot: string, scanPaths: readonly string[], options?: {
|
|
73
|
+
ignoreDirectories?: string[];
|
|
74
|
+
}): string[];
|
|
75
|
+
export declare function analyzeTestMocks(options: AnalyzeTestMocksOptions): AnalyzeTestMocksResult;
|
|
76
|
+
//# sourceMappingURL=analyze-test-mocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze-test-mocks.d.ts","sourceRoot":"","sources":["../../../src/analyzers/test-mocks/analyze-test-mocks.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,0BAA0B,EAAiB,MAAM,6BAA6B,CAAC;AAExF,eAAO,MAAM,kBAAkB,kBAAmB,CAAC;AACnD,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC,gFAAgF;AAChF,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAG7C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,WAAW,CAAC;AAE3E,MAAM,WAAW,uBAAuB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,4FAA4F;IAC5F,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,oFAAoF;IACpF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAA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C,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1F;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAWzE;AAQD,wBAAgB,oBAAoB,CAChC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,2BAAgC,GAC1C;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,SAAS,GAAG,eAAe,CAAA;CAAE,CA4BlE;AAyLD,wBAAgB,aAAa,CACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC3C,MAAM,EAAE,CAsBV;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,sBAAsB,CAiDzF"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { Project, SyntaxKind } from 'ts-morph';
|
|
5
|
+
import { deriveScanRootsFromScanPaths, findScanRoot, getPathAliases, resolvePathAlias, } from '../../lib/tsconfig-path-aliases.js';
|
|
6
|
+
import { DEFAULT_IGNORE_DIRECTORIES, walkDirectory } from '../../lib/walk-directory.js';
|
|
7
|
+
export const DEFAULT_SCAN_PATHS = ['src'];
|
|
8
|
+
export const DEFAULT_SIMILARITY_THRESHOLD = 0.8;
|
|
9
|
+
export { DEFAULT_IGNORE_DIRECTORIES };
|
|
10
|
+
/** Union of the delegate-detection patterns used by prior host-repo scripts. */
|
|
11
|
+
export const DEFAULT_DELEGATE_PATTERNS = [
|
|
12
|
+
/\bcreate[A-Z]\w*Mock\w*\s*\(/,
|
|
13
|
+
/(?:await\s+)?import\(\s*['"][^'"]*(?:\/mocks\/|\/testing|__tests__|@test\/)[^'"]*['"]/,
|
|
14
|
+
];
|
|
15
|
+
function unquoteStringLiteral(text) {
|
|
16
|
+
const trimmed = text.trim();
|
|
17
|
+
if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
|
|
18
|
+
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
19
|
+
(trimmed.startsWith('`') && trimmed.endsWith('`'))) {
|
|
20
|
+
return trimmed.slice(1, -1);
|
|
21
|
+
}
|
|
22
|
+
return trimmed;
|
|
23
|
+
}
|
|
24
|
+
function normalizeFactoryBody(text) {
|
|
25
|
+
return text
|
|
26
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
27
|
+
.replace(/(^|\s)\/\/.*$/gm, '')
|
|
28
|
+
.replace(/,\s*([}\]])/g, '$1')
|
|
29
|
+
.replace(/\)([}\]])/g, ') $1')
|
|
30
|
+
.replace(/\s+/g, ' ')
|
|
31
|
+
.trim();
|
|
32
|
+
}
|
|
33
|
+
export function factoryDelegatesToHelper(factoryText, patterns = DEFAULT_DELEGATE_PATTERNS) {
|
|
34
|
+
if (factoryText === null) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return patterns.some((pattern) => pattern.test(factoryText));
|
|
38
|
+
}
|
|
39
|
+
export function tokenizeFactory(text) {
|
|
40
|
+
return new Set(normalizeFactoryBody(text).match(/[A-Za-z_$][\w$]*|[^\s]/g) ?? []);
|
|
41
|
+
}
|
|
42
|
+
export function jaccardSimilarity(left, right) {
|
|
43
|
+
if (left.size === 0 && right.size === 0) {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
if (left.size === 0 || right.size === 0) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
let intersection = 0;
|
|
50
|
+
for (const token of left) {
|
|
51
|
+
if (right.has(token)) {
|
|
52
|
+
intersection += 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return intersection / (left.size + right.size - intersection);
|
|
56
|
+
}
|
|
57
|
+
export function factoryJaccardSimilarity(leftFactory, rightFactory) {
|
|
58
|
+
return jaccardSimilarity(tokenizeFactory(leftFactory), tokenizeFactory(rightFactory));
|
|
59
|
+
}
|
|
60
|
+
export function hashFactoryBody(factoryText) {
|
|
61
|
+
if (factoryText === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const normalized = normalizeFactoryBody(factoryText);
|
|
65
|
+
if (normalized.length === 0) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return createHash('sha256').update(normalized).digest('hex').slice(0, 12);
|
|
69
|
+
}
|
|
70
|
+
function resolveRelativeSpecifier(specifier, sourceFilePath, repoRoot) {
|
|
71
|
+
const sourceDir = path.dirname(sourceFilePath);
|
|
72
|
+
const resolved = path.resolve(sourceDir, specifier);
|
|
73
|
+
return path.relative(repoRoot, resolved).replace(/\\/g, '/');
|
|
74
|
+
}
|
|
75
|
+
export function resolveMockModuleKey(rawSpecifier, sourceFilePath, repoRoot, options = {}) {
|
|
76
|
+
const specifier = unquoteStringLiteral(rawSpecifier);
|
|
77
|
+
if (specifier.startsWith('.')) {
|
|
78
|
+
return {
|
|
79
|
+
groupKey: resolveRelativeSpecifier(specifier, sourceFilePath, repoRoot),
|
|
80
|
+
specifierKind: 'resolved-path',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (specifier.startsWith('@repo/')) {
|
|
84
|
+
return { groupKey: specifier, specifierKind: 'package' };
|
|
85
|
+
}
|
|
86
|
+
const scanPaths = options.scanPaths ?? DEFAULT_SCAN_PATHS;
|
|
87
|
+
const repoRelativeSource = path.relative(repoRoot, sourceFilePath).replace(/\\/g, '/');
|
|
88
|
+
const roots = deriveScanRootsFromScanPaths(scanPaths);
|
|
89
|
+
const scanRoot = findScanRoot(repoRelativeSource, roots);
|
|
90
|
+
if (scanRoot !== null) {
|
|
91
|
+
const pathAliasesByRoot = getPathAliases(repoRoot, scanPaths, options.pathAliases);
|
|
92
|
+
const resolved = resolvePathAlias(specifier, scanRoot, pathAliasesByRoot);
|
|
93
|
+
if (resolved) {
|
|
94
|
+
return { groupKey: resolved, specifierKind: 'resolved-path' };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { groupKey: specifier, specifierKind: 'package' };
|
|
98
|
+
}
|
|
99
|
+
function isMockCall(expressionText) {
|
|
100
|
+
return expressionText === 'vi.mock' || expressionText === 'jest.mock';
|
|
101
|
+
}
|
|
102
|
+
function collectMockOccurrences(sourceFile, delegatePatterns) {
|
|
103
|
+
const occurrences = [];
|
|
104
|
+
const filePath = sourceFile.getFilePath();
|
|
105
|
+
for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
106
|
+
const expressionText = call.getExpression().getText();
|
|
107
|
+
if (!isMockCall(expressionText)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const args = call.getArguments();
|
|
111
|
+
if (args.length === 0) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const rawSpecifier = args[0]?.getText() ?? '';
|
|
115
|
+
const factoryArg = args[1];
|
|
116
|
+
const factoryText = factoryArg ? factoryArg.getText() : null;
|
|
117
|
+
const fullMockText = call.getText();
|
|
118
|
+
const lineCount = fullMockText.split('\n').length;
|
|
119
|
+
occurrences.push({
|
|
120
|
+
filePath,
|
|
121
|
+
line: call.getStartLineNumber(),
|
|
122
|
+
lineCount,
|
|
123
|
+
factoryHash: hashFactoryBody(factoryText),
|
|
124
|
+
rawSpecifier,
|
|
125
|
+
delegatesToHelper: factoryDelegatesToHelper(factoryText, delegatePatterns),
|
|
126
|
+
factoryText,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return occurrences;
|
|
130
|
+
}
|
|
131
|
+
function computeGroupStatusFromFactories(occurrences, similarityThreshold) {
|
|
132
|
+
if (occurrences.length < 2) {
|
|
133
|
+
return { status: 'divergent', identical: false };
|
|
134
|
+
}
|
|
135
|
+
const stripped = occurrences.map(({ factoryText: _factoryText, ...occurrence }) => occurrence);
|
|
136
|
+
const hashes = new Set(stripped.map((occurrence) => occurrence.factoryHash ?? '__none__'));
|
|
137
|
+
if (hashes.size === 1) {
|
|
138
|
+
return { status: 'identical', identical: true };
|
|
139
|
+
}
|
|
140
|
+
let topScore = 0;
|
|
141
|
+
let topSimilarPair;
|
|
142
|
+
for (let leftIndex = 0; leftIndex < occurrences.length; leftIndex += 1) {
|
|
143
|
+
for (let rightIndex = leftIndex + 1; rightIndex < occurrences.length; rightIndex += 1) {
|
|
144
|
+
const left = occurrences[leftIndex];
|
|
145
|
+
const right = occurrences[rightIndex];
|
|
146
|
+
if (!left || !right || !left.factoryText || !right.factoryText) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const score = factoryJaccardSimilarity(left.factoryText, right.factoryText);
|
|
150
|
+
if (score > topScore) {
|
|
151
|
+
topScore = score;
|
|
152
|
+
topSimilarPair = {
|
|
153
|
+
left: { filePath: left.filePath, line: left.line },
|
|
154
|
+
right: { filePath: right.filePath, line: right.line },
|
|
155
|
+
score,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const status = topScore >= similarityThreshold ? 'near-duplicate' : 'divergent';
|
|
161
|
+
return { status, identical: false, topSimilarPair };
|
|
162
|
+
}
|
|
163
|
+
function groupOccurrences(allOccurrences, minOccurrences, minLines, similarityThreshold) {
|
|
164
|
+
const byKey = new Map();
|
|
165
|
+
for (const occurrence of allOccurrences) {
|
|
166
|
+
if (occurrence.lineCount < minLines) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const existing = byKey.get(occurrence.groupKey);
|
|
170
|
+
if (!existing) {
|
|
171
|
+
byKey.set(occurrence.groupKey, {
|
|
172
|
+
groupKey: occurrence.groupKey,
|
|
173
|
+
specifierKind: occurrence.specifierKind,
|
|
174
|
+
occurrences: [occurrence],
|
|
175
|
+
maxLineCount: occurrence.lineCount,
|
|
176
|
+
});
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
existing.occurrences.push(occurrence);
|
|
180
|
+
existing.maxLineCount = Math.max(existing.maxLineCount, occurrence.lineCount);
|
|
181
|
+
}
|
|
182
|
+
const groups = [];
|
|
183
|
+
const alreadyUsingHelpers = [];
|
|
184
|
+
for (const rawGroup of byKey.values()) {
|
|
185
|
+
if (rawGroup.occurrences.length < minOccurrences) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const occurrences = rawGroup.occurrences.map(({ factoryText: _factoryText, ...occurrence }) => occurrence);
|
|
189
|
+
const nonDelegatingOccurrences = occurrences.filter((occurrence) => !occurrence.delegatesToHelper);
|
|
190
|
+
const delegatingOccurrences = occurrences.filter((occurrence) => occurrence.delegatesToHelper);
|
|
191
|
+
if (nonDelegatingOccurrences.length < minOccurrences) {
|
|
192
|
+
alreadyUsingHelpers.push({
|
|
193
|
+
groupKey: rawGroup.groupKey,
|
|
194
|
+
specifierKind: rawGroup.specifierKind,
|
|
195
|
+
delegatingOccurrences,
|
|
196
|
+
allOccurrences: occurrences,
|
|
197
|
+
});
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const nonDelegatingWithFactory = rawGroup.occurrences.filter((occurrence) => !occurrence.delegatesToHelper);
|
|
201
|
+
const { status, identical, topSimilarPair } = computeGroupStatusFromFactories(nonDelegatingWithFactory, similarityThreshold);
|
|
202
|
+
groups.push({
|
|
203
|
+
groupKey: rawGroup.groupKey,
|
|
204
|
+
specifierKind: rawGroup.specifierKind,
|
|
205
|
+
occurrences,
|
|
206
|
+
nonDelegatingOccurrences,
|
|
207
|
+
identical,
|
|
208
|
+
status,
|
|
209
|
+
maxLineCount: rawGroup.maxLineCount,
|
|
210
|
+
topSimilarPair,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const sortGroups = (left, right) => {
|
|
214
|
+
const leftCount = left.allOccurrences?.length ?? left.occurrences?.length ?? 0;
|
|
215
|
+
const rightCount = right.allOccurrences?.length ?? right.occurrences?.length ?? 0;
|
|
216
|
+
if (rightCount !== leftCount) {
|
|
217
|
+
return rightCount - leftCount;
|
|
218
|
+
}
|
|
219
|
+
return left.groupKey.localeCompare(right.groupKey);
|
|
220
|
+
};
|
|
221
|
+
return {
|
|
222
|
+
groups: groups.sort(sortGroups),
|
|
223
|
+
alreadyUsingHelpers: alreadyUsingHelpers.sort(sortGroups),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
export function listTestFiles(repoRoot, scanPaths, options) {
|
|
227
|
+
const files = [];
|
|
228
|
+
const ignoreDirectories = options?.ignoreDirectories ?? DEFAULT_IGNORE_DIRECTORIES;
|
|
229
|
+
for (const scanPath of scanPaths) {
|
|
230
|
+
const absoluteScanPath = path.join(repoRoot, scanPath);
|
|
231
|
+
if (!fs.existsSync(absoluteScanPath)) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
walkDirectory(absoluteScanPath, (filePath) => {
|
|
235
|
+
if (/\.(test|spec)\.(ts|tsx)$/.test(filePath)) {
|
|
236
|
+
files.push(filePath);
|
|
237
|
+
}
|
|
238
|
+
}, { ignoreDirectories });
|
|
239
|
+
}
|
|
240
|
+
return files;
|
|
241
|
+
}
|
|
242
|
+
export function analyzeTestMocks(options) {
|
|
243
|
+
const scanPaths = options.scanPaths ?? DEFAULT_SCAN_PATHS;
|
|
244
|
+
const minOccurrences = options.minOccurrences ?? 2;
|
|
245
|
+
const minLines = options.minLines ?? 8;
|
|
246
|
+
const similarityThreshold = options.similarityThreshold ?? DEFAULT_SIMILARITY_THRESHOLD;
|
|
247
|
+
const delegatePatterns = options.delegatePatterns ?? DEFAULT_DELEGATE_PATTERNS;
|
|
248
|
+
const ignoreDirectories = options.ignoreDirectories ?? DEFAULT_IGNORE_DIRECTORIES;
|
|
249
|
+
const testFiles = listTestFiles(options.repoRoot, scanPaths, { ignoreDirectories });
|
|
250
|
+
const project = new Project({
|
|
251
|
+
skipAddingFilesFromTsConfig: true,
|
|
252
|
+
compilerOptions: {
|
|
253
|
+
allowJs: true,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
// Prefer per-path add: `addSourceFilesAtPaths` treats `[brackets]` in absolute
|
|
257
|
+
// paths as glob character classes (ts-morph ≤25), dropping Next.js `[locale]` tests.
|
|
258
|
+
const sourceFiles = testFiles.map((filePath) => project.addSourceFileAtPath(filePath));
|
|
259
|
+
const taggedOccurrences = [];
|
|
260
|
+
for (const sourceFile of sourceFiles) {
|
|
261
|
+
for (const occurrence of collectMockOccurrences(sourceFile, delegatePatterns)) {
|
|
262
|
+
const { groupKey, specifierKind } = resolveMockModuleKey(occurrence.rawSpecifier, occurrence.filePath, options.repoRoot, { scanPaths, pathAliases: options.pathAliases });
|
|
263
|
+
taggedOccurrences.push({ ...occurrence, groupKey, specifierKind });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const { groups, alreadyUsingHelpers } = groupOccurrences(taggedOccurrences, minOccurrences, minLines, similarityThreshold);
|
|
267
|
+
return {
|
|
268
|
+
groups,
|
|
269
|
+
alreadyUsingHelpers,
|
|
270
|
+
scannedFiles: sourceFiles.length,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=analyze-test-mocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze-test-mocks.js","sourceRoot":"","sources":["../../../src/analyzers/test-mocks/analyze-test-mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAmB,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhE,OAAO,EACH,4BAA4B,EAC5B,YAAY,EACZ,cAAc,EACd,gBAAgB,GACnB,MAAM,oCAAoC,CAAC;AAC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AAC;AACN,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type AnalyzeTestMocksResult } from './analyze-test-mocks.js';
|
|
2
|
+
export declare function formatReport(result: AnalyzeTestMocksResult, options: {
|
|
3
|
+
repoRoot: string;
|
|
4
|
+
minOccurrences: number;
|
|
5
|
+
minLines: number;
|
|
6
|
+
similarityThreshold?: number;
|
|
7
|
+
}): string;
|
|
8
|
+
//# sourceMappingURL=format-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-report.d.ts","sourceRoot":"","sources":["../../../src/analyzers/test-mocks/format-report.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,KAAK,sBAAsB,EAG9B,MAAM,yBAAyB,CAAC;AAkBjC,wBAAgB,YAAY,CACxB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAE,GACtG,MAAM,CA2ER"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { DEFAULT_SIMILARITY_THRESHOLD, } from './analyze-test-mocks.js';
|
|
3
|
+
function formatStatusLabel(group) {
|
|
4
|
+
if (group.status === 'near-duplicate' && group.topSimilarPair) {
|
|
5
|
+
const percent = Math.round(group.topSimilarPair.score * 100);
|
|
6
|
+
return `near-duplicate (max ${percent}%)`;
|
|
7
|
+
}
|
|
8
|
+
return group.status;
|
|
9
|
+
}
|
|
10
|
+
function formatSimilarPair(repoRoot, pair) {
|
|
11
|
+
const left = path.relative(repoRoot, pair.left.filePath);
|
|
12
|
+
const right = path.relative(repoRoot, pair.right.filePath);
|
|
13
|
+
const percent = Math.round(pair.score * 100);
|
|
14
|
+
return `- Closest pair (${percent}%): \`${left}:${pair.left.line}\` ↔ \`${right}:${pair.right.line}\``;
|
|
15
|
+
}
|
|
16
|
+
export function formatReport(result, options) {
|
|
17
|
+
const similarityThreshold = options.similarityThreshold ?? DEFAULT_SIMILARITY_THRESHOLD;
|
|
18
|
+
const lines = [
|
|
19
|
+
'# Test mock usage report',
|
|
20
|
+
'',
|
|
21
|
+
`Scanned **${result.scannedFiles}** test files.`,
|
|
22
|
+
`Thresholds: >= **${options.minOccurrences}** non-delegating occurrences, >= **${options.minLines}** lines per mock, near-duplicate >= **${Math.round(similarityThreshold * 100)}%** similarity.`,
|
|
23
|
+
'',
|
|
24
|
+
];
|
|
25
|
+
if (result.groups.length === 0) {
|
|
26
|
+
lines.push('No extraction candidates matched the thresholds.');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
for (const group of result.groups) {
|
|
30
|
+
lines.push(`## ${group.groupKey}`, '', `- Kind: ${group.specifierKind}`, `- Status: **${formatStatusLabel(group)}**`, `- Occurrences: ${group.occurrences.length} (${group.nonDelegatingOccurrences.length} non-delegating)`, `- Max lines: ${group.maxLineCount}`);
|
|
31
|
+
if (group.topSimilarPair && group.status !== 'identical') {
|
|
32
|
+
lines.push(formatSimilarPair(options.repoRoot, group.topSimilarPair));
|
|
33
|
+
}
|
|
34
|
+
lines.push('', '| File | Line | Lines | Delegates | Factory hash |', '| ---- | ---- | ----- | --------- | ------------ |');
|
|
35
|
+
for (const occurrence of group.occurrences) {
|
|
36
|
+
const relativePath = path.relative(options.repoRoot, occurrence.filePath);
|
|
37
|
+
const delegates = occurrence.delegatesToHelper ? 'yes' : 'no';
|
|
38
|
+
lines.push(`| \`${relativePath}\` | ${occurrence.line} | ${occurrence.lineCount} | ${delegates} | ${occurrence.factoryHash ?? '—'} |`);
|
|
39
|
+
}
|
|
40
|
+
lines.push('');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (result.alreadyUsingHelpers.length > 0) {
|
|
44
|
+
lines.push('## Already using shared mock helpers', '');
|
|
45
|
+
lines.push('These module groups have fewer than the required non-delegating inline mocks.', '');
|
|
46
|
+
for (const group of result.alreadyUsingHelpers) {
|
|
47
|
+
lines.push(`### ${group.groupKey}`, '');
|
|
48
|
+
lines.push(`- Kind: ${group.specifierKind}`, `- Total occurrences: ${group.allOccurrences.length}`, `- Delegating to shared helper: ${group.delegatingOccurrences.length}`, '', '| File | Line | Lines | Delegates |', '| ---- | ---- | ----- | --------- |');
|
|
49
|
+
for (const occurrence of group.allOccurrences) {
|
|
50
|
+
const relativePath = path.relative(options.repoRoot, occurrence.filePath);
|
|
51
|
+
const delegates = occurrence.delegatesToHelper ? 'yes' : 'no';
|
|
52
|
+
lines.push(`| \`${relativePath}\` | ${occurrence.line} | ${occurrence.lineCount} | ${delegates} |`);
|
|
53
|
+
}
|
|
54
|
+
lines.push('');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (result.groups.length === 0 && result.alreadyUsingHelpers.length === 0) {
|
|
58
|
+
lines.push('No duplicate multi-line mocks matched the thresholds.');
|
|
59
|
+
}
|
|
60
|
+
return `${lines.join('\n')}\n`;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=format-report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-report.js","sourceRoot":"","sources":["../../../src/analyzers/test-mocks/format-report.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACH,4BAA4B,GAI/B,MAAM,yBAAyB,CAAC;AAEjC,SAAS,iBAAiB,CAAC,KAAsB;IAC7C,IAAI,KAAK,CAAC,MAAM,KAAK,gBAAgB,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;QAC7D,OAAO,uBAAuB,OAAO,IAAI,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,CAAC;AACxB,CAAC;AAED,SA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CAAC;YACxC,KAAK,CAAC,IAAI,CACN,WAAW,KAAK,CAAC,aAAa,EAAE,EAChC,wBAAwB,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,EACrD,kCAAkC,KAAK,CAAC,qBAAqB,CAAC,MAAM,EAAE,EACtE,EAAE,EACF,qCAAqC,EACrC,qCAAqC,CACxC,CAAC;YAEF,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;gBAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAC1E,MAAM,SAAS,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC9D,KAAK,CAAC,IAAI,CAAC,OAAO,YAAY,QAAQ,UAAU,CAAC,IAAI,MAAM,UAAU,CAAC,SAAS,MAAM,SAAS,IAAI,CAAC,CAAC;YACxG,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;IACL,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,KAAK,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACnC,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
interface ParsedArgs {
|
|
3
|
+
command?: string;
|
|
4
|
+
root?: string;
|
|
5
|
+
scan: string[];
|
|
6
|
+
out?: string;
|
|
7
|
+
minOccurrences?: number;
|
|
8
|
+
minLines?: number;
|
|
9
|
+
similarity?: number;
|
|
10
|
+
ignore: string[];
|
|
11
|
+
help: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=cli.d.ts.map
|