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,505 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript Language Service Client for pi-local
|
|
3
|
-
*
|
|
4
|
-
* Uses TypeScript's in-process Language Service API for rich code intelligence.
|
|
5
|
-
* This is lighter weight than spawning tsserver and provides the same features.
|
|
6
|
-
*/
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import * as ts from "typescript";
|
|
10
|
-
// TypeScript file extensions
|
|
11
|
-
const TS_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx"]);
|
|
12
|
-
// Default compiler options when no tsconfig is found
|
|
13
|
-
/**
|
|
14
|
-
* Build default CompilerOptions through TypeScript's own config parser so that
|
|
15
|
-
* lib name → file path resolution works correctly in the Language Service.
|
|
16
|
-
* Direct assignment of `lib: ["lib.es2020.d.ts"]` doesn't work because the
|
|
17
|
-
* Language Service looks up those names relative to cwd, not the TS install dir.
|
|
18
|
-
*/
|
|
19
|
-
function buildDefaultCompilerOptions() {
|
|
20
|
-
const fakeConfig = {
|
|
21
|
-
compilerOptions: {
|
|
22
|
-
target: "ES2020",
|
|
23
|
-
module: "ESNext",
|
|
24
|
-
moduleResolution: "bundler",
|
|
25
|
-
strict: true,
|
|
26
|
-
esModuleInterop: true,
|
|
27
|
-
skipLibCheck: true,
|
|
28
|
-
lib: ["es2020", "dom", "dom.iterable"],
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const parsed = ts.parseJsonConfigFileContent(fakeConfig, ts.sys, process.cwd());
|
|
32
|
-
return { ...parsed.options, skipLibCheck: true };
|
|
33
|
-
}
|
|
34
|
-
const DEFAULT_COMPILER_OPTIONS = buildDefaultCompilerOptions();
|
|
35
|
-
/**
|
|
36
|
-
* Walk up from startDir until we find a tsconfig.json, or hit the fs root.
|
|
37
|
-
*/
|
|
38
|
-
function findTsConfig(startDir) {
|
|
39
|
-
let dir = startDir;
|
|
40
|
-
while (true) {
|
|
41
|
-
const candidate = path.join(dir, "tsconfig.json");
|
|
42
|
-
if (fs.existsSync(candidate))
|
|
43
|
-
return candidate;
|
|
44
|
-
const parent = path.dirname(dir);
|
|
45
|
-
if (parent === dir)
|
|
46
|
-
return null; // reached root
|
|
47
|
-
dir = parent;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Read and parse a tsconfig.json, returning merged CompilerOptions.
|
|
52
|
-
* Falls back to DEFAULT_COMPILER_OPTIONS on any error.
|
|
53
|
-
*/
|
|
54
|
-
function loadCompilerOptions(tsconfigPath) {
|
|
55
|
-
try {
|
|
56
|
-
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
57
|
-
if (configFile.error)
|
|
58
|
-
return DEFAULT_COMPILER_OPTIONS;
|
|
59
|
-
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
|
|
60
|
-
if (parsed.errors.length)
|
|
61
|
-
return DEFAULT_COMPILER_OPTIONS;
|
|
62
|
-
// Always set skipLibCheck to avoid noise from node_modules
|
|
63
|
-
return { ...parsed.options, skipLibCheck: true };
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
void err;
|
|
67
|
-
return DEFAULT_COMPILER_OPTIONS;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export class TypeScriptClient {
|
|
71
|
-
fileVersions = new Map();
|
|
72
|
-
fileContents = new Map();
|
|
73
|
-
languageService = null;
|
|
74
|
-
compilerOptions = DEFAULT_COMPILER_OPTIONS;
|
|
75
|
-
lastTsconfigDir = null;
|
|
76
|
-
constructor() {
|
|
77
|
-
this.initialize();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Normalize file path for consistent cross-platform use
|
|
81
|
-
*/
|
|
82
|
-
normalizePath(filePath) {
|
|
83
|
-
return path.resolve(filePath).replace(/\\/g, "/");
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Check if a file is a TypeScript/JavaScript file
|
|
87
|
-
*/
|
|
88
|
-
isTypeScriptFile(filePath) {
|
|
89
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
90
|
-
return TS_EXTENSIONS.has(ext);
|
|
91
|
-
}
|
|
92
|
-
initialize() {
|
|
93
|
-
const host = {
|
|
94
|
-
getScriptFileNames: () => Array.from(this.fileContents.keys()),
|
|
95
|
-
getScriptVersion: (fileName) => {
|
|
96
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
97
|
-
return String(this.fileVersions.get(normalized) ?? 0);
|
|
98
|
-
},
|
|
99
|
-
getScriptSnapshot: (fileName) => {
|
|
100
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
101
|
-
const content = this.fileContents.get(normalized);
|
|
102
|
-
if (content)
|
|
103
|
-
return ts.ScriptSnapshot.fromString(content);
|
|
104
|
-
try {
|
|
105
|
-
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName, "utf-8"));
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
getCurrentDirectory: () => process.cwd(),
|
|
112
|
-
getCompilationSettings: () => this.compilerOptions,
|
|
113
|
-
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
114
|
-
fileExists: (fileName) => ts.sys.fileExists(fileName),
|
|
115
|
-
readFile: (fileName) => {
|
|
116
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
117
|
-
const cached = this.fileContents.get(normalized);
|
|
118
|
-
if (cached !== undefined)
|
|
119
|
-
return cached;
|
|
120
|
-
return ts.sys.readFile(fileName);
|
|
121
|
-
},
|
|
122
|
-
directoryExists: (dirName) => ts.sys.directoryExists(dirName),
|
|
123
|
-
getDirectories: (dir) => ts.sys.getDirectories(dir),
|
|
124
|
-
};
|
|
125
|
-
this.languageService = ts.createLanguageService(host, ts.createDocumentRegistry());
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Detect tsconfig for the given file and refresh compilerOptions if the
|
|
129
|
-
* project root changed (avoids redundant re-parses across edits to the same project).
|
|
130
|
-
*/
|
|
131
|
-
refreshCompilerOptions(filePath) {
|
|
132
|
-
const dir = path.dirname(path.resolve(filePath));
|
|
133
|
-
const tsconfigPath = findTsConfig(dir);
|
|
134
|
-
const key = tsconfigPath ?? dir;
|
|
135
|
-
if (key === this.lastTsconfigDir)
|
|
136
|
-
return; // same project, no change
|
|
137
|
-
this.lastTsconfigDir = key;
|
|
138
|
-
this.compilerOptions = tsconfigPath
|
|
139
|
-
? loadCompilerOptions(tsconfigPath)
|
|
140
|
-
: DEFAULT_COMPILER_OPTIONS;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Add a file to the language service
|
|
144
|
-
*/
|
|
145
|
-
addFile(filePath, content) {
|
|
146
|
-
const normalized = this.normalizePath(filePath);
|
|
147
|
-
this.fileContents.set(normalized, content);
|
|
148
|
-
this.fileVersions.set(normalized, (this.fileVersions.get(normalized) || 0) + 1);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Update a file's content — also refreshes compilerOptions if project changed
|
|
152
|
-
*/
|
|
153
|
-
updateFile(filePath, content) {
|
|
154
|
-
this.refreshCompilerOptions(filePath);
|
|
155
|
-
const normalized = this.normalizePath(filePath);
|
|
156
|
-
this.fileVersions.set(normalized, (this.fileVersions.get(normalized) ?? 0) + 1);
|
|
157
|
-
this.fileContents.set(normalized, content);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Ensure a file is loaded from disk (refreshes cache)
|
|
161
|
-
*/
|
|
162
|
-
ensureFile(filePath) {
|
|
163
|
-
const normalized = this.normalizePath(filePath);
|
|
164
|
-
try {
|
|
165
|
-
const diskContent = fs.readFileSync(filePath, "utf-8");
|
|
166
|
-
const cachedContent = this.fileContents.get(normalized);
|
|
167
|
-
if (cachedContent !== diskContent) {
|
|
168
|
-
this.updateFile(filePath, diskContent);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
void err;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get all tracked files
|
|
177
|
-
*/
|
|
178
|
-
getTrackedFiles() {
|
|
179
|
-
return Array.from(this.fileContents.keys());
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Convert line/character to position offset
|
|
183
|
-
*/
|
|
184
|
-
lineCharToPosition(content, line, character) {
|
|
185
|
-
const lines = content.split("\n");
|
|
186
|
-
let position = 0;
|
|
187
|
-
for (let i = 0; i < Math.min(line, lines.length); i++) {
|
|
188
|
-
position += lines[i].length + 1;
|
|
189
|
-
}
|
|
190
|
-
return position + character;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Get diagnostics (errors and warnings) for a file
|
|
194
|
-
*/
|
|
195
|
-
getDiagnostics(filePath) {
|
|
196
|
-
this.refreshCompilerOptions(filePath);
|
|
197
|
-
const normalized = this.normalizePath(filePath);
|
|
198
|
-
this.ensureFile(filePath);
|
|
199
|
-
if (!this.languageService)
|
|
200
|
-
return [];
|
|
201
|
-
const syntactic = this.languageService.getSyntacticDiagnostics(normalized);
|
|
202
|
-
const semantic = this.languageService.getSemanticDiagnostics(normalized);
|
|
203
|
-
return ([...syntactic, ...semantic]
|
|
204
|
-
.filter((diag) => diag.file && diag.start !== undefined)
|
|
205
|
-
// Filter cross-file "redeclare" noise — happens when non-module scripts
|
|
206
|
-
// share global scope across multiple tracked files (TS2300, TS2451)
|
|
207
|
-
.filter((diag) => {
|
|
208
|
-
if (diag.code !== 2300 && diag.code !== 2451)
|
|
209
|
-
return true;
|
|
210
|
-
// Only keep if the related information points back to the same file
|
|
211
|
-
const related = diag.relatedInformation ?? [];
|
|
212
|
-
return related.every((r) => !r.file || this.normalizePath(r.file.fileName) === normalized);
|
|
213
|
-
})
|
|
214
|
-
.map((diag) => {
|
|
215
|
-
const startPos = diag.file?.getLineAndCharacterOfPosition(diag.start);
|
|
216
|
-
const endPos = diag.file?.getLineAndCharacterOfPosition(diag.start + diag.length);
|
|
217
|
-
return {
|
|
218
|
-
range: {
|
|
219
|
-
start: { line: startPos.line, character: startPos.character },
|
|
220
|
-
end: { line: endPos.line, character: endPos.character },
|
|
221
|
-
},
|
|
222
|
-
severity: (diag.category === ts.DiagnosticCategory.Error
|
|
223
|
-
? 1
|
|
224
|
-
: 2),
|
|
225
|
-
code: diag.code,
|
|
226
|
-
message: ts.flattenDiagnosticMessageText(diag.messageText, "\n"),
|
|
227
|
-
source: "typescript",
|
|
228
|
-
};
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Get hover information at a position
|
|
233
|
-
*/
|
|
234
|
-
getHover(filePath, line, character) {
|
|
235
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
236
|
-
if (!resolved)
|
|
237
|
-
return null;
|
|
238
|
-
const { normalized, position, ls } = resolved;
|
|
239
|
-
const info = ls.getQuickInfoAtPosition(normalized, position);
|
|
240
|
-
if (!info)
|
|
241
|
-
return null;
|
|
242
|
-
return {
|
|
243
|
-
type: ts.displayPartsToString(info.displayParts),
|
|
244
|
-
documentation: info.documentation
|
|
245
|
-
? ts.displayPartsToString(info.documentation)
|
|
246
|
-
: undefined,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Shared preamble for position-based LSP queries.
|
|
251
|
-
* Returns null if prerequisites are not met.
|
|
252
|
-
*/
|
|
253
|
-
resolvePosition(filePath, line, character) {
|
|
254
|
-
const normalized = this.normalizePath(filePath);
|
|
255
|
-
this.ensureFile(filePath);
|
|
256
|
-
if (!this.languageService)
|
|
257
|
-
return null;
|
|
258
|
-
const content = this.fileContents.get(normalized);
|
|
259
|
-
if (!content)
|
|
260
|
-
return null;
|
|
261
|
-
return {
|
|
262
|
-
normalized,
|
|
263
|
-
position: this.lineCharToPosition(content, line, character),
|
|
264
|
-
ls: this.languageService,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
withPosition(filePath, line, character, cb) {
|
|
268
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
269
|
-
if (!resolved)
|
|
270
|
-
return [];
|
|
271
|
-
const { normalized, position, ls } = resolved;
|
|
272
|
-
return cb(normalized, position, ls) ?? [];
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Go to definition
|
|
276
|
-
*/
|
|
277
|
-
getDefinition(filePath, line, character) {
|
|
278
|
-
return this.withPosition(filePath, line, character, (normalized, position, ls) => {
|
|
279
|
-
const definitions = ls.getDefinitionAtPosition(normalized, position);
|
|
280
|
-
if (!definitions)
|
|
281
|
-
return undefined;
|
|
282
|
-
return definitions.map((def) => {
|
|
283
|
-
if (def.textSpan) {
|
|
284
|
-
const defFile = def.fileName || normalized;
|
|
285
|
-
const defContent = this.fileContents.get(defFile) || "";
|
|
286
|
-
if (defContent) {
|
|
287
|
-
const lines = defContent
|
|
288
|
-
.substring(0, def.textSpan.start)
|
|
289
|
-
.split("\n");
|
|
290
|
-
return {
|
|
291
|
-
file: defFile,
|
|
292
|
-
line: lines.length - 1,
|
|
293
|
-
character: lines[lines.length - 1].length,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return { file: def.fileName, line: 0, character: 0 };
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Get type definition
|
|
303
|
-
*/
|
|
304
|
-
getTypeDefinition(filePath, line, character) {
|
|
305
|
-
return this.withPosition(filePath, line, character, (normalized, position, ls) => {
|
|
306
|
-
const defs = ls.getTypeDefinitionAtPosition(normalized, position);
|
|
307
|
-
if (!defs)
|
|
308
|
-
return undefined;
|
|
309
|
-
return this.toLocations(defs, normalized);
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Find references
|
|
314
|
-
*/
|
|
315
|
-
getReferences(filePath, line, character) {
|
|
316
|
-
return this.withPosition(filePath, line, character, (normalized, position, ls) => {
|
|
317
|
-
const references = ls.getReferencesAtPosition(normalized, position);
|
|
318
|
-
if (!references)
|
|
319
|
-
return undefined;
|
|
320
|
-
return this.toLocations(references);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
/** Map TS definition/reference entries to Location objects. */
|
|
324
|
-
toLocations(entries, fallbackFile) {
|
|
325
|
-
return entries.map((e) => ({
|
|
326
|
-
file: e.fileName || fallbackFile || "",
|
|
327
|
-
line: 0,
|
|
328
|
-
character: 0,
|
|
329
|
-
}));
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Shared preamble for tree-based LSP queries (symbols, folding).
|
|
333
|
-
*/
|
|
334
|
-
resolveTree(filePath) {
|
|
335
|
-
const normalized = this.normalizePath(filePath);
|
|
336
|
-
this.ensureFile(filePath);
|
|
337
|
-
if (!this.languageService)
|
|
338
|
-
return null;
|
|
339
|
-
const tree = this.languageService.getNavigationTree(normalized);
|
|
340
|
-
if (!tree)
|
|
341
|
-
return null;
|
|
342
|
-
return { normalized, tree };
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Get document symbols
|
|
346
|
-
*/
|
|
347
|
-
getSymbols(filePath) {
|
|
348
|
-
const resolved = this.resolveTree(filePath);
|
|
349
|
-
if (!resolved)
|
|
350
|
-
return [];
|
|
351
|
-
const { tree } = resolved;
|
|
352
|
-
const symbols = [];
|
|
353
|
-
const extract = (node, container) => {
|
|
354
|
-
if (node.span) {
|
|
355
|
-
symbols.push({
|
|
356
|
-
name: node.text,
|
|
357
|
-
kind: this.symbolKind(node.kind),
|
|
358
|
-
line: 0,
|
|
359
|
-
containerName: container,
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
if (node.childItems) {
|
|
363
|
-
for (const child of node.childItems) {
|
|
364
|
-
extract(child, node.text);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
extract(tree);
|
|
369
|
-
return symbols;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Get completions at a position
|
|
373
|
-
*/
|
|
374
|
-
getCompletions(filePath, line, character) {
|
|
375
|
-
return this.withPosition(filePath, line, character, (normalized, position, ls) => {
|
|
376
|
-
const completions = ls.getCompletionsAtPosition(normalized, position, {});
|
|
377
|
-
if (!completions)
|
|
378
|
-
return undefined;
|
|
379
|
-
return completions.entries.slice(0, 50).map((entry) => ({
|
|
380
|
-
name: entry.name,
|
|
381
|
-
kind: this.completionKind(entry.kind),
|
|
382
|
-
sortText: entry.sortText,
|
|
383
|
-
}));
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Go to implementation
|
|
388
|
-
*/
|
|
389
|
-
getImplementation(filePath, line, character) {
|
|
390
|
-
return this.withPosition(filePath, line, character, (normalized, position, ls) => {
|
|
391
|
-
const implementations = ls.getImplementationAtPosition(normalized, position);
|
|
392
|
-
if (!implementations)
|
|
393
|
-
return undefined;
|
|
394
|
-
return this.toLocations(implementations);
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Get folding ranges
|
|
399
|
-
*/
|
|
400
|
-
getFoldingRanges(filePath) {
|
|
401
|
-
const resolved = this.resolveTree(filePath);
|
|
402
|
-
if (!resolved)
|
|
403
|
-
return [];
|
|
404
|
-
const { tree } = resolved;
|
|
405
|
-
const ranges = [];
|
|
406
|
-
const findFolds = (node) => {
|
|
407
|
-
if (!node?.span)
|
|
408
|
-
return;
|
|
409
|
-
if (node.kind === "function" || node.kind === "class") {
|
|
410
|
-
ranges.push({
|
|
411
|
-
startLine: 0,
|
|
412
|
-
endLine: 0,
|
|
413
|
-
kind: node.kind,
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
if (node.childItems) {
|
|
417
|
-
for (const child of node.childItems) {
|
|
418
|
-
findFolds(child);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
findFolds(tree);
|
|
423
|
-
return ranges;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Explain an error at a specific line
|
|
427
|
-
*/
|
|
428
|
-
explainError(filePath, line) {
|
|
429
|
-
const diagnostics = this.getDiagnostics(filePath);
|
|
430
|
-
const errorAtLine = diagnostics.find((d) => d.range.start.line === line && d.severity === 1);
|
|
431
|
-
if (!errorAtLine)
|
|
432
|
-
return null;
|
|
433
|
-
return { message: errorAtLine.message, code: errorAtLine.code };
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Get quick fixes (code actions) for a diagnostic at a position.
|
|
437
|
-
* Returns array of fix descriptions with their edit changes.
|
|
438
|
-
*/
|
|
439
|
-
getCodeFixes(filePath, line, character, errorCodes) {
|
|
440
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
441
|
-
if (!resolved)
|
|
442
|
-
return [];
|
|
443
|
-
const { normalized, position, ls } = resolved;
|
|
444
|
-
const formatOpts = {
|
|
445
|
-
indentSize: 2,
|
|
446
|
-
tabSize: 2,
|
|
447
|
-
newLineCharacter: "\n",
|
|
448
|
-
convertTabsToSpaces: true,
|
|
449
|
-
};
|
|
450
|
-
const fixes = ls.getCodeFixesAtPosition(normalized, position, position, errorCodes, formatOpts, {});
|
|
451
|
-
if (!fixes)
|
|
452
|
-
return [];
|
|
453
|
-
return fixes.map((fix) => ({
|
|
454
|
-
description: fix.description,
|
|
455
|
-
changes: fix.changes?.map((change) => ({
|
|
456
|
-
fileName: change.fileName,
|
|
457
|
-
textChanges: change.textChanges,
|
|
458
|
-
})) || [],
|
|
459
|
-
}));
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Get all quick fixes for all diagnostics in a file.
|
|
463
|
-
* Returns a map of diagnostic line → fixes.
|
|
464
|
-
*/
|
|
465
|
-
getAllCodeFixes(filePath) {
|
|
466
|
-
const fixesByLine = new Map();
|
|
467
|
-
const diagnostics = this.getDiagnostics(filePath);
|
|
468
|
-
for (const diag of diagnostics) {
|
|
469
|
-
if (diag.severity !== 1 || diag.code === undefined)
|
|
470
|
-
continue;
|
|
471
|
-
const fixes = this.getCodeFixes(filePath, diag.range.start.line, diag.range.start.character, [diag.code]);
|
|
472
|
-
if (fixes.length > 0) {
|
|
473
|
-
fixesByLine.set(diag.range.start.line, fixes);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return fixesByLine;
|
|
477
|
-
}
|
|
478
|
-
symbolKind(kind) {
|
|
479
|
-
const map = {
|
|
480
|
-
script: "file",
|
|
481
|
-
class: "class",
|
|
482
|
-
interface: "interface",
|
|
483
|
-
function: "function",
|
|
484
|
-
method: "method",
|
|
485
|
-
property: "property",
|
|
486
|
-
variable: "variable",
|
|
487
|
-
enum: "enum",
|
|
488
|
-
module: "module",
|
|
489
|
-
};
|
|
490
|
-
return map[kind] || "unknown";
|
|
491
|
-
}
|
|
492
|
-
completionKind(kind) {
|
|
493
|
-
const map = {
|
|
494
|
-
property: "property",
|
|
495
|
-
method: "method",
|
|
496
|
-
class: "class",
|
|
497
|
-
interface: "interface",
|
|
498
|
-
enum: "enum",
|
|
499
|
-
variable: "variable",
|
|
500
|
-
function: "function",
|
|
501
|
-
keyword: "keyword",
|
|
502
|
-
};
|
|
503
|
-
return map[kind] || "text";
|
|
504
|
-
}
|
|
505
|
-
}
|
package/commands/rate.test.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { formatRateResult } from "./rate.js";
|
|
3
|
-
// Test the formatting functions directly with mock data
|
|
4
|
-
describe("formatRateResult", () => {
|
|
5
|
-
it("should format a visual score breakdown", () => {
|
|
6
|
-
const result = {
|
|
7
|
-
overall: 75,
|
|
8
|
-
categories: [
|
|
9
|
-
{ name: "Type Safety", score: 85, icon: "🔷", issues: [] },
|
|
10
|
-
{ name: "Complexity", score: 70, icon: "🧩", issues: [] },
|
|
11
|
-
{ name: "Security", score: 100, icon: "🔒", issues: [] },
|
|
12
|
-
{ name: "Architecture", score: 85, icon: "🏗️", issues: [] },
|
|
13
|
-
{ name: "Dead Code", score: 100, icon: "🗑️", issues: [] },
|
|
14
|
-
{ name: "Tests", score: 100, icon: "✅", issues: [] },
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
const output = formatRateResult(result);
|
|
18
|
-
expect(output).toContain("CODE QUALITY SCORE");
|
|
19
|
-
expect(output).toContain("75/100");
|
|
20
|
-
expect(output).toContain("Type Safety");
|
|
21
|
-
expect(output).toContain("Security");
|
|
22
|
-
expect(output).toContain("Tests");
|
|
23
|
-
});
|
|
24
|
-
it("should show correct grade for A", () => {
|
|
25
|
-
const result = {
|
|
26
|
-
overall: 95,
|
|
27
|
-
categories: Array(6).fill({
|
|
28
|
-
name: "Test",
|
|
29
|
-
score: 95,
|
|
30
|
-
icon: "✅",
|
|
31
|
-
issues: [],
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
const output = formatRateResult(result);
|
|
35
|
-
expect(output).toContain("A");
|
|
36
|
-
});
|
|
37
|
-
it("should show correct grade for B", () => {
|
|
38
|
-
const result = {
|
|
39
|
-
overall: 85,
|
|
40
|
-
categories: Array(6).fill({
|
|
41
|
-
name: "Test",
|
|
42
|
-
score: 85,
|
|
43
|
-
icon: "✅",
|
|
44
|
-
issues: [],
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
const output = formatRateResult(result);
|
|
48
|
-
expect(output).toContain("B");
|
|
49
|
-
});
|
|
50
|
-
it("should show correct grade for C", () => {
|
|
51
|
-
const result = {
|
|
52
|
-
overall: 75,
|
|
53
|
-
categories: Array(6).fill({
|
|
54
|
-
name: "Test",
|
|
55
|
-
score: 75,
|
|
56
|
-
icon: "✅",
|
|
57
|
-
issues: [],
|
|
58
|
-
}),
|
|
59
|
-
};
|
|
60
|
-
const output = formatRateResult(result);
|
|
61
|
-
expect(output).toContain("C");
|
|
62
|
-
});
|
|
63
|
-
it("should show issues section when there are problems", () => {
|
|
64
|
-
const result = {
|
|
65
|
-
overall: 50,
|
|
66
|
-
categories: [
|
|
67
|
-
{
|
|
68
|
-
name: "Type Safety",
|
|
69
|
-
score: 50,
|
|
70
|
-
icon: "🔷",
|
|
71
|
-
issues: ["50 untyped identifiers"],
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "Complexity",
|
|
75
|
-
score: 50,
|
|
76
|
-
icon: "🧩",
|
|
77
|
-
issues: ["High complexity: foo.ts"],
|
|
78
|
-
},
|
|
79
|
-
{ name: "Security", score: 100, icon: "🔒", issues: [] },
|
|
80
|
-
{ name: "Architecture", score: 100, icon: "🏗️", issues: [] },
|
|
81
|
-
{ name: "Dead Code", score: 100, icon: "🗑️", issues: [] },
|
|
82
|
-
{ name: "Tests", score: 100, icon: "✅", issues: [] },
|
|
83
|
-
],
|
|
84
|
-
};
|
|
85
|
-
const output = formatRateResult(result);
|
|
86
|
-
expect(output).toContain("Issues to address");
|
|
87
|
-
expect(output).toContain("Type Safety");
|
|
88
|
-
expect(output).toContain("/lens-booboo");
|
|
89
|
-
});
|
|
90
|
-
it("should not show issues section when clean", () => {
|
|
91
|
-
const result = {
|
|
92
|
-
overall: 100,
|
|
93
|
-
categories: Array(6).fill({
|
|
94
|
-
name: "Test",
|
|
95
|
-
score: 100,
|
|
96
|
-
icon: "✅",
|
|
97
|
-
issues: [],
|
|
98
|
-
}),
|
|
99
|
-
};
|
|
100
|
-
const output = formatRateResult(result);
|
|
101
|
-
expect(output).not.toContain("Issues to address");
|
|
102
|
-
});
|
|
103
|
-
it("should use colored bars based on score", () => {
|
|
104
|
-
const resultHigh = {
|
|
105
|
-
overall: 90,
|
|
106
|
-
categories: [{ name: "Test", score: 85, icon: "✅", issues: [] }],
|
|
107
|
-
};
|
|
108
|
-
const resultLow = {
|
|
109
|
-
overall: 50,
|
|
110
|
-
categories: [{ name: "Test", score: 50, icon: "✅", issues: [] }],
|
|
111
|
-
};
|
|
112
|
-
const outputHigh = formatRateResult(resultHigh);
|
|
113
|
-
const outputLow = formatRateResult(resultLow);
|
|
114
|
-
// High score should have green squares
|
|
115
|
-
expect(outputHigh).toContain("🟩");
|
|
116
|
-
// Low score should have red squares
|
|
117
|
-
expect(outputLow).toContain("🟥");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
id: no-dangerously-set-inner-html
|
|
2
|
-
language: TSX
|
|
3
|
-
message: "dangerouslySetInnerHTML can expose XSS vulnerabilities — sanitize with DOMPurify"
|
|
4
|
-
severity: error
|
|
5
|
-
note: |
|
|
6
|
-
dangerouslySetInnerHTML bypasses React's escaping and can introduce
|
|
7
|
-
XSS if the content is user-controlled. Always sanitize with DOMPurify
|
|
8
|
-
or similar library before rendering.
|
|
9
|
-
rule:
|
|
10
|
-
kind: jsx_attribute
|
|
11
|
-
has:
|
|
12
|
-
field: attribute
|
|
13
|
-
regex: "^dangerouslySetInnerHTML$"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
id: no-debugger
|
|
2
|
-
message: Unexpected `debugger` statement.
|
|
3
|
-
severity: error
|
|
4
|
-
language: TypeScript
|
|
5
|
-
rule:
|
|
6
|
-
pattern: debugger
|
|
7
|
-
note: |
|
|
8
|
-
Production code should definitely not contain debugger, as it will cause the browser to stop executing code and open an appropriate debugger.
|
|
9
|
-
|
|
10
|
-
url: https://eslint.org/docs/rules/no-debugger
|
|
11
|
-
|
|
12
|
-
fix: "" # Remove the debugger statement
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
id: no-eval
|
|
2
|
-
language: TypeScript
|
|
3
|
-
message: "Avoid eval() — it can execute arbitrary code and is a security risk"
|
|
4
|
-
severity: error
|
|
5
|
-
note: |
|
|
6
|
-
eval() executes strings as code which can lead to security vulnerabilities
|
|
7
|
-
and performance issues. Use safer alternatives like JSON.parse() for data.
|
|
8
|
-
Grade 3.5 — high risk, critical security issue.
|
|
9
|
-
rule:
|
|
10
|
-
any:
|
|
11
|
-
- pattern: eval($$$ARGS)
|
|
12
|
-
- pattern: window.eval($$$ARGS)
|
|
13
|
-
- pattern: global.eval($$$ARGS)
|