question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Enforce consistent linebreak style for semicolons

See original GitHub issue

Please describe what the rule should do:

Enforce consistent linebreak style for semicolons. Require that they be placed either at the end of a line or beginning of a line.

While in a project that use semicolons after every statement, there is little question that the semicolon belongs at the end of the line. However, in a project that uses semicolons only where needed, it’s helpful to enforce the placement of the occasional semicolon.

What category of rule is this? (place an “X” next to just one item)

[X] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

With "after", this would be an error:

foo()
bar(); // A semicolon is required here for the next statement to be interpreted as intended.
[1, 2, 3].forEach(a => { console.log(a) })
baz()

This would be correct:

foo()
bar() // A semicolon is required here for the next statement to be interpreted as intended.
;[1, 2, 3].forEach(a => { console.log(a) })
baz()

With "before", this would be an error:

foo();
bar()
;[1, 2, 3].forEach(a => { console.log(a) });
baz();

This would be correct:

foo();
bar();
[1, 2, 3].forEach(a => { console.log(a) });
baz();

Why should this rule be included in ESLint (instead of a plugin)?

Semicolon style is applicable to most projects that define a style guide. It varies significantly from project to project. Some using semis everywhere; others only where they’re needed. Developers new to no-semicolon projects may misplace the required semicolon. Developers on semicolon projects may prefer to enforce consistency as well.

This rule relates to semi, but does not depend on, conflict with, or overlap with it, or any other rule.

The rule is straightforward to understand. It’s just like operator-linebreak.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
kaicataldocommented, Apr 22, 2017

This has now been accepted!

1reaction
ilyavolodincommented, Mar 4, 2017

@paulmelnikow It does as a statement, but as a rule, we have no precedence for such tightly coupled rules. I’m still not convinced that it would be a good idea to go down this route.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: disable automatic semicolon insertion (looking for ...
I want to propose a way to disable automatic semicolon insertion (ASI), because its behaviours are a little confusing sometimes, and it's probably...
Read more >
linebreak-style - ESLint - Pluggable JavaScript Linter
This rule enforces consistent line endings independent of operating system, VCS, or editor used across your codebase. Options. This rule has a string...
Read more >
Options - Prettier
Consistent use of parentheses provides a better developer experience when editing real codebases, which justifies the default value for the option. Range.
Read more >
How would you re-write the production rules for an existing ...
the line doesn't already end with a newline, and ... you'll find projects with style guides which require semicolons even in context in ......
Read more >
Semicolons in Go - Google Groups
It can be summarized in two steps. First, the formal grammar requires semicolons in statement lists. Second, a lexical (not syntactic) rule inserts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found