非 eslint参考 https://segmentfault.com/a/1190000041954694
网上很多配置都是使用 @babel/eslint-parser,而使用 vite 的时候是没有 babel的配置的,这样就无法使用.
eslint-parser 这个不能按原文章安装。
参照:
https://stackoverflow.com/questions/70083042/eslint-parsing-error-unexpected-token
vue ts 报错 vite es-lint Parsing error: Unexpected token )eslint
安装 parse ts
yarn add -D @typescript-eslint/parser
yarn add -D @typescript-eslint/eslint-plugin
修改 .eslintrc文件
parserOptions: {
...
parser: '@typescript-eslint/parser'
}
eslint 8.56版本以上
因eslint 8.56后,弃用了 .eslintrc 文件,改成了 eslint.config.js
import tsParser from '@typescript-eslint/parser';
export default[
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures:{modules: true},
ecmaVersion: 'latest',
parser: '@typescript-eslint/parser'
},
}
{
rules: {
//...
}
}
]
附上自用简单 eslint.config.js
import globals from 'globals'
import pluginJs from '@eslint/js'
import tseslint from 'typescript-eslint'
import pluginVue from 'eslint-plugin-vue'
import tsParser from '@typescript-eslint/parser'
export default [
{
languageOptions: {
globals: globals.browser,
parser: tsParser,
parserOptions: {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
parser: '@typescript-eslint/parser'
}
}
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs['flat/essential'],
{
rules: {
'vue/multi-word-component-names': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'no-unsafe-optional-chaining': ['warn'],
'vue/valid-v-for': ['off']
}
}
]
文章评论