feat: implement core code review extension
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { ESLint } from 'eslint';
|
||||
import type { LinterAdapter, AdapterResult, LinterDiagnostic } from './adapter';
|
||||
|
||||
export class ESLintAdapter implements LinterAdapter {
|
||||
id = 'eslint';
|
||||
supportedLanguages = ['javascript', 'typescript'];
|
||||
|
||||
isAvailable(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
async check(document: vscode.TextDocument, workingDir: string): Promise<AdapterResult> {
|
||||
try {
|
||||
const engine = new ESLint({ cwd: workingDir });
|
||||
const results = await engine.lintText(document.getText(), {
|
||||
filePath: document.fileName || 'untitled.ts',
|
||||
});
|
||||
|
||||
const diagnostics: LinterDiagnostic[] = [];
|
||||
for (const result of results) {
|
||||
for (const msg of result.messages) {
|
||||
if (msg.ruleId === null) { continue; }
|
||||
|
||||
diagnostics.push({
|
||||
severity: msg.severity === 2 ? 'error' : 'warning',
|
||||
ruleId: `eslint:${msg.ruleId}`,
|
||||
message: msg.message,
|
||||
range: new vscode.Range(
|
||||
msg.line - 1,
|
||||
msg.column - 1,
|
||||
(msg.endLine ?? msg.line) - 1,
|
||||
(msg.endColumn ?? msg.column) - 1
|
||||
),
|
||||
suggestion: msg.fix?.text,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { diagnostics, status: 'ok' };
|
||||
} catch (error) {
|
||||
return {
|
||||
diagnostics: [],
|
||||
status: 'execution-failed',
|
||||
errorMessage: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user