vue 项目 eslint + prettier 配置

prettier 官方有三个跟 eslint 相集成的工具:

https://prettier.io/docs/en/integrating-with-linters.html

它们的具体区别见:https://gist.github.com/savokiss/e5e585f30d3c775a07c45f53fcb6ca06

不过目前已经不推荐使用 prettier-eslint 了(并且 Vetur 有一个相关 bug,在 VS Code 下也无法格式化代码),推荐 eslint-plugin-prettier 与 eslint-config-prettier 一起使用。

首先安装相应的包:

yarn add prettier eslint-plugin-pretter eslint-config-prettier -D

然后再 .eslintrc.js 配置文件中配置:

{
  "extends": ["plugin:prettier/recommended"]
}

大功告成,然后 eslint --fix 就会自动修复你的代码。

注意:这种方式实际上是向 prettier 妥协,因为格式化相关的规则都被关闭并且交给 prettier 处理。

原文地址:https://www.cnblogs.com/savokiss/p/14797080.html