pi-lens 3.1.2 → 3.2.0
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/CHANGELOG.md +55 -0
- package/README.md +16 -12
- package/clients/ast-grep-client.js +8 -1
- package/clients/ast-grep-client.ts +9 -1
- package/clients/biome-client.js +51 -38
- package/clients/biome-client.ts +60 -58
- package/clients/dependency-checker.js +30 -1
- package/clients/dependency-checker.ts +35 -1
- package/clients/dispatch/__tests__/runner-registration.test.ts +286 -282
- package/clients/dispatch/bus-dispatcher.js +15 -14
- package/clients/dispatch/bus-dispatcher.ts +32 -25
- package/clients/dispatch/dispatcher.js +18 -25
- package/clients/dispatch/dispatcher.test.ts +2 -1
- package/clients/dispatch/dispatcher.ts +17 -28
- package/clients/dispatch/plan.js +77 -32
- package/clients/dispatch/plan.ts +78 -32
- package/clients/dispatch/runners/ast-grep-napi.js +36 -376
- package/clients/dispatch/runners/ast-grep-napi.ts +60 -433
- package/clients/dispatch/runners/index.js +8 -4
- package/clients/dispatch/runners/index.ts +8 -4
- package/clients/dispatch/runners/lsp.js +65 -0
- package/clients/dispatch/runners/lsp.ts +125 -0
- package/clients/dispatch/runners/oxlint.js +2 -2
- package/clients/dispatch/runners/oxlint.ts +2 -2
- package/clients/dispatch/runners/pyright.js +24 -8
- package/clients/dispatch/runners/pyright.ts +28 -14
- package/clients/dispatch/runners/rust-clippy.js +2 -2
- package/clients/dispatch/runners/rust-clippy.ts +2 -4
- package/clients/dispatch/runners/tree-sitter.js +14 -2
- package/clients/dispatch/runners/tree-sitter.ts +15 -2
- package/clients/dispatch/runners/ts-lsp.js +3 -3
- package/clients/dispatch/runners/ts-lsp.ts +8 -5
- package/clients/dispatch/runners/yaml-rule-parser.js +292 -0
- package/clients/dispatch/runners/yaml-rule-parser.ts +338 -0
- package/clients/dispatch/types.js +3 -0
- package/clients/dispatch/types.ts +3 -0
- package/clients/formatters.js +67 -14
- package/clients/formatters.ts +68 -15
- package/clients/installer/index.js +78 -10
- package/clients/installer/index.ts +519 -426
- package/clients/jscpd-client.js +28 -0
- package/clients/jscpd-client.ts +41 -3
- package/clients/knip-client.js +30 -1
- package/clients/knip-client.ts +34 -2
- package/clients/lsp/__tests__/client.test.ts +64 -41
- package/clients/lsp/__tests__/config.test.ts +25 -17
- package/clients/lsp/__tests__/launch.test.ts +108 -43
- package/clients/lsp/__tests__/service.test.ts +76 -48
- package/clients/lsp/client.js +87 -2
- package/clients/lsp/client.ts +150 -6
- package/clients/lsp/config.js +8 -11
- package/clients/lsp/config.ts +24 -21
- package/clients/lsp/index.js +69 -0
- package/clients/lsp/index.ts +82 -0
- package/clients/lsp/interactive-install.js +19 -8
- package/clients/lsp/interactive-install.ts +52 -27
- package/clients/lsp/launch.js +182 -32
- package/clients/lsp/launch.ts +241 -38
- package/clients/lsp/path-utils.js +3 -46
- package/clients/lsp/path-utils.ts +11 -51
- package/clients/lsp/server.js +93 -71
- package/clients/lsp/server.ts +173 -131
- package/clients/path-utils.js +142 -0
- package/clients/path-utils.ts +153 -0
- package/clients/ruff-client.js +33 -4
- package/clients/ruff-client.ts +44 -13
- package/clients/safe-spawn.js +3 -1
- package/clients/safe-spawn.ts +3 -1
- package/clients/services/effect-integration.js +11 -7
- package/clients/services/effect-integration.ts +34 -26
- package/clients/sg-runner.js +51 -9
- package/clients/sg-runner.ts +58 -15
- package/clients/tree-sitter-client.js +12 -0
- package/clients/tree-sitter-client.ts +12 -0
- package/clients/typescript-client.js +6 -2
- package/clients/typescript-client.ts +9 -2
- package/commands/booboo.js +2 -4
- package/commands/booboo.ts +2 -4
- package/index.ts +377 -93
- package/package.json +2 -1
- package/rules/tree-sitter-queries/tsx/no-nested-links.yml +45 -0
- package/rules/tree-sitter-queries/typescript/constructor-super.yml +55 -0
- package/rules/tree-sitter-queries/typescript/debugger.yml +1 -1
- package/rules/tree-sitter-queries/typescript/no-dupe-class-members.yml +47 -0
- package/tsconfig.json +1 -1
- package/clients/__tests__/file-time.test.js +0 -216
- package/clients/__tests__/format-service.test.js +0 -245
- package/clients/__tests__/formatters.test.js +0 -271
- package/clients/agent-behavior-client.test.js +0 -94
- package/clients/ast-grep-client.test.js +0 -129
- package/clients/ast-grep-client.test.ts +0 -155
- package/clients/biome-client.test.js +0 -144
- package/clients/cache-manager.test.js +0 -197
- package/clients/complexity-client.test.js +0 -234
- package/clients/dependency-checker.test.js +0 -60
- package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
- package/clients/dispatch/__tests__/runner-registration.test.js +0 -236
- package/clients/dispatch/dispatcher.edge.test.js +0 -82
- package/clients/dispatch/dispatcher.format.test.js +0 -46
- package/clients/dispatch/dispatcher.inline.test.js +0 -74
- package/clients/dispatch/dispatcher.test.js +0 -115
- package/clients/dispatch/runners/architect.test.js +0 -138
- package/clients/dispatch/runners/ast-grep-napi.test.js +0 -106
- package/clients/dispatch/runners/oxlint.test.js +0 -230
- package/clients/dispatch/runners/pyright.test.js +0 -98
- package/clients/dispatch/runners/python-slop.test.js +0 -203
- package/clients/dispatch/runners/scan_codebase.test.js +0 -89
- package/clients/dispatch/runners/shellcheck.test.js +0 -98
- package/clients/dispatch/runners/spellcheck.test.js +0 -158
- package/clients/dispatch/runners/ts-slop.test.js +0 -180
- package/clients/dispatch/runners/ts-slop.test.ts +0 -230
- package/clients/dogfood.test.js +0 -201
- package/clients/file-kinds.test.js +0 -169
- package/clients/go-client.test.js +0 -127
- package/clients/jscpd-client.test.js +0 -127
- package/clients/knip-client.test.js +0 -112
- package/clients/lsp/__tests__/client.test.js +0 -325
- package/clients/lsp/__tests__/config.test.js +0 -166
- package/clients/lsp/__tests__/error-recovery.test.js +0 -213
- package/clients/lsp/__tests__/integration.test.js +0 -127
- package/clients/lsp/__tests__/launch.test.js +0 -260
- package/clients/lsp/__tests__/server.test.js +0 -259
- package/clients/lsp/__tests__/service.test.js +0 -417
- package/clients/metrics-client.test.js +0 -141
- package/clients/ruff-client.test.js +0 -132
- package/clients/rust-client.test.js +0 -108
- package/clients/sanitize.test.js +0 -177
- package/clients/secrets-scanner.test.js +0 -100
- package/clients/services/__tests__/effect-integration.test.js +0 -86
- package/clients/test-runner-client.test.js +0 -192
- package/clients/todo-scanner.test.js +0 -301
- package/clients/type-coverage-client.test.js +0 -105
- package/clients/typescript-client.codefix.test.js +0 -157
- package/clients/typescript-client.test.js +0 -105
- package/commands/clients/ast-grep-client.js +0 -250
- package/commands/clients/ast-grep-parser.js +0 -86
- package/commands/clients/ast-grep-rule-manager.js +0 -91
- package/commands/clients/ast-grep-types.js +0 -9
- package/commands/clients/biome-client.js +0 -380
- package/commands/clients/complexity-client.js +0 -667
- package/commands/clients/file-kinds.js +0 -177
- package/commands/clients/file-utils.js +0 -40
- package/commands/clients/jscpd-client.js +0 -169
- package/commands/clients/knip-client.js +0 -211
- package/commands/clients/ruff-client.js +0 -297
- package/commands/clients/safe-spawn.js +0 -88
- package/commands/clients/scan-utils.js +0 -83
- package/commands/clients/sg-runner.js +0 -190
- package/commands/clients/types.js +0 -11
- package/commands/clients/typescript-client.js +0 -505
- package/commands/rate.test.js +0 -119
- package/rules/ast-grep-rules/rules/no-dangerously-set-inner-html.yml +0 -13
- package/rules/ast-grep-rules/rules/no-debugger.yml +0 -12
- package/rules/ast-grep-rules/rules/no-eval.yml +0 -13
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for file-kinds.ts
|
|
3
|
-
* Centralized file type detection
|
|
4
|
-
*/
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { detectFileKind, getExtensionsForKind, getFileKindLabel, getLanguageId, isCodeKind, isConfigKind, isFileKind, isScannableFile, } from "./file-kinds.js";
|
|
7
|
-
describe("detectFileKind", () => {
|
|
8
|
-
it("should detect JavaScript/TypeScript files", () => {
|
|
9
|
-
expect(detectFileKind("src/app.ts")).toBe("jsts");
|
|
10
|
-
expect(detectFileKind("src/app.tsx")).toBe("jsts");
|
|
11
|
-
expect(detectFileKind("src/app.js")).toBe("jsts");
|
|
12
|
-
expect(detectFileKind("src/app.jsx")).toBe("jsts");
|
|
13
|
-
expect(detectFileKind("src/app.mjs")).toBe("jsts");
|
|
14
|
-
expect(detectFileKind("src/app.cjs")).toBe("jsts");
|
|
15
|
-
});
|
|
16
|
-
it("should detect Python files", () => {
|
|
17
|
-
expect(detectFileKind("app.py")).toBe("python");
|
|
18
|
-
expect(detectFileKind("tests/test_app.py")).toBe("python");
|
|
19
|
-
});
|
|
20
|
-
it("should detect Go files", () => {
|
|
21
|
-
expect(detectFileKind("main.go")).toBe("go");
|
|
22
|
-
expect(detectFileKind("pkg/utils.go")).toBe("go");
|
|
23
|
-
});
|
|
24
|
-
it("should detect Rust files", () => {
|
|
25
|
-
expect(detectFileKind("main.rs")).toBe("rust");
|
|
26
|
-
expect(detectFileKind("lib/app.rs")).toBe("rust");
|
|
27
|
-
});
|
|
28
|
-
it("should detect C++ files", () => {
|
|
29
|
-
expect(detectFileKind("main.cpp")).toBe("cxx");
|
|
30
|
-
expect(detectFileKind("header.hpp")).toBe("cxx");
|
|
31
|
-
expect(detectFileKind("file.cc")).toBe("cxx");
|
|
32
|
-
expect(detectFileKind("file.hxx")).toBe("cxx");
|
|
33
|
-
});
|
|
34
|
-
it("should detect CMake files", () => {
|
|
35
|
-
expect(detectFileKind("CMakeLists.txt")).toBe("cmake");
|
|
36
|
-
expect(detectFileKind("build.cmake")).toBe("cmake");
|
|
37
|
-
});
|
|
38
|
-
it("should detect Shell files", () => {
|
|
39
|
-
expect(detectFileKind("script.sh")).toBe("shell");
|
|
40
|
-
expect(detectFileKind("script.bash")).toBe("shell");
|
|
41
|
-
expect(detectFileKind("Makefile")).toBe("shell");
|
|
42
|
-
});
|
|
43
|
-
it("should detect JSON files", () => {
|
|
44
|
-
expect(detectFileKind("config.json")).toBe("json");
|
|
45
|
-
expect(detectFileKind("package.json")).toBe("json");
|
|
46
|
-
});
|
|
47
|
-
it("should detect Markdown files", () => {
|
|
48
|
-
expect(detectFileKind("README.md")).toBe("markdown");
|
|
49
|
-
expect(detectFileKind("docs/guide.mdx")).toBe("markdown");
|
|
50
|
-
});
|
|
51
|
-
it("should detect CSS files", () => {
|
|
52
|
-
expect(detectFileKind("style.css")).toBe("css");
|
|
53
|
-
expect(detectFileKind("style.scss")).toBe("css");
|
|
54
|
-
expect(detectFileKind("style.less")).toBe("css");
|
|
55
|
-
});
|
|
56
|
-
it("should detect YAML files", () => {
|
|
57
|
-
expect(detectFileKind("config.yaml")).toBe("yaml");
|
|
58
|
-
expect(detectFileKind("config.yml")).toBe("yaml");
|
|
59
|
-
});
|
|
60
|
-
it("should return undefined for unknown extensions", () => {
|
|
61
|
-
expect(detectFileKind("file.xyz")).toBeUndefined();
|
|
62
|
-
expect(detectFileKind("file")).toBeUndefined();
|
|
63
|
-
});
|
|
64
|
-
it("should handle case-insensitive extensions", () => {
|
|
65
|
-
expect(detectFileKind("file.TS")).toBe("jsts");
|
|
66
|
-
expect(detectFileKind("file.PY")).toBe("python");
|
|
67
|
-
});
|
|
68
|
-
it("should handle paths with special characters", () => {
|
|
69
|
-
expect(detectFileKind("/path/to/file.ts")).toBe("jsts");
|
|
70
|
-
expect(detectFileKind("C:\\path\\to\\file.py")).toBe("python");
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe("isFileKind", () => {
|
|
74
|
-
it("should check single file kind", () => {
|
|
75
|
-
expect(isFileKind("app.ts", "jsts")).toBe(true);
|
|
76
|
-
expect(isFileKind("app.py", "jsts")).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
it("should check multiple file kinds", () => {
|
|
79
|
-
expect(isFileKind("app.ts", ["jsts", "python"])).toBe(true);
|
|
80
|
-
expect(isFileKind("app.py", ["jsts", "python"])).toBe(true);
|
|
81
|
-
expect(isFileKind("app.go", ["jsts", "python"])).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
it("should return false for undefined file kind", () => {
|
|
84
|
-
expect(isFileKind("file.xyz", "jsts")).toBe(false);
|
|
85
|
-
expect(isFileKind("file.xyz", ["jsts", "python"])).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("isCodeKind", () => {
|
|
89
|
-
it("should identify code file kinds", () => {
|
|
90
|
-
expect(isCodeKind("jsts")).toBe(true);
|
|
91
|
-
expect(isCodeKind("python")).toBe(true);
|
|
92
|
-
expect(isCodeKind("go")).toBe(true);
|
|
93
|
-
expect(isCodeKind("rust")).toBe(true);
|
|
94
|
-
expect(isCodeKind("cxx")).toBe(true);
|
|
95
|
-
expect(isCodeKind("shell")).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
it("should reject non-code file kinds", () => {
|
|
98
|
-
expect(isCodeKind("json")).toBe(false);
|
|
99
|
-
expect(isCodeKind("markdown")).toBe(false);
|
|
100
|
-
expect(isCodeKind("css")).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe("isConfigKind", () => {
|
|
104
|
-
it("should identify config file kinds", () => {
|
|
105
|
-
expect(isConfigKind("json")).toBe(true);
|
|
106
|
-
expect(isConfigKind("yaml")).toBe(true);
|
|
107
|
-
expect(isConfigKind("markdown")).toBe(true);
|
|
108
|
-
expect(isConfigKind("css")).toBe(true);
|
|
109
|
-
});
|
|
110
|
-
it("should reject non-config file kinds", () => {
|
|
111
|
-
expect(isConfigKind("jsts")).toBe(false);
|
|
112
|
-
expect(isConfigKind("python")).toBe(false);
|
|
113
|
-
expect(isConfigKind("go")).toBe(false);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe("isScannableFile", () => {
|
|
117
|
-
it("should return true for code files", () => {
|
|
118
|
-
expect(isScannableFile("app.ts")).toBe(true);
|
|
119
|
-
expect(isScannableFile("app.py")).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
it("should return true for config files", () => {
|
|
122
|
-
expect(isScannableFile("config.json")).toBe(true);
|
|
123
|
-
expect(isScannableFile("README.md")).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
it("should return false for test files", () => {
|
|
126
|
-
expect(isScannableFile("app.test.ts")).toBe(false);
|
|
127
|
-
expect(isScannableFile("app.spec.ts")).toBe(false);
|
|
128
|
-
expect(isScannableFile("test-app.ts")).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
it("should return false for unknown extensions", () => {
|
|
131
|
-
expect(isScannableFile("file.xyz")).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("getLanguageId", () => {
|
|
135
|
-
it("should return correct language IDs", () => {
|
|
136
|
-
expect(getLanguageId("jsts")).toBe("typescript");
|
|
137
|
-
expect(getLanguageId("python")).toBe("python");
|
|
138
|
-
expect(getLanguageId("go")).toBe("go");
|
|
139
|
-
expect(getLanguageId("rust")).toBe("rust");
|
|
140
|
-
expect(getLanguageId("cxx")).toBe("cpp");
|
|
141
|
-
expect(getLanguageId("json")).toBe("json");
|
|
142
|
-
});
|
|
143
|
-
it("should return plaintext for unknown kinds", () => {
|
|
144
|
-
expect(getLanguageId("unknown")).toBe("plaintext");
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe("getExtensionsForKind", () => {
|
|
148
|
-
it("should return extensions for jsts", () => {
|
|
149
|
-
const exts = getExtensionsForKind("jsts");
|
|
150
|
-
expect(exts).toContain(".ts");
|
|
151
|
-
expect(exts).toContain(".tsx");
|
|
152
|
-
expect(exts).toContain(".js");
|
|
153
|
-
expect(exts).toContain(".jsx");
|
|
154
|
-
});
|
|
155
|
-
it("should return extensions for python", () => {
|
|
156
|
-
const exts = getExtensionsForKind("python");
|
|
157
|
-
expect(exts).toEqual([".py"]);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe("getFileKindLabel", () => {
|
|
161
|
-
it("should return human-readable labels", () => {
|
|
162
|
-
expect(getFileKindLabel("jsts")).toBe("JavaScript/TypeScript");
|
|
163
|
-
expect(getFileKindLabel("python")).toBe("Python");
|
|
164
|
-
expect(getFileKindLabel("cxx")).toBe("C/C++");
|
|
165
|
-
});
|
|
166
|
-
it("should return kind as fallback", () => {
|
|
167
|
-
expect(getFileKindLabel("unknown")).toBe("unknown");
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
-
import { GoClient } from "./go-client.js";
|
|
5
|
-
import { setupTestEnvironment } from "./test-utils.js";
|
|
6
|
-
describe("GoClient", () => {
|
|
7
|
-
let client;
|
|
8
|
-
let tmpDir;
|
|
9
|
-
let cleanup;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
client = new GoClient();
|
|
12
|
-
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-go-test-"));
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
cleanup();
|
|
16
|
-
});
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
cleanup();
|
|
19
|
-
});
|
|
20
|
-
describe("isGoFile", () => {
|
|
21
|
-
it("should recognize Go files", () => {
|
|
22
|
-
expect(client.isGoFile("main.go")).toBe(true);
|
|
23
|
-
expect(client.isGoFile("handler.go")).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
it("should not recognize non-Go files", () => {
|
|
26
|
-
expect(client.isGoFile("main.ts")).toBe(false);
|
|
27
|
-
expect(client.isGoFile("main.py")).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe("isGoAvailable", () => {
|
|
31
|
-
it("should check Go availability", () => {
|
|
32
|
-
const available = client.isGoAvailable();
|
|
33
|
-
expect(typeof available).toBe("boolean");
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe("isGoplsAvailable", () => {
|
|
37
|
-
it("should check gopls availability", () => {
|
|
38
|
-
const available = client.isGoplsAvailable();
|
|
39
|
-
expect(typeof available).toBe("boolean");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("checkFile", () => {
|
|
43
|
-
it("should return empty array for non-existent files", () => {
|
|
44
|
-
if (!client.isGoAvailable())
|
|
45
|
-
return;
|
|
46
|
-
const result = client.checkFile("/nonexistent/file.go");
|
|
47
|
-
expect(result).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
it("should return array for valid Go files", () => {
|
|
50
|
-
if (!client.isGoAvailable())
|
|
51
|
-
return;
|
|
52
|
-
const content = `
|
|
53
|
-
package main
|
|
54
|
-
|
|
55
|
-
import "fmt"
|
|
56
|
-
|
|
57
|
-
func main() {
|
|
58
|
-
fmt.Println("Hello, World!")
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
const filePath = path.join(tmpDir, "main.go");
|
|
62
|
-
fs.writeFileSync(filePath, content);
|
|
63
|
-
const result = client.checkFile(filePath);
|
|
64
|
-
expect(Array.isArray(result)).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
it("should detect syntax errors", () => {
|
|
67
|
-
if (!client.isGoAvailable())
|
|
68
|
-
return;
|
|
69
|
-
const content = `
|
|
70
|
-
package main
|
|
71
|
-
|
|
72
|
-
func main() {
|
|
73
|
-
fmt.Println("missing import"
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
const filePath = path.join(tmpDir, "main.go");
|
|
77
|
-
fs.writeFileSync(filePath, content);
|
|
78
|
-
const result = client.checkFile(filePath);
|
|
79
|
-
// go vet should catch syntax issues
|
|
80
|
-
expect(Array.isArray(result)).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe("formatDiagnostics", () => {
|
|
84
|
-
it("should format diagnostics for display", () => {
|
|
85
|
-
const diags = [
|
|
86
|
-
{
|
|
87
|
-
line: 5,
|
|
88
|
-
column: 2,
|
|
89
|
-
endLine: 5,
|
|
90
|
-
endColumn: 10,
|
|
91
|
-
severity: "error",
|
|
92
|
-
message: "undefined: fmt",
|
|
93
|
-
file: "main.go",
|
|
94
|
-
},
|
|
95
|
-
];
|
|
96
|
-
const formatted = client.formatDiagnostics(diags);
|
|
97
|
-
expect(formatted).toContain("Go");
|
|
98
|
-
expect(formatted).toContain("1 issue");
|
|
99
|
-
expect(formatted).toContain("undefined: fmt");
|
|
100
|
-
});
|
|
101
|
-
it("should show error and warning counts", () => {
|
|
102
|
-
const diags = [
|
|
103
|
-
{
|
|
104
|
-
line: 1,
|
|
105
|
-
column: 0,
|
|
106
|
-
endLine: 1,
|
|
107
|
-
endColumn: 10,
|
|
108
|
-
severity: "error",
|
|
109
|
-
message: "Error",
|
|
110
|
-
file: "test.go",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
line: 2,
|
|
114
|
-
column: 0,
|
|
115
|
-
endLine: 2,
|
|
116
|
-
endColumn: 10,
|
|
117
|
-
severity: "warning",
|
|
118
|
-
message: "Warning",
|
|
119
|
-
file: "test.go",
|
|
120
|
-
},
|
|
121
|
-
];
|
|
122
|
-
const formatted = client.formatDiagnostics(diags);
|
|
123
|
-
expect(formatted).toContain("1 error(s)");
|
|
124
|
-
expect(formatted).toContain("1 warning(s)");
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { JscpdClient } from "./jscpd-client.js";
|
|
3
|
-
import { createTempFile, setupTestEnvironment } from "./test-utils.js";
|
|
4
|
-
describe("JscpdClient", () => {
|
|
5
|
-
let client;
|
|
6
|
-
let tmpDir;
|
|
7
|
-
let cleanup;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
client = new JscpdClient();
|
|
10
|
-
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-jscpd-test-"));
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
cleanup();
|
|
14
|
-
});
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
cleanup();
|
|
17
|
-
});
|
|
18
|
-
describe("isAvailable", () => {
|
|
19
|
-
it("should check jscpd availability", () => {
|
|
20
|
-
const available = client.isAvailable();
|
|
21
|
-
expect(typeof available).toBe("boolean");
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe("scan", () => {
|
|
25
|
-
it("should return success=false when not available", () => {
|
|
26
|
-
// Create a mock that returns false
|
|
27
|
-
const mockClient = new JscpdClient();
|
|
28
|
-
if (mockClient.isAvailable())
|
|
29
|
-
return; // Skip if available
|
|
30
|
-
const result = mockClient.scan(tmpDir);
|
|
31
|
-
expect(result.success).toBe(false);
|
|
32
|
-
expect(result.clones).toEqual([]);
|
|
33
|
-
});
|
|
34
|
-
it("should detect duplicate code blocks", { timeout: 15000 }, () => {
|
|
35
|
-
if (!client.isAvailable())
|
|
36
|
-
return;
|
|
37
|
-
// Create identical code blocks in different files
|
|
38
|
-
const duplicateCode = `
|
|
39
|
-
function processData(data: number[]): number {
|
|
40
|
-
let sum = 0;
|
|
41
|
-
for (let i = 0; i < data.length; i++) {
|
|
42
|
-
sum += data[i];
|
|
43
|
-
}
|
|
44
|
-
return sum;
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
createTempFile(tmpDir, "file1.ts", duplicateCode);
|
|
48
|
-
createTempFile(tmpDir, "file2.ts", duplicateCode);
|
|
49
|
-
const result = client.scan(tmpDir, 3, 20); // Lower thresholds for test
|
|
50
|
-
expect(result.success).toBe(true);
|
|
51
|
-
// May or may not detect clones depending on jscpd behavior
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("formatResult", () => {
|
|
55
|
-
it("should return empty string for no success", () => {
|
|
56
|
-
const result = {
|
|
57
|
-
success: false,
|
|
58
|
-
clones: [],
|
|
59
|
-
duplicatedLines: 0,
|
|
60
|
-
totalLines: 100,
|
|
61
|
-
percentage: 0,
|
|
62
|
-
};
|
|
63
|
-
expect(client.formatResult(result)).toBe("");
|
|
64
|
-
});
|
|
65
|
-
it("should return empty string for no clones", () => {
|
|
66
|
-
const result = {
|
|
67
|
-
success: true,
|
|
68
|
-
clones: [],
|
|
69
|
-
duplicatedLines: 0,
|
|
70
|
-
totalLines: 100,
|
|
71
|
-
percentage: 0,
|
|
72
|
-
};
|
|
73
|
-
expect(client.formatResult(result)).toBe("");
|
|
74
|
-
});
|
|
75
|
-
it("should format clones for display", () => {
|
|
76
|
-
const result = {
|
|
77
|
-
success: true,
|
|
78
|
-
clones: [
|
|
79
|
-
{
|
|
80
|
-
fileA: "src/file1.ts",
|
|
81
|
-
startA: 10,
|
|
82
|
-
fileB: "src/file2.ts",
|
|
83
|
-
startB: 20,
|
|
84
|
-
lines: 15,
|
|
85
|
-
tokens: 50,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
fileA: "src/file3.ts",
|
|
89
|
-
startA: 5,
|
|
90
|
-
fileB: "src/file4.ts",
|
|
91
|
-
startB: 12,
|
|
92
|
-
lines: 8,
|
|
93
|
-
tokens: 30,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
duplicatedLines: 23,
|
|
97
|
-
totalLines: 500,
|
|
98
|
-
percentage: 4.6,
|
|
99
|
-
};
|
|
100
|
-
const formatted = client.formatResult(result);
|
|
101
|
-
expect(formatted).toContain("jscpd");
|
|
102
|
-
expect(formatted).toContain("2 duplicate block(s)");
|
|
103
|
-
expect(formatted).toContain("4.6%");
|
|
104
|
-
expect(formatted).toContain("15 lines");
|
|
105
|
-
});
|
|
106
|
-
it("should truncate long clone lists", () => {
|
|
107
|
-
const clones = Array.from({ length: 10 }, (_, i) => ({
|
|
108
|
-
fileA: `file${i}a.ts`,
|
|
109
|
-
startA: 1,
|
|
110
|
-
fileB: `file${i}b.ts`,
|
|
111
|
-
startB: 1,
|
|
112
|
-
lines: 5,
|
|
113
|
-
tokens: 20,
|
|
114
|
-
}));
|
|
115
|
-
const result = {
|
|
116
|
-
success: true,
|
|
117
|
-
clones,
|
|
118
|
-
duplicatedLines: 50,
|
|
119
|
-
totalLines: 1000,
|
|
120
|
-
percentage: 5,
|
|
121
|
-
};
|
|
122
|
-
const formatted = client.formatResult(result, 8);
|
|
123
|
-
expect(formatted).toContain("...");
|
|
124
|
-
expect(formatted).toContain("2 more");
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { KnipClient } from "./knip-client.js";
|
|
3
|
-
import { setupTestEnvironment } from "./test-utils.js";
|
|
4
|
-
describe("KnipClient", () => {
|
|
5
|
-
let client;
|
|
6
|
-
let tmpDir;
|
|
7
|
-
let cleanup;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
client = new KnipClient();
|
|
10
|
-
({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-knip-test-"));
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
cleanup();
|
|
14
|
-
});
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
cleanup();
|
|
17
|
-
});
|
|
18
|
-
describe("isAvailable", () => {
|
|
19
|
-
it("should check knip availability", () => {
|
|
20
|
-
const available = client.isAvailable();
|
|
21
|
-
expect(typeof available).toBe("boolean");
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe("analyze", () => {
|
|
25
|
-
it("should return success=false when not available", () => {
|
|
26
|
-
const mockClient = new KnipClient();
|
|
27
|
-
if (mockClient.isAvailable())
|
|
28
|
-
return;
|
|
29
|
-
const result = mockClient.analyze(tmpDir);
|
|
30
|
-
expect(result.success).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe("formatResult", () => {
|
|
34
|
-
it("should return empty string for no issues", () => {
|
|
35
|
-
const result = {
|
|
36
|
-
success: true,
|
|
37
|
-
issues: [],
|
|
38
|
-
unusedExports: [],
|
|
39
|
-
unusedFiles: [],
|
|
40
|
-
unusedDeps: [],
|
|
41
|
-
unlistedDeps: [],
|
|
42
|
-
summary: "",
|
|
43
|
-
};
|
|
44
|
-
expect(client.formatResult(result)).toBe("");
|
|
45
|
-
});
|
|
46
|
-
it("should format unused exports", () => {
|
|
47
|
-
const result = {
|
|
48
|
-
success: true,
|
|
49
|
-
issues: [
|
|
50
|
-
{ type: "export", name: "unusedFunc", file: "utils.ts" },
|
|
51
|
-
],
|
|
52
|
-
unusedExports: [
|
|
53
|
-
{ type: "export", name: "unusedFunc", file: "utils.ts" },
|
|
54
|
-
],
|
|
55
|
-
unusedFiles: [],
|
|
56
|
-
unusedDeps: [],
|
|
57
|
-
unlistedDeps: [],
|
|
58
|
-
summary: "Found 1 issue",
|
|
59
|
-
};
|
|
60
|
-
const formatted = client.formatResult(result);
|
|
61
|
-
expect(formatted).toContain("Knip");
|
|
62
|
-
expect(formatted).toContain("unusedFunc");
|
|
63
|
-
});
|
|
64
|
-
it("should format unused dependencies", () => {
|
|
65
|
-
const result = {
|
|
66
|
-
success: true,
|
|
67
|
-
issues: [{ type: "dependency", name: "lodash" }],
|
|
68
|
-
unusedExports: [],
|
|
69
|
-
unusedFiles: [],
|
|
70
|
-
unusedDeps: [{ type: "dependency", name: "lodash" }],
|
|
71
|
-
unlistedDeps: [],
|
|
72
|
-
summary: "",
|
|
73
|
-
};
|
|
74
|
-
const formatted = client.formatResult(result);
|
|
75
|
-
expect(formatted).toContain("lodash");
|
|
76
|
-
expect(formatted).toContain("unused dep");
|
|
77
|
-
});
|
|
78
|
-
it("should show unlisted dependencies count", () => {
|
|
79
|
-
const result = {
|
|
80
|
-
success: true,
|
|
81
|
-
issues: [{ type: "unlisted", name: "axios" }],
|
|
82
|
-
unusedExports: [],
|
|
83
|
-
unusedFiles: [],
|
|
84
|
-
unusedDeps: [],
|
|
85
|
-
unlistedDeps: [{ type: "unlisted", name: "axios" }],
|
|
86
|
-
summary: "",
|
|
87
|
-
};
|
|
88
|
-
const formatted = client.formatResult(result);
|
|
89
|
-
expect(formatted).toContain("unlisted dep");
|
|
90
|
-
});
|
|
91
|
-
it("should format multiple issue types", () => {
|
|
92
|
-
const result = {
|
|
93
|
-
success: true,
|
|
94
|
-
issues: [
|
|
95
|
-
{ type: "export", name: "func1", file: "a.ts" },
|
|
96
|
-
{ type: "file", name: "old.ts" },
|
|
97
|
-
],
|
|
98
|
-
unusedExports: [
|
|
99
|
-
{ type: "export", name: "func1", file: "a.ts" },
|
|
100
|
-
{ type: "export", name: "func2", file: "b.ts" },
|
|
101
|
-
],
|
|
102
|
-
unusedFiles: [{ type: "file", name: "old.ts" }],
|
|
103
|
-
unusedDeps: [],
|
|
104
|
-
unlistedDeps: [],
|
|
105
|
-
summary: "",
|
|
106
|
-
};
|
|
107
|
-
const formatted = client.formatResult(result);
|
|
108
|
-
expect(formatted).toContain("2 unused export(s)");
|
|
109
|
-
expect(formatted).toContain("1 unused file(s)");
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|