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

Require semicolons #1155

Closed
danny-andrews opened this issue Jun 23, 2018 · 1 comment

Comments

@danny-andrews
Copy link

commented Jun 23, 2018

I know this bug will get shot down, because semi-omitters irrationally put "code aesthetics" above consistency and correctness 😉, but I will attempt to reason with you one last time, for the beginners if nothing else!

You should consider changing to require semicolons because:

  1. Some statements require a "hack" to get the desired behavior. These hacks are especially confusing for beginners:
console.log('hey')
;[1, 2, 3].forEach(print) // WTF is this semicolon doing at the beginning of the line
  1. It can result in edge-cases even when the no-unexpected-multiline rule is enabled:
function a() {
  return
    "Nope, I am sorry!"
}

a() // undefined

This code will pass even with no-unexpected-newline rule is enabled. Proof

  1. Always requiring semicolons results in zero edge-cases, completely consistent code, and no hacks to confuse beginners. The previous example would look like this:
function a() {
  return;
  "Nope, I am sorry!";
}

a(); // undefined

Although this wouldn't give you an error, you would probably never write code like this, because it's clear that you're not returning anything (because you know the semicolon ends a statement).

Pls reconsider. I'm out.

Further reading: https://hackernoon.com/an-open-letter-to-javascript-leaders-regarding-no-semicolons-82cec422d67d

@LinusU

This comment has been minimized.

Copy link
Member

commented Jun 24, 2018

Your example would trigger both the "Unreachable code" (no-unreachable) and the
"Expected an assignment or function call and instead saw an expression" (no-unused-expressions) error though so it wouldn't be accepted by Standard. Also, adding semicolons wouldn't change anything as you pointed out yourselves.

because semi-omitters irrationally put "code aesthetics" above consistency

Is this really consistent though?

function a() {
  return;
  "Nope, I am sorry!";
} // <--- why is there no semicolon here?

a();

for the beginners if nothing else!

This sounds like the classic "Think of the children" argument. I don't see how not using semicolons is harder for beginners. One could even, and people do, make the argument that using semicolons is harder for beginners.


Anyhow, it doesn't really matter one way or another. There is no way for us to decide which one is "best" in this thread. Standard is not using semicolons and that won't change, since it would break 100% of all projects using standard. We only introduce rule changes when they only affect a small percentage of the eco-system, and has a clear positive benefit.

If you want to use semicolons, feel free to use semistandard

@LinusU LinusU closed this Jun 24, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Sep 22, 2018

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