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
feat: fix indent rule for else-if #17318
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6361,7 +6361,156 @@ ruleTester.run("indent", rule, { | |
;[1, 2, 3].forEach(x=>console.log(x)) | ||
`, | ||
options: [4] | ||
} | ||
}, | ||
|
||
// https://github.com/eslint/eslint/issues/17316 | ||
{ | ||
code: unIndent` | ||
if (foo) | ||
\tif (bar) doSomething(); | ||
\telse doSomething(); | ||
else | ||
\tif (bar) doSomething(); | ||
\telse doSomething(); | ||
`, | ||
options: ["tab"] | ||
}, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (bar) | ||
doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (bar) doSomething(); | ||
else | ||
doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (bar) | ||
doSomething(); | ||
else | ||
doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (bar) doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (bar) | ||
doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (bar) doSomething(); | ||
else | ||
doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (bar) | ||
doSomething(); | ||
else | ||
doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
|
||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (foo) | ||
if (bar) doSomething(); | ||
else | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (foo) doSomething(); | ||
else doSomething(); | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (foo) { | ||
doSomething(); | ||
} | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else if (foo) | ||
{ | ||
doSomething(); | ||
} | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (foo) { | ||
doSomething(); | ||
} | ||
`, | ||
unIndent` | ||
if (foo) | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
else | ||
if (foo) | ||
{ | ||
doSomething(); | ||
} | ||
` | ||
], | ||
|
||
invalid: [ | ||
|
@@ -13381,6 +13530,31 @@ ruleTester.run("indent", rule, { | |
`, | ||
options: [4], | ||
errors: expectedErrors([4, 0, 4, "Punctuator"]) | ||
}, | ||
|
||
// https://github.com/eslint/eslint/issues/17316 | ||
{ | ||
code: unIndent` | ||
if (foo) | ||
\tif (bar) doSomething(); | ||
\telse doSomething(); | ||
else | ||
if (bar) doSomething(); | ||
else doSomething(); | ||
Comment on lines
+13537
to
+13543
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compared to all the great Would you mind copying a few of them here (and make them invalid of course)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll add more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added more |
||
`, | ||
output: unIndent` | ||
if (foo) | ||
\tif (bar) doSomething(); | ||
\telse doSomething(); | ||
else | ||
\tif (bar) doSomething(); | ||
\telse doSomething(); | ||
`, | ||
options: ["tab"], | ||
errors: expectedErrors("tab", [ | ||
[5, 1, 0, "Keyword"], | ||
[6, 1, 0, "Keyword"] | ||
]) | ||
} | ||
] | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to trace this logic all the way back to the big rewrite of this rule so I'm guessing it was carried over from broken logic earlier or was an inherent bug in the initial implementation.