Open klren0312 opened 1 year ago
安装vue-eslint-parser; 配置parserOptions.tsconfigRootDir为tsconfig.json路径, parserOptions.extraFileExtensions配置['.vue']
vue-eslint-parser
parserOptions.tsconfigRootDir
tsconfig.json
parserOptions.extraFileExtensions
['.vue']
parser: 'vue-eslint-parser', parserOptions: { ecmaVersion: 'latest', sourceType: 'module', parser: '@typescript-eslint/parser', project: ['./tsconfig.json'], tsconfigRootDir: __dirname, extraFileExtensions: ['.vue'] },
module.exports = { env: { browser: true, es2021: true }, extends: [ 'standard-with-typescript', 'plugin:vue/vue3-essential' ], overrides: [ { env: { node: true }, files: [ '.eslintrc.{js,cjs}' ], parserOptions: { sourceType: 'script' } } ], parser: 'vue-eslint-parser', parserOptions: { ecmaVersion: 'latest', sourceType: 'module', parser: '@typescript-eslint/parser', project: ['./tsconfig.json'], tsconfigRootDir: __dirname, extraFileExtensions: ['.vue'] }, plugins: [ 'vue' ], rules: { 'import/no-unresolved': 'off', 'import/extensions': 'off', 'import/no-absolute-path': 'off', 'import/no-extraneous-dependencies': 'off', 'no-console': 'off', '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-empty-function': 'warn', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-floating-promises': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/restrict-plus-operands': 'off', '@typescript-eslint/ban-types': [ 'error', { extendDefaults: true, types: { '{}': false, }, }, ], '@typescript-eslint/no-explicit-any': 'off', 'vue/multi-word-component-names': 'off' // vue组件模板名称 } }
解决方法
安装
vue-eslint-parser
; 配置parserOptions.tsconfigRootDir
为tsconfig.json
路径,parserOptions.extraFileExtensions
配置['.vue']
完整配置