pi-lens 2.0.7 → 2.0.8
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/clients/ast-grep-client.test.ts +146 -116
- package/clients/ast-grep-client.ts +645 -551
- package/clients/biome-client.test.ts +154 -137
- package/clients/biome-client.ts +397 -337
- package/clients/complexity-client.test.ts +188 -200
- package/clients/complexity-client.ts +815 -667
- package/clients/dependency-checker.test.ts +55 -55
- package/clients/dependency-checker.ts +358 -333
- package/clients/go-client.test.ts +121 -111
- package/clients/go-client.ts +218 -216
- package/clients/jscpd-client.test.ts +132 -132
- package/clients/jscpd-client.ts +155 -118
- package/clients/knip-client.test.ts +123 -133
- package/clients/knip-client.ts +231 -218
- package/clients/metrics-client.test.ts +171 -167
- package/clients/metrics-client.ts +283 -252
- package/clients/ruff-client.test.ts +128 -117
- package/clients/ruff-client.ts +300 -269
- package/clients/rust-client.test.ts +104 -85
- package/clients/rust-client.ts +241 -234
- package/clients/subprocess-client.ts +1 -1
- package/clients/test-runner-client.test.ts +248 -215
- package/clients/test-runner-client.ts +728 -608
- package/clients/test-utils.ts +10 -3
- package/clients/todo-scanner.test.ts +288 -202
- package/clients/todo-scanner.ts +225 -187
- package/clients/type-coverage-client.test.ts +119 -119
- package/clients/type-coverage-client.ts +142 -115
- package/clients/types.ts +28 -28
- package/clients/typescript-client.test.ts +99 -93
- package/clients/typescript-client.ts +527 -502
- package/index.ts +662 -212
- package/package.json +1 -1
- package/tsconfig.json +12 -12
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TypeCoverageClient } from "./type-coverage-client.js";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
2
|
import { setupTestEnvironment } from "./test-utils.js";
|
|
3
|
+
import { TypeCoverageClient } from "./type-coverage-client.js";
|
|
4
4
|
|
|
5
5
|
describe("TypeCoverageClient", () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
6
|
+
let client: TypeCoverageClient;
|
|
7
|
+
let _tmpDir: string;
|
|
8
|
+
let cleanup: () => void;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
client = new TypeCoverageClient();
|
|
12
|
+
({ tmpDir: _tmpDir, cleanup } = setupTestEnvironment("pi-lens-typecoverage-test-"));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
cleanup();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("isAvailable", () => {
|
|
24
|
+
it("should check type-coverage availability", () => {
|
|
25
|
+
const available = client.isAvailable();
|
|
26
|
+
expect(typeof available).toBe("boolean");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("formatResult", () => {
|
|
31
|
+
it("should return empty string when not successful", () => {
|
|
32
|
+
const result = {
|
|
33
|
+
success: false,
|
|
34
|
+
percentage: 0,
|
|
35
|
+
typed: 0,
|
|
36
|
+
total: 0,
|
|
37
|
+
untypedLocations: [],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
expect(client.formatResult(result)).toBe("");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should show coverage percentage", () => {
|
|
44
|
+
const result = {
|
|
45
|
+
success: true,
|
|
46
|
+
percentage: 95,
|
|
47
|
+
typed: 95,
|
|
48
|
+
total: 100,
|
|
49
|
+
untypedLocations: [],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const formatted = client.formatResult(result);
|
|
53
|
+
expect(formatted).toContain("95.0%");
|
|
54
|
+
expect(formatted).toContain("95/100");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should show warning for low coverage", () => {
|
|
58
|
+
const result = {
|
|
59
|
+
success: true,
|
|
60
|
+
percentage: 80,
|
|
61
|
+
typed: 80,
|
|
62
|
+
total: 100,
|
|
63
|
+
untypedLocations: [],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const formatted = client.formatResult(result);
|
|
67
|
+
expect(formatted).toContain("⚠");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should show checkmark for high coverage", () => {
|
|
71
|
+
const result = {
|
|
72
|
+
success: true,
|
|
73
|
+
percentage: 100,
|
|
74
|
+
typed: 100,
|
|
75
|
+
total: 100,
|
|
76
|
+
untypedLocations: [],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const formatted = client.formatResult(result);
|
|
80
|
+
expect(formatted).toContain("✓");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should show untyped locations", () => {
|
|
84
|
+
const result = {
|
|
85
|
+
success: true,
|
|
86
|
+
percentage: 90,
|
|
87
|
+
typed: 90,
|
|
88
|
+
total: 100,
|
|
89
|
+
untypedLocations: [
|
|
90
|
+
{ file: "test.ts", line: 10, column: 5, name: "x" },
|
|
91
|
+
{ file: "test.ts", line: 20, column: 8, name: "y" },
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const formatted = client.formatResult(result);
|
|
96
|
+
expect(formatted).toContain("test.ts:10");
|
|
97
|
+
expect(formatted).toContain("test.ts:20");
|
|
98
|
+
expect(formatted).toContain("x");
|
|
99
|
+
expect(formatted).toContain("y");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should truncate long untyped location lists", () => {
|
|
103
|
+
const locations = Array.from({ length: 20 }, (_, i) => ({
|
|
104
|
+
file: `file${i}.ts`,
|
|
105
|
+
line: i + 1,
|
|
106
|
+
column: 0,
|
|
107
|
+
name: `var${i}`,
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
const result = {
|
|
111
|
+
success: true,
|
|
112
|
+
percentage: 80,
|
|
113
|
+
typed: 80,
|
|
114
|
+
total: 100,
|
|
115
|
+
untypedLocations: locations,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const formatted = client.formatResult(result, 10);
|
|
119
|
+
expect(formatted).toContain("...");
|
|
120
|
+
expect(formatted).toContain("10 more");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
123
|
});
|
|
@@ -15,127 +15,154 @@ import * as path from "node:path";
|
|
|
15
15
|
// --- Types ---
|
|
16
16
|
|
|
17
17
|
export interface TypeCoverageResult {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
success: boolean;
|
|
19
|
+
percentage: number;
|
|
20
|
+
typed: number;
|
|
21
|
+
total: number;
|
|
22
|
+
untypedLocations: UntypedLocation[];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface UntypedLocation {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
file: string;
|
|
27
|
+
line: number;
|
|
28
|
+
column: number;
|
|
29
|
+
name: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// --- Client ---
|
|
33
33
|
|
|
34
34
|
export class TypeCoverageClient {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
35
|
+
private available: boolean | null = null;
|
|
36
|
+
private log: (msg: string) => void;
|
|
37
|
+
|
|
38
|
+
constructor(verbose = false) {
|
|
39
|
+
this.log = verbose
|
|
40
|
+
? (msg) => console.log(`[type-coverage] ${msg}`)
|
|
41
|
+
: () => {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
isAvailable(): boolean {
|
|
45
|
+
if (this.available !== null) return this.available;
|
|
46
|
+
const result = spawnSync("npx", ["type-coverage", "--version"], {
|
|
47
|
+
encoding: "utf-8",
|
|
48
|
+
timeout: 10000,
|
|
49
|
+
shell: true,
|
|
50
|
+
});
|
|
51
|
+
this.available = !result.error && result.status === 0;
|
|
52
|
+
return this.available;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Run type-coverage on the project at cwd.
|
|
57
|
+
* Uses --detail to get per-identifier locations for untyped names.
|
|
58
|
+
* Uses --strict to count `any` casts as untyped.
|
|
59
|
+
*/
|
|
60
|
+
scan(cwd: string): TypeCoverageResult {
|
|
61
|
+
if (!this.isAvailable()) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
percentage: 0,
|
|
65
|
+
typed: 0,
|
|
66
|
+
total: 0,
|
|
67
|
+
untypedLocations: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const result = spawnSync(
|
|
73
|
+
"npx",
|
|
74
|
+
[
|
|
75
|
+
"type-coverage",
|
|
76
|
+
"--detail",
|
|
77
|
+
"--strict",
|
|
78
|
+
"--ignore-files",
|
|
79
|
+
"**/*.d.ts",
|
|
80
|
+
],
|
|
81
|
+
{
|
|
82
|
+
encoding: "utf-8",
|
|
83
|
+
timeout: 30000,
|
|
84
|
+
cwd,
|
|
85
|
+
shell: true,
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const output = (result.stdout ?? "") + (result.stderr ?? "");
|
|
90
|
+
return this.parseOutput(output, cwd);
|
|
91
|
+
} catch (err: any) {
|
|
92
|
+
this.log(`Scan error: ${err.message}`);
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
percentage: 0,
|
|
96
|
+
typed: 0,
|
|
97
|
+
total: 0,
|
|
98
|
+
untypedLocations: [],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
formatResult(result: TypeCoverageResult, maxLocations = 10): string {
|
|
104
|
+
if (!result.success) return "";
|
|
105
|
+
|
|
106
|
+
const pct = result.percentage.toFixed(1);
|
|
107
|
+
let icon = "✗";
|
|
108
|
+
if (result.percentage >= 95) icon = "✓";
|
|
109
|
+
else if (result.percentage >= 80) icon = "⚠";
|
|
110
|
+
|
|
111
|
+
let output = `[type-coverage] ${icon} ${pct}% typed (${result.typed}/${result.total} identifiers)`;
|
|
112
|
+
|
|
113
|
+
if (result.untypedLocations.length === 0) {
|
|
114
|
+
output += " — fully typed\n";
|
|
115
|
+
return output;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
output += `:\n`;
|
|
119
|
+
for (const loc of result.untypedLocations.slice(0, maxLocations)) {
|
|
120
|
+
output += ` ${path.basename(loc.file)}:${loc.line}:${loc.column} — ${loc.name}\n`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (result.untypedLocations.length > maxLocations) {
|
|
124
|
+
output += ` ... and ${result.untypedLocations.length - maxLocations} more\n`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- Internal ---
|
|
131
|
+
|
|
132
|
+
private parseOutput(output: string, cwd: string): TypeCoverageResult {
|
|
133
|
+
const untypedLocations: UntypedLocation[] = [];
|
|
134
|
+
|
|
135
|
+
// Parse detail lines: "path/to/file.ts:line:col: name"
|
|
136
|
+
const detailPattern = /^(.+):(\d+):(\d+):\s+(.+)$/gm;
|
|
137
|
+
let match: RegExpExecArray | null;
|
|
138
|
+
while ((match = detailPattern.exec(output)) !== null) {
|
|
139
|
+
const [, file, line, col, name] = match;
|
|
140
|
+
// Skip the summary line which also matches the pattern
|
|
141
|
+
if (name.includes("%") || name.includes("/")) continue;
|
|
142
|
+
untypedLocations.push({
|
|
143
|
+
file: path.resolve(cwd, file),
|
|
144
|
+
line: parseInt(line, 10),
|
|
145
|
+
column: parseInt(col, 10),
|
|
146
|
+
name: name.trim(),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Parse summary: "(3979 / 4100) 97.04%"
|
|
151
|
+
const summaryMatch = output.match(/\((\d+)\s*\/\s*(\d+)\)\s*([\d.]+)%/);
|
|
152
|
+
if (!summaryMatch) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
percentage: 0,
|
|
156
|
+
typed: 0,
|
|
157
|
+
total: 0,
|
|
158
|
+
untypedLocations: [],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const typed = parseInt(summaryMatch[1], 10);
|
|
163
|
+
const total = parseInt(summaryMatch[2], 10);
|
|
164
|
+
const percentage = parseFloat(summaryMatch[3]);
|
|
165
|
+
|
|
166
|
+
return { success: true, percentage, typed, total, untypedLocations };
|
|
167
|
+
}
|
|
141
168
|
}
|
package/clients/types.ts
CHANGED
|
@@ -4,56 +4,56 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export interface Position {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
line: number;
|
|
8
|
+
character: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface Range {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
start: Position;
|
|
13
|
+
end: Position;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export enum DiagnosticSeverity {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
Error = 1,
|
|
18
|
+
Warning = 2,
|
|
19
|
+
Information = 3,
|
|
20
|
+
Hint = 4,
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface Diagnostic {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
range: Range;
|
|
25
|
+
severity?: DiagnosticSeverity;
|
|
26
|
+
code?: string | number;
|
|
27
|
+
source?: string;
|
|
28
|
+
message: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface SymbolInfo {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
name: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
line: number;
|
|
35
|
+
containerName?: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface HoverInfo {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
type: string;
|
|
40
|
+
documentation?: string;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export interface Location {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
file: string;
|
|
45
|
+
line: number;
|
|
46
|
+
character: number;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface CompletionItem {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
name: string;
|
|
51
|
+
kind: string;
|
|
52
|
+
sortText?: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export interface FoldingRange {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
startLine: number;
|
|
57
|
+
endLine: number;
|
|
58
|
+
kind: string;
|
|
59
59
|
}
|