Semicolon position for "semicolons: as-needed" #3737
Replies: 6 comments 10 replies
-
Related prettier issues: |
Beta Was this translation helpful? Give feedback.
-
I think that the case is sufficiently rare to choose either option. I could favor familiarity with prettier, composability, and ease of implementation. Thus, I voted "Start of statement". |
Beta Was this translation helpful? Give feedback.
-
This sounds a lot like adding another expression at the end of a block in Rust, and it's never bothered me. It appears the assessment is mainly the comments complexity you describe versus Prettier conformance. It's been pointed out that this case is rare (and I agree from the few bits of no-semi code I've written in the past) so I don't think Prettier conformance weighs heavily. If the extra complexity is significant, I'd go for after-the-statement. Another minor point: When Prettier creates something like console.log('hi')
;['warning one', 'warning two'].forEach((warning) => console.warn(warning)) I will be so appalled that I change it to console.log("hi")
const warnings = ["warning one", "warning two"]
warnings.forEach((warning) => console.warn(warning)) We might as well save that trouble by putting the semicolon after the |
Beta Was this translation helpful? Give feedback.
-
This is a challenging viewpoint I do not like this poll. Why would you follow the competition? Why not follow the developers? No, not by some poll, but by simply using GitHub search as a customer research tool, to find the most frequently used JavaScript standard. |
Beta Was this translation helpful? Give feedback.
-
I think I speak for most people when I say that whatever you choose will be acceptable, as long as 99.999% of the hideous semicolons are removed. I would limit solicitation of feedback on this issue and move on with what you think is best, otherwise it's going to be an energy drain endlessly debating an edge-case that doesn't really matter in terms of dev experience. |
Beta Was this translation helpful? Give feedback.
-
Thank you all for your feedback. The results are, not surprisingly, fairly balanced. We'll go with the "start of the statement" as this is the established standard by Prettier, StandardJS, and has the advantage that you can easily move statements without worrying about ASI. This comes with the downside that we'll inherit some of the bugs that Prettier ran into too but they are rare enough, and it's easily possible to rewrite the statement to avoid the need for the semicolon in the first place. |
Beta Was this translation helpful? Give feedback.
-
I'm about to implement the
semicolons: as-needed
option. I prefer to always add semicolons, which is why I'm not very familiar with the established standards when omitting semicolons. One question I ran into when implementing the option is where to put the semicolon in case it is required.Start of statement:
Prettier puts the semicolon in front of the expression that requires the semicolon.
The downside of this approach is that it may require multiple formatting passes when such an expression has a leading comment because:
Input:
The comments are leading comments of the array expression. This becomes the following code after the first pass
The comments have become trailing comments of the
console.log(a)
expression because it is between the)
and the;
of the previous statement.The second formatting then results in
I don't expect this to be a significant problem, but something to keep in mind.
It's also worth noting that Prettier places comments at the end of properties and not in front of the next class or type member.
The main upside of the approach is (from Prettier's documentation)
StandardJs also puts the semicolons at the beginning of the statement.
End of previous statement
My intuition would have been to keep the
;
with the previous statement if it is necessary:The downsides of this approach are:
36 votes ·
Beta Was this translation helpful? Give feedback.
All reactions