Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upThe rule “Never start a line with (, [, or `” is incorrect, too restrictive, and not easy enough to follow #938
Comments
claudepache
changed the title
The rule “Never start a line with (, [, or `” is incorrect, too restrictive, and not simple enough to follow
The rule “Never start a line with (, [, or `” is incorrect, too restrictive, and not easy enough to follow
Jun 27, 2017
This comment has been minimized.
This comment has been minimized.
|
Err, alright - I'm not sure what your question is here. If your question is "could you please change this?" then I can save us all some time by telling you it's not going to happen. Keen to hear what you mean tho, we're always open to improvements in documentation or otherwise! (: |
This comment has been minimized.
This comment has been minimized.
The rule in question is a high level conceptual rule, and isn't the rule specially used to lint, enforce or solve the scenario its trying to protect against. For a more in depth discussion of the rational for this read https://feross.org/never-use-semicolons/ I recommend trying out the linter and the style as is, and if you like it great! If not, then you are free to choose your own slew of eslint rules, or some of the variants but beware of wasted time bike shedding. |
This comment has been minimized.
This comment has been minimized.
|
@claudepache Thanks for sharing your thoughts. The statement in question "Never start a line with..." is easy-to-understand and succinct. You're technically correct that it should say standalone statements, not lines, but the way it is written now gets the point across more clearly to users of all skill levels. Of course, the actual ESLint rules operate on the AST and enforce that no unexpected ASI occurs, based on how the code would actually execute. But, I think sharing a simple "rule of thumb" makes more sense in the first few lines of the readme. Cheers :) |
claudepache commentedJun 27, 2017
The rule in question:
(,[, or`(1) The rule is incorrect, because:
+,-and/are also hazards for ASI, and should be added to the list of offending tokens.(2) The rule is too restrictive, because it is fine to start a line with any of the offending character when it is not at the beginning of a standalone statement. That includes:
//and/*(those are not statements);if,else, etc. clause (those are not standalone);(3) Finally, it lacks a simple receipt of what to do when you are in a situation where you want to start a line with
(or[. You don’t have to refactor your code. You just need to precede it with a semicolon, but only when you are at the beginning of a standalone statement (hence the usefulness of mentioning “beginning of a standalone statement”).