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,120 +1,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TypeScriptClient } from "./typescript-client.js";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
2
|
import { createTempFile, setupTestEnvironment } from "./test-utils.js";
|
|
3
|
+
import { TypeScriptClient } from "./typescript-client.js";
|
|
4
4
|
|
|
5
5
|
describe("TypeScriptClient", () => {
|
|
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
|
-
|
|
6
|
+
let client: TypeScriptClient;
|
|
7
|
+
let tmpDir: string;
|
|
8
|
+
let cleanup: () => void;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
client = new TypeScriptClient();
|
|
12
|
+
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-ts-test-"));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
cleanup();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("isTypeScriptFile", () => {
|
|
24
|
+
it("should recognize TypeScript files", () => {
|
|
25
|
+
expect(client.isTypeScriptFile("test.ts")).toBe(true);
|
|
26
|
+
expect(client.isTypeScriptFile("test.tsx")).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should also recognize JavaScript files (for type checking)", () => {
|
|
30
|
+
expect(client.isTypeScriptFile("test.js")).toBe(true);
|
|
31
|
+
expect(client.isTypeScriptFile("test.jsx")).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should not recognize non-JS/TS files", () => {
|
|
35
|
+
expect(client.isTypeScriptFile("test.py")).toBe(false);
|
|
36
|
+
expect(client.isTypeScriptFile("test.md")).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("updateFile and getDiagnostics", () => {
|
|
41
|
+
it("should detect type errors", () => {
|
|
42
|
+
const content = `
|
|
43
43
|
const x: number = "string"; // Type error
|
|
44
44
|
`;
|
|
45
|
-
|
|
45
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
client.updateFile(filePath, content);
|
|
48
|
+
const diags = client.getDiagnostics(filePath);
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
expect(diags.length).toBeGreaterThan(0);
|
|
51
|
+
expect(diags.some((d) => d.message.includes("string"))).toBe(true);
|
|
52
|
+
});
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
it("should not report errors for valid code", () => {
|
|
55
|
+
const content = `
|
|
56
56
|
const x: number = 42;
|
|
57
57
|
const y: string = "hello";
|
|
58
58
|
`;
|
|
59
|
-
|
|
59
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
client.updateFile(filePath, content);
|
|
62
|
+
const diags = client.getDiagnostics(filePath);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
// May have warnings but no errors for valid code
|
|
65
|
+
const errors = diags.filter((d) => d.severity === 1); // Error severity
|
|
66
|
+
expect(errors.length).toBe(0);
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
it("should detect undefined variables", () => {
|
|
70
|
+
const content = `
|
|
71
71
|
function test() {
|
|
72
72
|
return undefinedVariable;
|
|
73
73
|
}
|
|
74
74
|
`;
|
|
75
|
-
|
|
75
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
client.updateFile(filePath, content);
|
|
78
|
+
const diags = client.getDiagnostics(filePath);
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
expect(diags.some((d) => d.message.includes("undefined"))).toBe(true);
|
|
81
|
+
});
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
it("should detect missing function arguments", () => {
|
|
84
|
+
const content = `
|
|
85
85
|
function add(a: number, b: number): number {
|
|
86
86
|
return a + b;
|
|
87
87
|
}
|
|
88
88
|
const result = add(1);
|
|
89
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
|
-
|
|
90
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
91
|
+
|
|
92
|
+
client.updateFile(filePath, content);
|
|
93
|
+
const diags = client.getDiagnostics(filePath);
|
|
94
|
+
|
|
95
|
+
expect(diags.some((d) => d.message.includes("Expected"))).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("diagnostic severity", () => {
|
|
100
|
+
it("should have correct severity levels", () => {
|
|
101
|
+
const diags = [
|
|
102
|
+
{
|
|
103
|
+
range: {
|
|
104
|
+
start: { line: 0, character: 0 },
|
|
105
|
+
end: { line: 0, character: 10 },
|
|
106
|
+
},
|
|
107
|
+
severity: 1, // Error
|
|
108
|
+
message: "Error message",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
range: {
|
|
112
|
+
start: { line: 1, character: 0 },
|
|
113
|
+
end: { line: 1, character: 10 },
|
|
114
|
+
},
|
|
115
|
+
severity: 2, // Warning
|
|
116
|
+
message: "Warning message",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
// Test that diagnostics have expected structure
|
|
121
|
+
expect(diags[0].severity).toBe(1); // Error
|
|
122
|
+
expect(diags[1].severity).toBe(2); // Warning
|
|
123
|
+
expect(diags[0].message).toContain("Error");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
120
126
|
});
|