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.

`no-extra-semi` mistakenly removes necessary semicolon when `semi` is `never`

See original GitHub issue

Tell us about your environment

  • ESLint Version: 3.13.1
  • Node Version: 6.9.3
  • npm Version: 4.1.1 What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:
rules:
  semi:
    - error
    - never
  no-extra-semi:
    - error

What did you do? Please include the actual source code causing the issue.

var foo = function(){};
;[1].map(foo)

What did you expect to happen?

var foo = function(){}
;[1].map(foo)

What actually happened? Please include the actual, raw output from ESLint.

var foo = function(){}
[1].map(foo)

When semi is never, no-extra-semi is true, and there are whitespaces between two semicolons, those rules will delete both of semicolons. semi deletes the first one, and no-extra-semi deletes the second one.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:31 (31 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Jan 17, 2017

@alberto I disagree. The rules are both working correctly, it’s just that their fixes happen to interfere with each other. semi removes the first semicolon (which is correct behavior, because the first semicolon is unnecessary in the original source text). no-extra-semi removes the second semicolon (which is also correct behavior, because the second semicolon is also unnecessary in the original source text). Neither rule knows anything about what the other rule is doing, so core is the only good place to handle this.

If we start adding exceptions to specific fixers to prevent them from conflicting with fixers from other rules, then we’re going to end up with a lot of duplicated logic. For example, the semi rule will have to detect no-extra-semi errors in order to determine whether it should handle the fix. With hundreds of rules, this will quickly become very difficult to reason about, and it also won’t work for custom autofixable rules.

Core is designed to prevent this by isolating fixes. If a rule makes a fix that is safe on its own, core is supposed to guarantee that the fix will be safe when applied with other fixes. This bug violates the guarantee, so it’s an issue with core, not with the rules.

1reaction
not-an-aardvarkcommented, Feb 27, 2017

The bug that was initially reported in this issue was fixed by https://github.com/eslint/eslint/commit/4d35a81c9ddae2e77409bb6d82adeb62e1e1c33c, but I’m going to reopen this since I think we do need to eventually figure out a better general solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-extra-semi - ESLint - Pluggable JavaScript Linter
Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, ...
Read more >
ESLint demands semicolon and wants it removed at the same ...
This is a workaround for the specific situation but it does not resolve the underlying issue. "semi" and "@typescript-eslint/semi" do the same ...
Read more >
Working with Rules - ESLint中文文档
Working with Rules. Each rule in ESLint has two files named with its identifier (for example, no-extra-semi ). in the lib/rules directory: a...
Read more >
deno_lint docs
no-delete-var. Recommended. Disallows the deletion of variables ... no-extra-semi. Recommended. Disallows the use of unnecessary semi-colons.
Read more >
demo-outil-edition - node_modules - eslint - CHANGELOG.md
2f7015b6 New: semi-style rule (fixes #8169) (#8542) (Toru Nagashima) ... 7276e6d Docs: remove unneeded semicolons in arrow-parens.md (#8249) ...
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