feat: 适配器 i18n + Provider 动态注册 + SetupView 重构 + jars 资源
- 适配器 i18n 接入(eslint/pmd/sql-lint/stylelint) - Provider 动态注册机制(registry.ts + providers.json + factory 重构) - SetupView 全面重构(setupView.ts 新增 600+ 行) - i18n 消息扩展(messages.ts +210 行) - 规则导入流程优化(import-service / prompt-builder) - 新增 PMD jars 依赖及测试用例
This commit is contained in:
+40
-3
@@ -1,8 +1,45 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { ESLint } from 'eslint';
|
||||
import js from '@eslint/js';
|
||||
import ts from 'typescript-eslint';
|
||||
import type { LinterAdapter, AdapterResult, LinterDiagnostic } from './adapter';
|
||||
import { getEslintConfigPath } from '../config';
|
||||
|
||||
const PROJECT_CONFIG_FILES = [
|
||||
'.eslintrc.js',
|
||||
'.eslintrc.json',
|
||||
'.eslintrc.yaml',
|
||||
'.eslintrc.yml',
|
||||
'.eslintrc',
|
||||
'eslint.config.js',
|
||||
'eslint.config.mjs',
|
||||
];
|
||||
|
||||
function findProjectConfig(dir: string): string | null {
|
||||
for (const name of PROJECT_CONFIG_FILES) {
|
||||
const p = path.join(dir, name);
|
||||
if (fs.existsSync(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveEslintConfig(workingDir: string): { configFile?: string; overrideConfig?: any[] } {
|
||||
const globalPath = getEslintConfigPath();
|
||||
if (globalPath && globalPath.trim() !== '') {
|
||||
return { configFile: globalPath };
|
||||
}
|
||||
|
||||
const projectConfig = findProjectConfig(workingDir);
|
||||
if (projectConfig) {
|
||||
return { configFile: projectConfig };
|
||||
}
|
||||
|
||||
return { overrideConfig: ESLintAdapter.getDefaultConfig() };
|
||||
}
|
||||
|
||||
export class ESLintAdapter implements LinterAdapter {
|
||||
id = 'eslint';
|
||||
@@ -10,7 +47,7 @@ export class ESLintAdapter implements LinterAdapter {
|
||||
|
||||
private static defaultConfig: any[] | null = null;
|
||||
|
||||
private static getDefaultConfig(): any[] {
|
||||
public static getDefaultConfig(): any[] {
|
||||
if (!ESLintAdapter.defaultConfig) {
|
||||
ESLintAdapter.defaultConfig = [
|
||||
js.configs.recommended,
|
||||
@@ -26,10 +63,10 @@ export class ESLintAdapter implements LinterAdapter {
|
||||
|
||||
async check(document: vscode.TextDocument, workingDir: string): Promise<AdapterResult> {
|
||||
try {
|
||||
const resolved = resolveEslintConfig(workingDir);
|
||||
const engine = new ESLint({
|
||||
cwd: workingDir,
|
||||
overrideConfigFile: true,
|
||||
overrideConfig: ESLintAdapter.getDefaultConfig(),
|
||||
...resolved,
|
||||
});
|
||||
const ext = document.languageId === 'typescript' ? 'ts' : 'js';
|
||||
const isVirtual = document.uri.scheme === 'untitled';
|
||||
|
||||
Reference in New Issue
Block a user