如何在 Vue 项目中同时检查 .vue 和 .ts?

对于 Vue 项目配置 ts 通常是以下配置

{

"root": true,

"env": { "es6": true, "browser": true, "node": true },

"extends": [

"plugin:vue/vue3-recommended",

"plugin:@typescript-eslint/recommended",

"custom"

],

"parser": "vue-eslint-parser",

"parserOptions": {

"sourceType": "module",

"parser": "@typescript-eslint/parser",

"ecmaVersion": 2020

},

"plugins": ["simple-import-sort"],

"rules": {

"simple-import-sort/imports": "error",

"simple-import-sort/exports": "error"

}

}

但这里有个问题,parser 是负责将 .vue 里的源代码(sourcecode)编译成 Vue AST,然后在转换成 ESLint AST,从而使 ESLint 能够校验 .vue 里的错误,而且在 eslint-plugin-vue 文档里说,如果要使 .vue 里的 <script setup lant="ts"> 也能接受 ts 的检查就需要加上下面的句子

{

"parser": "vue-eslint-parser",

"parserOptions": {

"sourceType": "module",

"parser": "@typescript-eslint/parser",

},

}

可是,通常 Vue 项目里也有 .ts 文件的存在,失去了 @typescript-eslint/parser,项目的 ESLint 是怎么对 .ts 做校验和检查的呢?

难道是 vue-eslint-parser 同时支持 .vue.tsAST 转换?

以上是 如何在 Vue 项目中同时检查 .vue 和 .ts? 的全部内容, 来源链接: utcz.com/p/933674.html

回到顶部