pi-lens 2.0.7 → 2.0.9
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 +649 -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 +220 -216
- package/clients/jscpd-client.test.ts +132 -132
- package/clients/jscpd-client.ts +157 -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 +298 -269
- package/clients/rust-client.test.ts +104 -85
- package/clients/rust-client.ts +245 -234
- package/clients/subprocess-client.ts +2 -2
- package/clients/test-runner-client.test.ts +248 -215
- package/clients/test-runner-client.ts +730 -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 +121 -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 +669 -212
- package/package.json +1 -1
- package/rules/ast-grep-rules/rules/empty-catch.yml +12 -9
- package/tsconfig.json +12 -12
- package/rules/ast-grep-rules/rules/silent-failure.yml +0 -14
|
@@ -1,139 +1,169 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
2
|
import { AstGrepClient } from "./ast-grep-client.js";
|
|
3
3
|
import { createTempFile, setupTestEnvironment } from "./test-utils.js";
|
|
4
4
|
|
|
5
5
|
describe("AstGrepClient", () => {
|
|
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
|
-
|
|
6
|
+
let client: AstGrepClient;
|
|
7
|
+
let tmpDir: string;
|
|
8
|
+
let cleanup: () => void;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
client = new AstGrepClient();
|
|
12
|
+
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-astgrep-test-"));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("isAvailable", () => {
|
|
20
|
+
it("should check ast-grep availability", () => {
|
|
21
|
+
const available = client.isAvailable();
|
|
22
|
+
expect(typeof available).toBe("boolean");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("scanFile", () => {
|
|
27
|
+
it("should return empty array for non-existent files", () => {
|
|
28
|
+
if (!client.isAvailable()) return;
|
|
29
|
+
const result = client.scanFile("/nonexistent/file.ts");
|
|
30
|
+
expect(result).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should detect var usage (no-var rule)", () => {
|
|
34
|
+
if (!client.isAvailable()) return;
|
|
35
|
+
|
|
36
|
+
const content = `
|
|
37
37
|
var x = 1;
|
|
38
38
|
var y = 2;
|
|
39
39
|
`;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
41
|
+
const result = client.scanFile(filePath);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// Should detect var usage
|
|
44
|
+
expect(result.some((d) => d.rule === "no-var")).toBe(true);
|
|
45
|
+
});
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
it("should detect console.log usage", () => {
|
|
48
|
+
if (!client.isAvailable()) return;
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const content = `
|
|
51
51
|
console.log("test");
|
|
52
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
|
-
|
|
53
|
+
const filePath = createTempFile(tmpDir, "test.ts", content);
|
|
54
|
+
const result = client.scanFile(filePath);
|
|
55
|
+
|
|
56
|
+
// May detect console.log depending on rules
|
|
57
|
+
expect(Array.isArray(result)).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("formatDiagnostics", () => {
|
|
62
|
+
it("should format diagnostics for display", () => {
|
|
63
|
+
const diags = [
|
|
64
|
+
{
|
|
65
|
+
line: 1,
|
|
66
|
+
column: 0,
|
|
67
|
+
endLine: 1,
|
|
68
|
+
endColumn: 10,
|
|
69
|
+
severity: "warning" as const,
|
|
70
|
+
message: "Unexpected var, use let or const instead",
|
|
71
|
+
rule: "no-var",
|
|
72
|
+
file: "test.ts",
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const formatted = client.formatDiagnostics(diags);
|
|
77
|
+
expect(formatted).toContain("ast-grep");
|
|
78
|
+
expect(formatted).toContain("no-var");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should categorize by severity", () => {
|
|
82
|
+
const diags = [
|
|
83
|
+
{
|
|
84
|
+
line: 1,
|
|
85
|
+
column: 0,
|
|
86
|
+
endLine: 1,
|
|
87
|
+
endColumn: 10,
|
|
88
|
+
severity: "warning" as const,
|
|
89
|
+
message: "Warning",
|
|
90
|
+
rule: "rule1",
|
|
91
|
+
file: "test.ts",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
line: 2,
|
|
95
|
+
column: 0,
|
|
96
|
+
endLine: 2,
|
|
97
|
+
endColumn: 10,
|
|
98
|
+
severity: "error" as const,
|
|
99
|
+
message: "Error",
|
|
100
|
+
rule: "rule2",
|
|
101
|
+
file: "test.ts",
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const formatted = client.formatDiagnostics(diags);
|
|
106
|
+
expect(formatted).toContain("warning(s)");
|
|
107
|
+
expect(formatted).toContain("error(s)");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should show fixable indicator", () => {
|
|
111
|
+
const diags = [
|
|
112
|
+
{
|
|
113
|
+
line: 1,
|
|
114
|
+
column: 0,
|
|
115
|
+
endLine: 1,
|
|
116
|
+
endColumn: 10,
|
|
117
|
+
severity: "warning" as const,
|
|
118
|
+
message: "Use const",
|
|
119
|
+
rule: "prefer-const",
|
|
120
|
+
file: "test.ts",
|
|
121
|
+
fix: "const",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const formatted = client.formatDiagnostics(diags);
|
|
126
|
+
expect(formatted).toContain("fixable");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("search", () => {
|
|
131
|
+
it("should search for patterns", async () => {
|
|
132
|
+
if (!client.isAvailable()) return;
|
|
133
|
+
|
|
134
|
+
createTempFile(
|
|
135
|
+
tmpDir,
|
|
136
|
+
"test.ts",
|
|
137
|
+
`
|
|
117
138
|
function test() {
|
|
118
139
|
console.log("hello");
|
|
119
140
|
}
|
|
120
|
-
|
|
141
|
+
`,
|
|
142
|
+
);
|
|
121
143
|
|
|
122
|
-
|
|
144
|
+
const result = await client.search("console.log($MSG)", "typescript", [
|
|
145
|
+
tmpDir,
|
|
146
|
+
]);
|
|
123
147
|
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
expect(result.matches.length).toBeGreaterThan(0);
|
|
149
|
+
});
|
|
126
150
|
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
it("should return empty matches for no match", async () => {
|
|
152
|
+
if (!client.isAvailable()) return;
|
|
129
153
|
|
|
130
|
-
|
|
154
|
+
createTempFile(
|
|
155
|
+
tmpDir,
|
|
156
|
+
"test.ts",
|
|
157
|
+
`
|
|
131
158
|
const x = 1;
|
|
132
|
-
|
|
159
|
+
`,
|
|
160
|
+
);
|
|
133
161
|
|
|
134
|
-
|
|
162
|
+
const result = await client.search("console.log($MSG)", "typescript", [
|
|
163
|
+
tmpDir,
|
|
164
|
+
]);
|
|
135
165
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
166
|
+
expect(result.matches.length).toBe(0);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
139
169
|
});
|