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,142 +1,153 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
2
|
import { RuffClient } from "./ruff-client.js";
|
|
3
3
|
import { createTempFile, setupTestEnvironment } from "./test-utils.js";
|
|
4
4
|
|
|
5
5
|
describe("RuffClient", () => {
|
|
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
|
-
|
|
6
|
+
let client: RuffClient;
|
|
7
|
+
let tmpDir: string;
|
|
8
|
+
let cleanup: () => void;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
client = new RuffClient();
|
|
12
|
+
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-ruff-test-"));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
cleanup();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("isPythonFile", () => {
|
|
24
|
+
it("should recognize Python files", () => {
|
|
25
|
+
expect(client.isPythonFile("test.py")).toBe(true);
|
|
26
|
+
expect(client.isPythonFile("module.py")).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should not recognize non-Python files", () => {
|
|
30
|
+
expect(client.isPythonFile("test.ts")).toBe(false);
|
|
31
|
+
expect(client.isPythonFile("test.js")).toBe(false);
|
|
32
|
+
expect(client.isPythonFile("test.txt")).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("isAvailable", () => {
|
|
37
|
+
it("should check ruff availability", () => {
|
|
38
|
+
const available = client.isAvailable();
|
|
39
|
+
expect(typeof available).toBe("boolean");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("checkFile", () => {
|
|
44
|
+
it("should return empty array for non-existent files", () => {
|
|
45
|
+
if (!client.isAvailable()) return;
|
|
46
|
+
const result = client.checkFile("/nonexistent/file.py");
|
|
47
|
+
expect(result).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should detect lint issues in Python code", () => {
|
|
51
|
+
if (!client.isAvailable()) return;
|
|
52
|
+
|
|
53
|
+
const content = `
|
|
54
54
|
import os
|
|
55
55
|
import sys
|
|
56
56
|
|
|
57
57
|
x = 1
|
|
58
58
|
`;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const filePath = createTempFile(tmpDir, "test.py", content);
|
|
60
|
+
const result = client.checkFile(filePath);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// Should detect unused imports
|
|
63
|
+
expect(
|
|
64
|
+
result.some((d) => d.rule === "F401" || d.message.includes("unused")),
|
|
65
|
+
).toBe(true);
|
|
66
|
+
});
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
it("should return array of diagnostics", () => {
|
|
69
|
+
if (!client.isAvailable()) return;
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
const content = `
|
|
70
72
|
def foo():
|
|
71
73
|
x = undefined_variable
|
|
72
74
|
return x
|
|
73
75
|
`;
|
|
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
|
-
|
|
76
|
+
const filePath = createTempFile(tmpDir, "test.py", content);
|
|
77
|
+
const result = client.checkFile(filePath);
|
|
78
|
+
|
|
79
|
+
// Should return an array
|
|
80
|
+
expect(Array.isArray(result)).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("formatDiagnostics", () => {
|
|
85
|
+
it("should format diagnostics for display", () => {
|
|
86
|
+
const diags = [
|
|
87
|
+
{
|
|
88
|
+
line: 1,
|
|
89
|
+
column: 0,
|
|
90
|
+
endLine: 1,
|
|
91
|
+
endColumn: 10,
|
|
92
|
+
severity: "error" as const,
|
|
93
|
+
message: "Undefined name 'x'",
|
|
94
|
+
rule: "F821",
|
|
95
|
+
file: "test.py",
|
|
96
|
+
fixable: false,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const formatted = client.formatDiagnostics(diags);
|
|
101
|
+
expect(formatted).toContain("Ruff");
|
|
102
|
+
expect(formatted).toContain("F821");
|
|
103
|
+
expect(formatted).toContain("Undefined name");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should show fixable count", () => {
|
|
107
|
+
const diags = [
|
|
108
|
+
{
|
|
109
|
+
line: 1,
|
|
110
|
+
column: 0,
|
|
111
|
+
endLine: 1,
|
|
112
|
+
endColumn: 10,
|
|
113
|
+
severity: "warning" as const,
|
|
114
|
+
message: "Unused import",
|
|
115
|
+
rule: "F401",
|
|
116
|
+
file: "test.py",
|
|
117
|
+
fixable: true,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
const formatted = client.formatDiagnostics(diags);
|
|
122
|
+
expect(formatted).toContain("fixable");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("checkFormatting", () => {
|
|
127
|
+
it("should detect formatting issues", () => {
|
|
128
|
+
if (!client.isAvailable()) return;
|
|
129
|
+
|
|
130
|
+
const content = `x=1
|
|
120
131
|
y=2
|
|
121
132
|
`;
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
const filePath = createTempFile(tmpDir, "test.py", content);
|
|
134
|
+
const result = client.checkFormatting(filePath);
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
// Should suggest formatting (missing spaces around =)
|
|
137
|
+
expect(typeof result).toBe("string");
|
|
138
|
+
});
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
it("should return empty string for well-formatted code", () => {
|
|
141
|
+
if (!client.isAvailable()) return;
|
|
131
142
|
|
|
132
|
-
|
|
143
|
+
const content = `x = 1
|
|
133
144
|
y = 2
|
|
134
145
|
`;
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
const filePath = createTempFile(tmpDir, "test.py", content);
|
|
147
|
+
const result = client.checkFormatting(filePath);
|
|
137
148
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
// Well-formatted code should return empty or minimal output
|
|
150
|
+
expect(result).toBe("");
|
|
151
|
+
});
|
|
152
|
+
});
|
|
142
153
|
});
|