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.
Files changed (36) hide show
  1. package/clients/ast-grep-client.test.ts +146 -116
  2. package/clients/ast-grep-client.ts +649 -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 +220 -216
  11. package/clients/jscpd-client.test.ts +132 -132
  12. package/clients/jscpd-client.ts +157 -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 +298 -269
  19. package/clients/rust-client.test.ts +104 -85
  20. package/clients/rust-client.ts +245 -234
  21. package/clients/subprocess-client.ts +2 -2
  22. package/clients/test-runner-client.test.ts +248 -215
  23. package/clients/test-runner-client.ts +730 -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 +121 -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 +669 -212
  33. package/package.json +1 -1
  34. package/rules/ast-grep-rules/rules/empty-catch.yml +12 -9
  35. package/tsconfig.json +12 -12
  36. package/rules/ast-grep-rules/rules/silent-failure.yml +0 -14
@@ -1,139 +1,169 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
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
- 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 = `
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
- const filePath = createTempFile(tmpDir, "test.ts", content);
41
- const result = client.scanFile(filePath);
40
+ const filePath = createTempFile(tmpDir, "test.ts", content);
41
+ const result = client.scanFile(filePath);
42
42
 
43
- // Should detect var usage
44
- expect(result.some(d => d.rule === "no-var")).toBe(true);
45
- });
43
+ // Should detect var usage
44
+ expect(result.some((d) => d.rule === "no-var")).toBe(true);
45
+ });
46
46
 
47
- it("should detect console.log usage", () => {
48
- if (!client.isAvailable()) return;
47
+ it("should detect console.log usage", () => {
48
+ if (!client.isAvailable()) return;
49
49
 
50
- const content = `
50
+ const content = `
51
51
  console.log("test");
52
52
  `;
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, column: 0, endLine: 1, endColumn: 10,
85
- severity: "warning" as const, message: "Warning", rule: "rule1", file: "test.ts",
86
- },
87
- {
88
- line: 2, column: 0, endLine: 2, endColumn: 10,
89
- severity: "error" as const, message: "Error", rule: "rule2", file: "test.ts",
90
- },
91
- ];
92
-
93
- const formatted = client.formatDiagnostics(diags);
94
- expect(formatted).toContain("warning(s)");
95
- expect(formatted).toContain("error(s)");
96
- });
97
-
98
- it("should show fixable indicator", () => {
99
- const diags = [
100
- {
101
- line: 1, column: 0, endLine: 1, endColumn: 10,
102
- severity: "warning" as const, message: "Use const", rule: "prefer-const",
103
- file: "test.ts", fix: "const",
104
- },
105
- ];
106
-
107
- const formatted = client.formatDiagnostics(diags);
108
- expect(formatted).toContain("fixable");
109
- });
110
- });
111
-
112
- describe("search", () => {
113
- it("should search for patterns", async () => {
114
- if (!client.isAvailable()) return;
115
-
116
- createTempFile(tmpDir, "test.ts", `
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
- const result = await client.search("console.log($MSG)", "typescript", [tmpDir]);
144
+ const result = await client.search("console.log($MSG)", "typescript", [
145
+ tmpDir,
146
+ ]);
123
147
 
124
- expect(result.matches.length).toBeGreaterThan(0);
125
- });
148
+ expect(result.matches.length).toBeGreaterThan(0);
149
+ });
126
150
 
127
- it("should return empty matches for no match", async () => {
128
- if (!client.isAvailable()) return;
151
+ it("should return empty matches for no match", async () => {
152
+ if (!client.isAvailable()) return;
129
153
 
130
- createTempFile(tmpDir, "test.ts", `
154
+ createTempFile(
155
+ tmpDir,
156
+ "test.ts",
157
+ `
131
158
  const x = 1;
132
- `);
159
+ `,
160
+ );
133
161
 
134
- const result = await client.search("console.log($MSG)", "typescript", [tmpDir]);
162
+ const result = await client.search("console.log($MSG)", "typescript", [
163
+ tmpDir,
164
+ ]);
135
165
 
136
- expect(result.matches.length).toBe(0);
137
- });
138
- });
166
+ expect(result.matches.length).toBe(0);
167
+ });
168
+ });
139
169
  });