更漂亮+ Airbnb的ESLint配置 [英] Prettier + Airbnb's ESLint config

查看:444
本文介绍了更漂亮+ Airbnb的ESLint配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始在我的编辑器中使用Visual Studio Code,并找到了Prettier - JavaScript格式化程序。我认为这是一个很棒的插件,因为它可以帮助我保持代码看起来不错。

Recently, I've started using Visual Studio Code for my editor and found the Prettier - JavaScript formatter. I think it's a great plugin because it helps me keep my code looking nice.

我设置了Airbnb的ESLint配置并发现它非常有用。

I set up Airbnb's ESLint config and have found that to be super helpful.

这是捕获。我正在运行的Airbnb ESLint配置与Prettier不太搭配。例如,对于JavaScript字符串,Prettier被格式化为包含双重刻度和Airbnb的ESLint,如单个刻度。当我使用Prettier格式化代码时,Airbnb的ESLint不同意。

Here's the catch. The Airbnb ESLint config I'm currently running doesn't play nice with Prettier. For example, for JavaScript string, Prettier is formatted to include double ticks and Airbnb's ESLint like single ticks. When I format the code using Prettier, then Airbnb's ESLint doesn't agree.

我知道Kent Dodds已经完成了ESLint配置的一些工作,其中包括这里的例子。

I know Kent Dodds has done some work with ESLint configs, among others, example here.

但我不能似乎找到了一个解决方案,让我使用Prettier的魔力将我的代码格式化为Airbnb的ESLint。

But I can't seem to find a solution that lets me use the magic of Prettier to format my code to Airbnb's ESLint.

推荐答案

我认为 eslint-config-prettier https://prettier.io/docs/en/eslint.html#turn-off-eslint-s-formatting-rules

基本上关闭所有规则这与代码样式有关,因为更漂亮的无论如何都会照顾它。

Basically it turns off all rules that have to do with code styling because prettier will take care of it anyway.

所以你只需要安装这个插件以及任何其他所需的eslint插件(如 eslint-config-airbnb ),在您的eslint配置中,您只需将其添加到 extends 字段。例如:

So you just install this plugin along with any other desired eslint plugin (like eslint-config-airbnb) and in your eslint config you just add it to the extends field. For example:

{
  "extends": ["airbnb", "prettier"]
}

这篇关于更漂亮+ Airbnb的ESLint配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆