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: fix indent errors on multiline destructure #8756
Merged
not-an-aardvark
merged 5 commits into
eslint:master
from
VictorHom:pr/indent_multiline_destructure
Jun 20, 2017
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
310b010
Fix: multiline destructure errors (fixes #8729)
not-an-aardvark acec1be
Fix: multiline destructure errors (fixes #8729)
VictorHom 05028f7
fix the functions that check bracket/braces
VictorHom de345f8
set the indentation of = operator to be variabledeclarator
VictorHom d59a701
add two additional tests
VictorHom File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2026,6 +2026,38 @@ ruleTester.run("indent", rule, { | |
`, | ||
options: [2] | ||
}, | ||
{ | ||
code: unIndent` | ||
const { | ||
a | ||
} | ||
= | ||
{ | ||
a: 1 | ||
} | ||
`, | ||
options: [2] | ||
}, | ||
{ | ||
code: unIndent` | ||
const { | ||
a | ||
} = { | ||
a: 1 | ||
} | ||
`, | ||
options: [2] | ||
}, | ||
{ | ||
code: unIndent` | ||
const [ | ||
a | ||
] = [ | ||
1 | ||
] | ||
`, | ||
options: [2] | ||
}, | ||
{ | ||
|
||
// https://github.com/eslint/eslint/issues/7233 | ||
|
@@ -6834,6 +6866,24 @@ ruleTester.run("indent", rule, { | |
options: [2], | ||
errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]]) | ||
}, | ||
{ | ||
code: unIndent` | ||
const { | ||
a | ||
} = { | ||
a: 1 | ||
} | ||
`, | ||
output: unIndent` | ||
const { | ||
a | ||
} = { | ||
a: 1 | ||
} | ||
`, | ||
options: [2], | ||
errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]]) | ||
}, | ||
{ | ||
code: unIndent` | ||
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. Can you also add tests to make sure these are valid? const
{
a
} = {
a: 1
}; const
foo = {
bar: 1
} |
||
var foo = [ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think the root cause of the problem is that the
=
token's indentation is not set correctly in theVariableDeclarator
listener. By design,offsets.ignoreToken
is called on the token, but this is a no-op if the token is not the first of its line. So the=
token ends up with an offset of 1 from the start of the declarator, and then the value on the right of the equals sign is matched against the indentation of the equals sign. As a result, the rule indents value on the right of the equals sign by 1 from the start of the declarator, when it should be indented by 0.I think this can be fixed by explicitly specifying the indentation of the
=
token relative to the declarator. Applying the following diff to the original version of the file seems to make everything work correctly and fixes the bug: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.
thanks for the explanation. That makes sense