![]() Prettier does it his own opinionated way. This will for example break up lines that are too long, which is something all code-formatters do. Prettier uses a "print-width" setting (see Prettier options) to make sure lines end somewhere around the same character. This is somewhat true for all formatters, but no other is that intrusive and adds like 15 newlines for three lines of code (see next point)! ![]() You are writing three lines of code, hit your auto-format hotkey and suddenly are completely lost, because the file got completely reformatted. It's easy to lose track where you have been in the code. Problem: removing mindfully set linebreaksįor me, the most annoying thing Prettier does is combining your lines, removing linebreaks you intentionally added for increased readability - let's say you always want Accessibility tags in a second line -> impossible to do with Prettier! If both lines combined fit within the "print-width" it will collapse them into a single line, no matter what you want! If you want the freedom to decide yourself how your code looks better use another formatter. I am not saying it's all bad, but their vision might not be for you. Prettier could have solved all that with configurations and really be the one formatter everyone uses, but sadly (imo) instead of wanting to be the one formatter they want to be the one code style. Second, people use different languages and Prettier's opinion clearly works better on some (like Java/JavaScript) than others (like HTML). ![]() First, people are different and want to use different styling. I personally don't think that this is even desirable. They are lacking configuration-options and they will probably never add them, since it's against their options philosophy of wanting to "stop all the ongoing debates over styles", which can only happen if every single developer accepts the same styling. The problem with Prettier is that they bluntly force their opinion on you and give you no options to turn off the things that bother you. Just discuss it and give everyone a chance to be heard and you will have more happy developers. It's an opinionated code formatter and ensures consistency (which is a good thing), but it might go a bit too far.Ĭode-Style is opinionated and I strongly believe the best code-style is the style your team or organization agrees on. I would use EditorConfig (file ~/.editorconfig) and ESLint, but avoid Prettier. Feross Aboukhadijeh: Write Perfect Code With Standard And ESLint - JSConf.Asia 2018Īlso look at the React framework's repository:.Useful sources for who want to dive into: Especially if you are working with a team. I also agree with KevinBrownTech to use three of them.They have some common features in order to do the same things.Prettier updates your code with your rules to reshape your code.EditorConfig changes your editor settings.When you press TAB, it leaves four spaces.ĮSLint statically analyzes your code to quickly find problems.It applies your rules before writing code.on save with the Visual Studio Code editorĮditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.It changes your code after writing your code.It removes all original styling and ensures that all outputted code conforms to a consistent style. So while its role diminishes somewhat compared to the days before prettier, it's still useful to have in a project to catch the other errors. It picks up when you declare variables you don't use, or reference things that aren't defined, amongst a few other niceties. I like to set it up to do this when I stage my files for a commit, so that it's physically impossible for me to commit code that doesn't match my style guide.ĮSLint: So why would you want a linter too? Because ESLint does more than just style. Prettier: Automatically formats your code. Of course if you've set up prettier it'll fix it before it goes into your code base, but still, why would you want to look at it in one format while you're writing it and then have it switch when you go to commit? Might as well be consistent. ![]() Otherwise if you don't have EditorConfig, as you're typing your editor will auto-format differently to the rest of the code base, which is confusing. While this isn't strictly necessary in order to achieve your goals, it's nice if you're always looking at code that follows the same coding styles. In my experience, the best combination is all 3, and here's why:ĮditorConfig: This helps your editor produce code that looks like your style guide as you go. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |