

jsbeautifyrc in your project’s directory.įor example, here’s what we’re using: #. Luckily, it wasn’t a problem - both prettier and js-beautify can be easily setup by having a simple. We really wanted that introducing the automatic code formatters wouldn’t change our existing style of writing code. We didn’t want to change it, as many devs got used to it already. Step 2.: Configure the formattersĪ lot of folks might just go with the default settings, if they don’t care about the code style that much.įor us, that wasn’t the case though. less files, and js-beautify for Angular’s. (It can also format JS and CSS as well, but I prefer Prettier’s way of doing that, IMO it’s a bit better at those syntaxes.)īecause of those reasons, we‘ve decided to go with both of them. Luckily there’s js-beautify, which is handling those alternate HTML syntaxes without troubles. If you’re using frameworks like Vue or Angular, you might want to switch to something else for it.

Prettier also does support HTML, but right now its’ support is quite experimental. It is stable since long and has solid support for language syntaxes like JS, JSX, TypeScript, JSON, CSS, LESS, SCSS, GraphQL (with more languages like SQL, Java, PHP, Python, Ruby on its’ way). When it comes to frontend web development, most of the folks are using Prettier now. Unless you’re the only developer in your company, or you all are working with the same IDE configurations, you’ll want to standardise it. The problem is, very often each one of them has its’ own implementation and configuration of the formatter. Many of the current IDEs already have auto formatting built in (VSCode, Atom, WebStorm). To help you with each of the steps, I’ve decided to break down each of them and describe it, on our own example, where we managed to setup Prettier and HTML Beautifier for all of our files, together with git and CI hooks. (optionally) setup CI hooks, so it will fail if somebody manages to push badly formatted code.Īnd that’s it! If you complete in all of the steps above, your code will be clean and readable forever. (optionally) setup git precommit hooks, so it will be impossible to push badly formatted code,ĥ.

(optionally) format your existing codebase by running one CLI command,Ĥ. configure your IDE, so it formats your code automatically every time you save a file,ģ. Prettier) and setup a common config for it,Ģ. In addition, setting up all of it for your whole codebase will take you just about 5 to 15 minutes. Because even if it just means tidying up your spaces, it also means this: your code will be much clearer, and you’ll have more time to focus on your code, not anything else.

