根据prettier官方文档Integrating with Linters · Prettier
使用eslint-config-prettier
prettier/eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier. (github.com)
在.eslintrc.json配置:
"extends": ["prettier"]
这样eslint与prettier冲突的规则会被关闭(官网: “extends”: [“prettier”] enables the config from eslint-config-prettier, which turns off some ESLint rules that conflict with Prettier. )
总结
1、安装
yarn add eslint-config-prettier -Dyarn add vue-eslint-parser -Dyarn add prettier -D# 大概要安装以下:yarn add @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-prettier eslint-config-prettier eslint eslint-plugin-vue -D
2、配置.eslintrc.json
"extends": ["prettier"],
完整配置参考:
{"root": true,"env": {"es2021": true,"node": true,"browser": true},"globals": {"node": true},"extends": [// "plugin:vue/essential",/** @see https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#recommended-configs */// "plugin:@typescript-eslint/recommended","eslint:recommended","plugin:vue/vue3-recommended",//避免与 prettier 冲突"plugin:prettier/recommended"],"parser": "vue-eslint-parser","parserOptions": {"parser": "@typescript-eslint/parser","vueFeatures": {// "filter": true,"interpolationAsNonHTML": false,"styleCSSVariableInjection": true}},"plugins": ["@typescript-eslint"],"ignorePatterns": ["types/env.d.ts", "node_modules/**", "**/dist/**"],"rules": {"@typescript-eslint/no-unused-vars": "error","@typescript-eslint/no-var-requires": "off","@typescript-eslint/consistent-type-imports": "error","@typescript-eslint/explicit-module-boundary-types": "off",// "space-before-blocks": "warn",// "space-before-function-paren": "error",// "space-in-parens": "warn",// "no-whitespace-before-property": "off",/*** Having a semicolon helps the optimizer interpret your code correctly.* This avoids rare errors in optimized code.* @see https://twitter.com/alex_kozack/status/1364210394328408066*/"semi": ["error", "always"],/*** This will make the history of changes in the hit a little cleaner*/"comma-dangle": ["warn", "always-multiline"]}}
.editorconfig
root = true[*]charset = utf-8end_of_line = lfindent_size = 2indent_style = spaceinsert_final_newline = trueij_html_quote_style = doublemax_line_length = 120tab_width = 2trim_trailing_whitespace = true[*.sass]indent_size = 2[*.scss]indent_size = 2[*.vue]indent_size = 2tab_width = 2[{*.ats,*.ts}]indent_size = 2tab_width = 2[{*.cjs,*.js}]indent_size = 2tab_width = 2[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}]indent_size = 2[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}]indent_size = 2tab_width = 2
prettier
{"printWidth": 100,"tabWidth": 2,"useTabs": false,"semi": true,"vueIndentScriptAndStyle": true,"singleQuote": true,"quoteProps": "as-needed","bracketSpacing": true,"trailingComma": "es5","jsxBracketSameLine": true,"jsxSingleQuote": false,"arrowParens": "always","insertPragma": false,"requirePragma": false,"proseWrap": "never","htmlWhitespaceSensitivity": "ignore","endOfLine": "lf","rangeStart": 0}
