Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
137 lines
3.8 KiB
JavaScript
137 lines
3.8 KiB
JavaScript
import js from '@eslint/js';
|
|
import typescript from '@typescript-eslint/eslint-plugin';
|
|
import typescriptParser from '@typescript-eslint/parser';
|
|
|
|
export default [
|
|
js.configs.recommended,
|
|
{
|
|
ignores: [
|
|
'test/**',
|
|
'dist/**',
|
|
'node_modules/**',
|
|
'coverage/**',
|
|
'*.config.js',
|
|
'*.config.ts',
|
|
],
|
|
},
|
|
// 类型定义文件特殊规则 - 必须放在通用TypeScript规则之前
|
|
{
|
|
files: ['**/*.d.ts'],
|
|
languageOptions: {
|
|
parser: typescriptParser,
|
|
parserOptions: { sourceType: 'module', ecmaVersion: 'latest' },
|
|
},
|
|
plugins: {
|
|
'@typescript-eslint': typescript,
|
|
},
|
|
rules: {
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
'no-unused-vars': 'off',
|
|
},
|
|
},
|
|
// utils目录特殊规则
|
|
{
|
|
files: ['utils/**/*.ts'],
|
|
languageOptions: {
|
|
parser: typescriptParser,
|
|
parserOptions: { sourceType: 'module', ecmaVersion: 'latest'},
|
|
globals: {
|
|
setTimeout: 'readonly',
|
|
clearTimeout: 'readonly',
|
|
},
|
|
},
|
|
plugins: {
|
|
'@typescript-eslint': typescript,
|
|
},
|
|
rules: {
|
|
'@typescript-eslint/no-unused-vars': ['error', {
|
|
argsIgnorePattern: '^_',
|
|
varsIgnorePattern: '^[A-Z_]+$'
|
|
}],
|
|
'no-undef': 'off',
|
|
'no-unused-vars': 'off'
|
|
}
|
|
},
|
|
// 测试文件特殊规则
|
|
{
|
|
files: ['test/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
|
|
languageOptions: {
|
|
parser: typescriptParser,
|
|
parserOptions: { sourceType: 'module', ecmaVersion: 'latest'},
|
|
globals: {
|
|
describe: 'readonly',
|
|
it: 'readonly',
|
|
test: 'readonly',
|
|
expect: 'readonly',
|
|
beforeEach: 'readonly',
|
|
afterEach: 'readonly',
|
|
beforeAll: 'readonly',
|
|
afterAll: 'readonly',
|
|
vi: 'readonly',
|
|
},
|
|
},
|
|
plugins: {
|
|
'@typescript-eslint': typescript,
|
|
},
|
|
rules: {
|
|
'no-unused-vars': 'off',
|
|
// 测试文件中放宽未使用变量的限制
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
'no-unused-vars': 'off',
|
|
// 允许使用any类型
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
// 允许非空断言
|
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
// 允许使用console
|
|
'no-console': 'off',
|
|
// 放宽行长度限制
|
|
'max-len': 'off',
|
|
// 允许尾随逗号
|
|
'comma-dangle': 'off',
|
|
}
|
|
},
|
|
// 通用TypeScript规则
|
|
{
|
|
files: ['**/*.ts', '**/*.tsx'],
|
|
languageOptions: {
|
|
parser: typescriptParser,
|
|
parserOptions: {
|
|
ecmaVersion: 'latest',
|
|
sourceType: 'module',
|
|
},
|
|
},
|
|
plugins: {
|
|
'@typescript-eslint': typescript,
|
|
},
|
|
rules: {
|
|
'no-unused-vars': 'off',
|
|
// TypeScript 规则 - 放宽限制
|
|
'@typescript-eslint/no-unused-vars': ['error', {
|
|
varsIgnorePattern: '^(_|.*[A-Z_]+.*)$',
|
|
argsIgnorePattern: '^_'
|
|
}],
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
'@typescript-eslint/no-explicit-any': 'warn', // 恢复为警告级别
|
|
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
'@typescript-eslint/no-var-requires': 'error',
|
|
|
|
// 通用规则
|
|
'no-console': 'warn',
|
|
'no-debugger': 'error',
|
|
'no-var': 'error',
|
|
'prefer-const': 'error',
|
|
'object-shorthand': 'error',
|
|
'prefer-template': 'error',
|
|
|
|
// 代码风格 - 放宽限制
|
|
'indent': ['error', 2, { SwitchCase: 1 }],
|
|
'quotes': ['error', 'single', { avoidEscape: true }],
|
|
'semi': ['error', 'always'],
|
|
'comma-dangle': ['error', 'never'], // 禁止尾随逗号
|
|
'eol-last': ['warn', 'always'], // 降级为警告
|
|
'no-trailing-spaces': 'warn', // 降级为警告
|
|
'max-len': ['warn', { code: 150, ignoreUrls: true }], // 增加行长度限制
|
|
},
|
|
},
|
|
]; |