The Airbnb Style Guide is one of the most popular. It is also very well formatted and easy to read.
The style guides we mentioned above are full of really helpful advice for formatting, organizing and composing your code. But there are a lot of rules – it can be difficult to internalize them all. Linters are tools that will scan your code with a set of style rules and will report any errors to you that they find. In some cases, they can even auto-fix the errors! The following articles explain in more detail the benefits of using a linter while you code.
- This article gets right to the point… start here!
- This article goes a little further by discussing exactly how linters do what they do.
The official ‘Getting Started’ page is a good place to start. It covers installation and basic setup. The basic way to use this tool is to simply run the
eslintcommand in your terminal with a specific file.
Far more useful are linting plugins for your favorite text editor. Most editor plugins allow you to automatically lint your code as you are writing it, and will show the errors right in the editor, which makes resolving them much simpler.
Prettier is awesome. It is similar to a linter, but serves a slightly different function. Prettier will take your JS code and then automatically format it according to a set of rules. Unlike a linter, it’s not looking for style errors, but specifically targeting the layout of your code and making intelligent decisions about things like spaces, indentation levels and line-breaks.
This quick talk from prettier’s creator is a great introduction.
Setup is simple. The homepage links to tutorials for most popular editors.
Using prettier makes coding faster and easier! You don’t have to worry about nailing things like indentation, or remembering every semi-colon because prettier will take care of those details for you
- Is there anything we can help with up to this point? Do you have something to suggest about this chapter? Let us know in the comments below.