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

Fix: edge-cases of semi-style #9560

Merged
merged 2 commits into from Nov 7, 2017
Merged

Fix: edge-cases of semi-style #9560

merged 2 commits into from Nov 7, 2017

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented Nov 1, 2017

What is the purpose of this pull request? (put an "X" next to item)

[X] Bug fix

Tell us about your environment

  • ESLint Version: 4.10.0
  • Node Version: 8.9.0
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using?

  • default

Please show your full configuration:

  • nothing

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

The online demo for "first" option

/*eslint semi-style: [error, first] */

{
	; // Should be ignored. It's reported by `no-extra-semi`.
}

while (a)
	; // Should be ignored to keep the indented loop body.
foo

do
	; // Should be ignored to keep the indented loop body.
while (a)

do
	foo; // Should be ignored instead of making `;while`.
while (a)

if (a)
	foo; // Should be ignored instead of making `;else`.
else
	bar

The online demo for "last" option

/*eslint semi-style: [error, last] */

{
	; // Should be ignored. It's reported by `no-extra-semi`.
}

switch (a) {
	case 1:
		;foo // Should be ignored. It's reported by `no-extra-semi`.
}

while (a)
	; // Should be ignored to keep the indented loop body.
foo

do
	; // Should be ignored to keep the indented loop body.
while (a)

What did you expect to happen?

No errors.

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

Several errors are reported. See the demo pages.

What changes did you make? (Give an overview)

This PR fixes those false positives. Now the rule ignores semicolons at the first/last in a block/clause.

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@mysticatea mysticatea added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Nov 1, 2017
t === "IfStatement" ||
t === "LabeledStatement" ||
t === "WhileStatement" ||
t === "WithStatement"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be !astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's simple. Yes, it works fine!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I rethought, I'm wondering if I remove the check of EmptyStatement entirely. It makes only redundant consequent semicolons... E.g. foo;;\nbar or foo\n;;bar. No-extra-semi rule should remove that.

@mysticatea
Copy link
Member Author

I updated this PR to simplify with dropping EmptyStatements. The behavior follows to Semi rule which ignores EmptyStatements.

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a question 😄

code: `
switch (a) {
case 1:
;foo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please explain a little why this case is valid? IMHO, it's using options: ["last"], so it should be foo;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This rule checks the location of the semicolon between two statements. I.e.:

first();
second()
// OR
first()
;second()

The rule does not add/remove semicolons because it's the responsibility of semi and no-extra-semi rules. Instead, the rule handles whitespaces of around semicolons.

Now, the current behavior is that the case 1:\n;foo is warned and fixed to case 1:;\nfoo, it was wrong.

@aladdin-add aladdin-add merged commit 7e3bf6a into master Nov 7, 2017
@aladdin-add aladdin-add deleted the semi-style/fix-alone branch November 7, 2017 05:12
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants