扩展检查应用:
vue2 使用 Vetur
,vue3使用 Volar
安装:
"eslint": "^8.15.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-vue": "^8.7.1",
"typescript": "^4.6.4",
"vue-tsc": "^0.34.15"
eslint配置
module.exports = {
root: true,
env: {
browser: true,
node: true,
es6: true,
commonjs: true,
amd: true
},
// ts eslint 配置
parserOptions: {
parser:'@typescript-eslint/parser',
},
plugins: ['@typescript-eslint'],
extends: ['plugin:vue/vue3-recommended','plugin:prettier/recommended','prettier/@typescript-eslint','plugin:@typescript-eslint/recommended'],
// js eslint 配置
// parserOptions: {
// parser: 'babel-eslint',
// sourceType: 'module'
// },
// plugins: ['html', 'vue'],
// extends: ['plugin:vue/recommended', 'eslint:recommended'],
rules: {
'max-len': 'off',
// 统一豁免规则,原因:直接修改可能对现有功能产生影响
'eqeqeq': 1,
// 'vue/no-v-html': 1,
// 其中代码本身有问题的规则错误有
'no-undef': 0,
'import/no-duplicates': 0,
// 可能引起格式化问题但建议手动修改代码的有
'no-plusplus': 0,
'no-eval': 0,
'no-prototype-builtins': 0,
'no-multi-assign': 0,
'no-unused-vars': 0,
'no-useless-escape': 0,
'camelcase': 0,
'vue/no-unused-components': 0,
'vue/return-in-computed-property': 0,
'no-param-reassign': 0,
'prefer-const': 0,
'prefer-destructuring': 0,
'no-underscore-dangle': 0,
'no-restricted-syntax': 0,
'no-nested-ternary': 0,
'radix': 0,
'vue/no-side-effects-in-computed-properties': 0,
'vue/order-in-components': 0,
'function-paren-newline': 0,
},
};
tsconfig.json
{
"include": [
"src/*.ts",
"src/**/*.ts",
"src/**/*.vue"
],
"exclude": [
"node_modules"
],
"compileOnSave": true,
// 编译选项
"compilerOptions": {
// 输出目录
"outDir": "./output",
// 是否包含可以用于 debug 的 sourceMap
"sourceMap": true,
// 解决template标签飘蓝
"jsx": "preserve",
// 定义this
"noImplicitThis": false,
// 以严格模式解析
"strict": true,
// 编译输出目标 ES 版本
"target": "es5",
// 编译过程中需要引入的库文件的列表
"lib": ["es2015", "es2017", "ESNext", "dom"],
// 采用的模块系统
"module": "esnext",
// 如何处理模块
"moduleResolution": "node",
// 无需要设定默认值
"strictPropertyInitialization": false,
// 允许从没有设置默认导出的模块中默认导入
"allowSyntheticDefaultImports": true,
// 将每个文件作为单独的模块
"isolatedModules": true,
// 允许从没有设置默认导出的模块中默认导入
"esModuleInterop": true,
"useDefineForClassFields": true,
"resolveJsonModule": true,
// 启用装饰器
"experimentalDecorators": true,
// 启用设计类型元数据(用于反射)
"emitDecoratorMetadata": true,
// 在表达式和声明上有隐含的any类型时报错
"noImplicitAny": false,
// 不是函数的所有返回路径都有返回值时报错。
"noImplicitReturns": true,
// 从 tslib 导入外部帮助库: 比如__extends,__rest等
"importHelpers": true,
// 编译过程中打印文件名
"listFiles": true,
// 移除注释
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
// 是否允许编译javascript文件
"allowJs": false,
// 是否允许跳过检查
"skipLibCheck": true,
"pretty": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"noUnusedParameters": false,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
// 解析非相对模块名的基准目录
"baseUrl": "./",
// 指定特殊模块的路径
"paths": {
"@/*": ["src/*"], // 这里 只建议使用 @/ 使用其他的别名可能不会生效
},
},
"references": [{ "path": "./tsconfig.node.json" }]
}