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