ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

ES6 AirBnb Style Guidelines and Semicolons


#1

From https://gitter.im/airbnb/javascript
September 3, 2015

justin808: Any advice on using the methods in lodash versus built-ins, such as map on Array?
I tend to always use lodash so as not to remember what JS has built-in, but maybe that’s not optimal?

goatslacker: lodash methods were faster than native methods last time I checked because they’re not spec compliant.
if you have something like lodash I guess it’s best to use it rather than not

justin808: I like that for consistency, simply using lodash.
@goatslacker if you were starting a new project, would you go modernized (no semicolons)? LIke this website offers: http://es6-features.org/ The default it shows is “modernized”.

justin808: Just saw this:

foo();
[1,2,3].forEach(bar);

you could do this:

foo()
;[1,2,3].forEach(bar)

goatslacker: I actually find it more difficult to remember when to use a semicolon than when not.

justin808: http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding does some explaining

goatslacker: yeah

justin808: I’m most familiar with ruby where you end a line with a comma and it continues

goatslacker: https://medium.com/@goatslacker/no-you-dont-need-semicolons-148d936b9cf2
i wrote about it too

justin808: the JS rule using what’s on the next line…boy, that would take some getting used to.
@goatslacker do you work at AirBnb?

goatslacker: I do

justin808: I see, there’s a couple rules of when to begin a line with semicolons if you’re choosing the “modern” syntax.

Are the linters as helpful on the style of not using semicolons?

Basically, @goatslacker would you use https://github.com/feross/standard for a new project, say you were going to create a new startup company.

goatslacker: yeah, I usually don’t begin lines with arithmetic operators, braces, a parenthesis, or a template literal.
nah, I’d use Airbnb style guide with semicolons and all
semicolons are popular amongst the JS community

justin808: From standard:

Never start a line with ( or [
This is the only gotcha with omitting semicolons – automatically checked for you!

goatslacker: that’s actually not the only gotcha, arithmetic operators also fail
and so do template literals

justin808: @goatslacker, thanks! Really psyched to get my projects on ES6 with these guidelines. ESLint seems to potentially support them very well.

goatslacker:

var a = 2
+1
console.log(a === 3)

yeah eslint and jscs are nice

justin808: Ruby would treat that totally differently. That’s what I don’t like.
Is there a jscs setup for the airbnb style guide?
Maybe this: jscs-dev/node-jscs@79ff109

goatslacker: yes, that works well

justin808: @goatslacker worth it to use both at same time? (eslint and jscs?)

goatslacker: yeah definitely

justin808 Thanks!

goatslacker: eslint catches bugs, jscs enforces style guide

justin808: I’m starting a new project, so looking forward to getting it started with linters, as it’s too hard to catch up later on a big project.

goatslacker: :+1: start off on the right foot

References:


#2

If you want to see this in action, with JSCS and ESLint:


#3

AirBnb now has a .eslintrc file, @geoffevason: