Why to use JavaScript Standard Style?
Miguel ángel Durán García
Programación JavaScript y Desarrollo Web. Reconocido Google Developer Expert, Microsoft MVP y GitHub Star. ?
Last years we have seen an increased presence of code linters on development teams. Speaking especially about Javascript we have some great: ESLint, jshint and jscs. All of them offers a great flexibility in order to determine what they should check. While those are great for checking code quality and follow coding rules there's always a point of discussion about them. Which is the best style to follow?
Personally, I like very much the preset system of jscs. One of my favourites presets is the one based on the Airbnb Javascript Style Guide (https://github.com/airbnb/javascript). However, it's open to debate if that's style is good enough and fits on your organization needs, if the style to follow is the better suitable and if your coworkers are used to code in other way.
Opinions are like assholes. Everybody's got one and everyone thinks everyone else's stinks.
Lately, a new Style Guide for Javascript become popular on some GitHub projects: Standard JS. It has a very different approach as the tools before as Standard JS offers a guide to follow as it is. No configuration, no discussion. It uses ESLint under the hood but it lacks configuration in order to modify rules. You only have to follow them.
One style to rule them all.
2 spaces indentation, space after keywords, single quotes for strings, always use === instead ==, whitespace after comma, follow indentation... You can see a good summary of the rules on GitHub.
One of the most not-welcomed-by-everyone rule is the lack of semicolons. I personally had always an internal debate about this but after using CoffeeScript for a while I have to say that I'm fine with that. In fact, I don't miss them although there's debate about some exceptions when those are needed but Standard prevents you to do that. Well I'm no one to tell you if semicolons are good or evil, there's plenty of articles out there talking about that already.
Also there's packages for Atom, Sublime Text, VIM, Visual Code and more in order to install it and be ready to use Standard JS. So, why do am I using it for my projects and Hubii?
- Zero configuration. While you can use it in your project as a dependency to check syntax, it's better to just install the package on your favourte editor and code.
- I pretty agree with almost all the rules. I tend to find almost all rules well documented and with good reasons.
- Bye, bye coworkers discussions. It's a good standard to follow as you don't need to discuss if some rule is better than other. It's just a standard, it's at it is.
- Catch style errors before they're submitted in PRs. Saves precious code review time by eliminating back-and-forth between maintainer and contributor.
So, I think that adopting Standard Style means focus on the importance of code, good community support and to not impose a personal and subjective style hover others. That might be hard sometimes because, I've cited before, opinions are like assholes and using Standard JS might be one as well.
What do you think about Javascript Standard Style? Do you agree or disagree with that package and why?