130 lines
3.7 KiB
JavaScript
130 lines
3.7 KiB
JavaScript
const path = require('path');
|
|
|
|
module.exports = {
|
|
root: true,
|
|
env: {
|
|
'browser': true,
|
|
'node': true,
|
|
'es2021': true,
|
|
'vue/setup-compiler-macros': true,
|
|
},
|
|
// 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'),
|
|
},
|
|
extends: [
|
|
'plugin:vue/vue3-recommended',
|
|
'plugin:@typescript-eslint/recommended',
|
|
'plugin:import/recommended',
|
|
'plugin:import/typescript',
|
|
'plugin:prettier/recommended',
|
|
],
|
|
plugins: ['vue', '@typescript-eslint', 'import', 'prettier'],
|
|
rules: {
|
|
// 你的规则保持不变
|
|
'no-param-reassign': 0,
|
|
'no-plusplus': 0,
|
|
'prettier/prettier': 1,
|
|
'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,
|
|
'vue/require-default-prop': 0,
|
|
'vue/singleline-html-element-content-newline': 0,
|
|
'vue/max-attributes-per-line': 0,
|
|
|
|
'@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: ['^@/'] }],
|
|
'import/extensions': [
|
|
'error',
|
|
'ignorePackages',
|
|
{
|
|
js: 'never',
|
|
ts: 'never',
|
|
tsx: 'never',
|
|
vue: 'off',
|
|
},
|
|
],
|
|
},
|
|
|
|
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'],
|
|
};
|