在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Tslint配置主要配置文件如下: // tsconfig.json { "compilerOptions": { "target": "esnext", "module": "esnext", "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", "types": [ "webpack-env", "jest" ], "paths": { "@/*": [ "src/*" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src/**/*.ts", "src/**/*.js", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules", "src/assets/json/*.json" ] } // tslint.json { "defaultSeverity": "warning", "extends": [ "tslint:recommended" ], "linterOptions": { "exclude": [ "node_modules/**", "src/assets/json/*.json" ] }, "rules": { "quotemark": [true, "single"], "indent": [true, "spaces", 2], "interface-name": false, "ordered-imports": false, "object-literal-sort-keys": false, "no-consecutive-blank-lines": false, "semicolon": [true, "never"], "member-access": false, "no-console": false, "max-line-length": [ false ] } } Eslint配置文件如下: // .eslintrc.js // https://repo.advai.net/advgit/atome-fe/docs/-/blob/1667c9156ed5fa16584e510c550b5ec0f95ad627/standard/.eslintrc.js module.exports = { root: true, env: { browser: true, node: true, es6: true, }, parser: 'vue-eslint-parser', extends: [ 'plugin:vue/recommended', 'plugin:prettier/recommended', 'prettier/@typescript-eslint', 'plugin:@typescript-eslint/recommended', ], plugins: ['@typescript-eslint'], parserOptions: { parser: '@typescript-eslint/parser', }, rules: { 'prettier/prettier': 'error', 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'array-bracket-spacing': 2, 'no-var': 2, 'no-eval': 2, 'arrow-spacing': 2, 'block-spacing': 2, 'key-spacing': 2, 'brace-style': 2, 'vue/camelcase': 2, 'vue/require-component-is': 0, 'vue/require-default-prop': 0, 'comma-dangle': [2, 'always-multiline'], 'vue/eqeqeq': [2, 'always', { null: 'ignore' }], 'object-curly-spacing': [2, 'always'], 'vue/singleline-html-element-content-newline': 0, 'vue/html-closing-bracket-newline': [ 2, { singleline: 'never', multiline: 'always', }, ], 'vue/max-attributes-per-line': 0, 'vue/html-self-closing': [ 2, { html: { void: 'always', normal: 'never', component: 'always', }, svg: 'always', math: 'always', }, ], // 设置 typescript-eslint 规则 // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules '@typescript-eslint/camelcase': 0, // 目前埋点有部分字段无法更换 '@typescript-eslint/no-non-null-assertion': 0, // 允许非空断言运算符 '@typescript-eslint/member-delimiter-style': [ 2, { multiline: { delimiter: 'none', requireLast: true, }, singleline: { delimiter: 'semi', requireLast: false, }, }, ], '@typescript-eslint/no-unused-vars': [0, { args: 'none' }], // TODO 后期逐步替换 '@typescript-eslint/interface-name-prefix': 0, '@typescript-eslint/explicit-function-return-type': 0, '@typescript-eslint/no-empty-function': 0, '@typescript-eslint/no-var-requires': 0, '@typescript-eslint/no-use-before-define': 0, '@typescript-eslint/no-explicit-any': 0, // TODO }, }
另附参考内容(若侵权请联系本人删除)供大家学习参考:
二、安装 eslint-plugin-vue
然后在
三、安装 prettierprettier 用来做格式化工具配合我们的 ESLint 可以更大的发挥作用,首先安装相关依赖:
接着按需配置 prettier,新建 .prettierrc 文件
到这里 ESLint 和 prettier 相关配置已经完成,接下来我们利用一些工具帮我们在 git commit 阶段完成代码格式化和校验工作。 使用 husky 和 lint-staged 钩子完成校验与格式化五、Vscode 相关配置
总结通过以上几步我们可以在
另外各种插件因为版本问题导致的冲突一般都可以在对应插件的 |
请发表评论