Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting Lines With Semicolons (ES6) #80

Closed
mattdesl opened this issue Mar 24, 2015 · 6 comments

Comments

@mattdesl
Copy link

commented Mar 24, 2015

Note: This isn't a question about whether to use ASI or not (already discussed #78).

@maxogden

We no longer recommend starting lines with semicolons. It's hacky. Start lines with void, var, const or something that makes more sense.

Can you expand on this a bit more? To me void is confusing and code-smell-ish. I don't really see anything wrong with enforcing a preceding semicolon for [ and ( and disallowing lines starting with other operators (like regexes and template strings).

Preceding semicolon:

let [ x, y ] = [ 8, 2 ]
;[ x, y ] = [ y, x ]

Void: (does this even work??)

let [ x, y ] = [ 8, 2 ]
void [ x, y ] = [ y, x ]

Avoiding it completely:

let [ x, y ] = [ 8, 2 ]
let t = x
x = y
y = t

Aside from swapping variables, it can also be useful to write code like this:

//translate Z and project into 2D
let [ x, y, z ] = position()
z += translation
;[ x, y ] = project([ x, y, z ])

drawPoint(x, y)
@maxogden

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2015

My opinion is if you have ;[ or ;( it should not cause a standard error. I just didn't think it was the best thing to have as the first code example in the readme.

@mattdesl

This comment has been minimized.

Copy link
Author

commented Mar 25, 2015

Ah, the wording led me to believe the tool would never allow it. Maybe listing it as a bullet point below "no semicolons" would be better, like:

"Any lines starting with [ or ( require a preceding semicolon; but using shorthand patterns is discouraged"

It could link to a code example showing the ;[ approach next to the preferred alternative (with var or some assignment). And maybe a note about ES6 edge cases.

@maxogden

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2015

@mattdesl not a bad idea, I think we might as well just change that whole line to link to a separate markdown file with more detail rather than try to explain complex stuff in the bullet list

@feross

This comment has been minimized.

Copy link
Member

commented Apr 9, 2015

Let's add more detailed explanations of these edge cases on the wiki: https://github.com/feross/standard/wiki

I'm going to close this now. Thanks for bringing this up, @mattdesl!

@mattdesl

This comment has been minimized.

Copy link
Author

commented Apr 16, 2015

@feross
Some edits if you want to review:
https://gist.github.com/mattdesl/4fb2e1d2c0b5a0b8048a#asi

You could pull the wiki into git for proper commits/PRs/etc. I tend to do that on my own projects since the wikis are a bit lacklusre.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 20, 2015

Thanks @mattdesl. Added a RULES.md file and removed the wiki.

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.