简体   繁体   English

根据eslint配置,在原子编辑器中美化js代码

[英]Beautify js code in atom editor on save according to eslint configuration

I am using Atom as my code editor of choice and am finding it hard to implement functionality to beautify code. 我使用Atom作为我选择的代码编辑器,并发现很难实现美化代码的功能。 I am relying quite heavily on eslint package and just got beautify to clean up my code on save. 我非常依赖eslint包,只是美化来清理我的代码。 issue is that once code is beautified it results in some minor eslint errors and I am looking for a way to either set up beautify plugin in a way that respects eslint rules or use something else that does the job. 问题是,一旦代码被美化,它会导致一些小的eslint错误,我正在寻找一种方法来设置美化插件,以尊重eslint规则或使用其他工作。

You may want to use an Atom plugin called Prettier Eslint that formats code according to eslint config file ( .eslintrc ). 您可能希望使用名为Prettier Eslint的Atom插件,该插件根据eslint配置文件( .eslintrc )格式化代码。 It uses eslint's --fix flag to fix issues. 它使用eslint的--fix标志来修复问题。

Edit: Looks like its Prettier-atom now. 编辑:现在看起来像它的Prettier-atom Thanks, @dube. 谢谢,@ dube。

It sounds like your beautify settings aren't matched up with your eslint rules. 听起来你的beautify设置与你的eslint规则不匹配。 For example, the eslint indent rule might be set to 4 while beautify indent is set to 2 . 例如, eslint indent规则可能设置为4beautify indent设置为2

The beautify plugin has some settings to customize how it beautifies your code. beautify插件有一些设置来自定义它如何美化你的代码。 You can read about those settings in the docs . 您可以在文档中阅读有关这些设置的信息 Unfortunately there's only 17 settings so it might not be possible to sync the 2 packages. 不幸的是,只有17个设置,因此可能无法同步2个软件包。

If you find you need more control over the auto-formatting in Atom you might want to check out the ESFormatter package. 如果您发现需要更多地控制Atom中的自动格式化,您可能需要查看ESFormatter包。 It has more than 250 options, which might suit your needs better if you have some non-standard ESLint rules. 它有250多个选项,如果您有一些非标准的ESLint规则,它们可能更适合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM