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

Curly bugs #13280

Closed
Mister-Hope opened this issue May 10, 2020 · 3 comments
Closed

Curly bugs #13280

Mister-Hope opened this issue May 10, 2020 · 3 comments
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

Comments

@Mister-Hope
Copy link

Mister-Hope commented May 10, 2020

Tell us about your environment

  • ESLint Version:
    7.0.0
  • Node Version:
    12.16.3
  • npm Version:
    yarn 1.24.4

What parser (default, Babel-ESLint, etc.) are you using?
eslint
Please show your full configuration:

Configuration
rules:
  curly:
    - error
    - multi

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

  for (const [lineId, line] of lines.entries())
    if (regexp === false) {
      for (const reg of regionRegexps)
        if (testLine(line, reg, regionName)) {
          start = lineId + 1;
          regexp = reg;
          break;
        }
    } else if (testLine(line, regexp, regionName, true))
      return { start, end: lineId, regexp };
eslint .

What did you expect to happen?

No errors

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

{
	"resource": "/z:/npm/hopepress/packages/@vuepress/markdown/lib/snippet.ts",
	"owner": "eslint",
	"code": {
		"value": "curly",
		"target": {
			"$mid": 1,
			"external": "https://eslint.org/docs/rules/curly",
			"path": "/docs/rules/curly",
			"scheme": "https",
			"authority": "eslint.org"
		}
	},
	"severity": 8,
	"message": "Unnecessary { after 'if' condition.",
	"source": "eslint",
	"startLineNumber": 2,
	"startColumn": 3,
	"endLineNumber": 2,
	"endColumn": 3
}

The most worse part is I am using eslint --fix earlier, and the code became

  for (const [lineId, line] of lines.entries())
    if (regexp === false) 
      for (const reg of regionRegexps)
        if (testLine(line, reg, regionName)) {
          start = lineId + 1;
          regexp = reg;
          break;
        }
       else if (testLine(line, regexp, regionName, true))
        return { start, end: lineId, regexp };

which is tolally different.

Are you willing to submit a pull request to fix this bug?

No

@Mister-Hope Mister-Hope added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 10, 2020
@anikethsaha
Copy link
Member

anikethsaha commented May 10, 2020

Thanks for the issue.

This is the intended behavior as you are using multi option for the rule and it allows { } only if it contains more than one statement in them

so in your code.

  for (const [lineId, line] of lines.entries())  // single statement - ok
    if (regexp === false) {  // single statement - eslint will throw error as this is single statement but you have placed them in blocks i.e wrapped with { ... }
      for (const reg of regionRegexps)  // single statement - ok
        if (testLine(line, reg, regionName)) {  // multi statement - ok
          start = lineId + 1;
          regexp = reg;
          break;
        }
    } else if (testLine(line, regexp, regionName, true)) 
      return { start, end: lineId, regexp };

refer this

EDIT :

I do think it might be a bug. the else-if is becoming alternate for the inner if after the fix

@mdjermanovic mdjermanovic added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels May 10, 2020
@mdjermanovic
Copy link
Member

@Mister-Hope thanks for the bug report!

I can't reproduce this in our online demo (v7.0.0).

Please let me know if I'm missing something.

I can confirm that this bug indeed exists in v.6.8.0, but it should have been fixed by #12943, which was merged for v7.0.0.

@Mister-Hope
Copy link
Author

emm I do have a version 6.8.0 globally installed, I will check jt out after I return home. thanks

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 8, 2020
@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 Nov 8, 2020
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

No branches or pull requests

3 participants