Files
leaser_front/.eslintrc.js
T

130 lines
3.7 KiB
JavaScript
Raw Normal View History

2025-06-22 23:55:55 +08:00
const path = require('path');
module.exports = {
root: true,
env: {
'browser': true,
'node': true,
2025-10-12 15:08:29 +08:00
'es2021': true,
2025-06-22 23:55:55 +08:00
'vue/setup-compiler-macros': true,
},
2025-10-12 15:08:29 +08:00
// 1. 主解析器始终是 'vue-eslint-parser'
parser: 'vue-eslint-parser',
parserOptions: {
// 2. 在顶层 parserOptions 中指定 TS 解析器和 JSX 支持
parser: '@typescript-eslint/parser',
ecmaVersion: 'latest', // 使用 'latest' 更稳妥
sourceType: 'module',
ecmaFeatures: {
jsx: true, // 关键:开启 JSX 支持
},
extraFileExtensions: ['.vue'],
project: path.resolve(__dirname, './tsconfig.json'),
},
2025-06-22 23:55:55 +08:00
extends: [
2025-10-12 15:08:29 +08:00
'plugin:vue/vue3-recommended',
2025-06-22 23:55:55 +08:00
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:prettier/recommended',
],
2025-10-12 15:08:29 +08:00
plugins: ['vue', '@typescript-eslint', 'import', 'prettier'],
2025-06-22 23:55:55 +08:00
rules: {
2025-10-12 15:08:29 +08:00
// 你的规则保持不变
'no-param-reassign': 0,
'no-plusplus': 0,
2025-06-22 23:55:55 +08:00
'prettier/prettier': 1,
2025-10-12 15:08:29 +08:00
'no-console': process.env.NODE_ENV === 'production' ? 2 : 1,
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'no-unused-expressions': 'off',
'vue/multi-word-component-names': 0,
2025-06-22 23:55:55 +08:00
'vue/require-default-prop': 0,
'vue/singleline-html-element-content-newline': 0,
'vue/max-attributes-per-line': 0,
2025-10-12 15:08:29 +08:00
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/ban-types': 'off',
'import/no-unresolved': [2, { ignore: ['^@/'] }],
2025-06-22 23:55:55 +08:00
'import/extensions': [
2025-10-12 15:08:29 +08:00
'error',
2025-06-22 23:55:55 +08:00
'ignorePackages',
{
js: 'never',
ts: 'never',
tsx: 'never',
2025-10-12 15:08:29 +08:00
vue: 'off',
2025-06-22 23:55:55 +08:00
},
],
},
2025-10-12 15:08:29 +08:00
overrides: [
// 3. 为 .vue 文件提供更具体的解析器选项(如果需要)
{
files: ['*.vue'],
rules: {
// 在这里可以覆盖一些只针对 .vue 文件的规则
// 例如,vue-eslint-parser 已经处理了未使用的变量,所以可以关闭 TS 的检查
'@typescript-eslint/no-unused-vars': 'off',
},
},
// 4. 为 .tsx 文件单独配置(推荐)
{
files: ['*.tsx'],
parser: '@typescript-eslint/parser', // 直接使用 TS 解析器
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
project: path.resolve(__dirname, './tsconfig.json'),
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
},
// d.ts 文件配置保持不变
{
files: ['**/*.d.ts'],
parserOptions: { project: undefined },
rules: {
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/ban-types': 'off',
},
},
{
files: ['*.config.ts', '*.config.js'], // 匹配所有 .config.ts 和 .config.js 文件
parserOptions: {
project: undefined, // 关键:告诉 ESLint 这个文件不需要关联 TS 项目配置
},
rules: {
// 在这里可以关闭一些对配置文件不适用的规则
'import/no-named-as-default': 'off', // 例如,这个规则在配置文件中很常见
},
},
],
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: path.resolve(__dirname, './tsconfig.json'),
},
node: {
extensions: ['.js', '.ts', '.tsx', '.vue'],
},
},
},
ignorePatterns: ['.eslintrc.js', 'node_modules', 'dist', '*.config.js'],
2025-06-22 23:55:55 +08:00
};