解决Vue项目中ESLint和Prettier冲突问题[Vue.js项目实践: 新冠自检系统]

Logo

新冠疫情自我检测系统网页设计开发文档

Sylvan Ding 的第一个基于 Vue.js 的项目. 本项目所提供的信息,只供参考之用,不保证信息的准确性、有效性、及时性和完整性,更多内容请查看国家卫健委网站!
Explore the docs »

View Demo · Report Bug · Request Feature

homepage

解决Vue项目中ESLint和Prettier冲突问题

You will need to install the appropriate extension/plugin for your code editor. For VS Code, install ESLint and Prettier. These plugins have millions of downloads each, so it’ll be difficult to miss them in the VS Code extension marketplace. Once you’ve installed these, we are ready to move on to configuring each of them for proper usage.

Linters usually contain not only code quality rules, but also stylistic rules. Most stylistic rules are unnecessary when using Prettier, but worse – they might conflict with Prettier!

Luckily it’s easy to turn off rules that conflict or are unnecessary with Prettier. Package eslint-config-prettier can exclude all ESLint rules that could conflict with Prettier.

开发环境

node14.16.1
npm8.18.0
vue-cli2.9.6
vue2.5.2

解决方案

Install eslint-config-prettier:

npm install eslint-config-prettier --save-dev --legacy-peer-deps

You may meet upstream dependency conflict when installing NPM packages with the latest npm version (v8). The effective solution to this error is to pass a command --legacy-peer-deps to the npm install that can help ignore the peer dependencies and continue the installation.

Once the setup is successful, you should see a file eslintrc.js based on the format you chose your configuration file to be in.

Then, add "prettier" to the “extends” array in your .eslintrc.js file. Make sure to put it last, so it gets the chance to override other configs.

{
  "extends": [
    "some-other-config-you-use",
    "prettier"
  ]
}

Create .prettierrc file written in JSON as configuration file for Prettier:

{
  "arrowParens": "always",
  "bracketSameLine": false,
  "bracketSpacing": true,
  "embeddedLanguageFormatting": "auto",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": false,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false
}

转载请注明出处:©️ Sylvan Ding 2022

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值