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: fix indent errors on multiline destructure #8756

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/rules/indent.js
Expand Up @@ -658,7 +658,6 @@ module.exports = {
while (astUtils.isOpeningParenToken(token) && token !== startToken) {
token = sourceCode.getTokenBefore(token);
}

return sourceCode.getTokenAfter(token);
}

Expand All @@ -675,7 +674,6 @@ module.exports = {
if (offset === "first" && elements.length && !elements[0]) {
return;
}

elements.forEach((element, index) => {
if (offset === "off") {
offsets.ignoreToken(getFirstToken(element));
Expand Down Expand Up @@ -1242,6 +1240,7 @@ module.exports = {
offsets.ignoreToken(equalOperator);
offsets.ignoreToken(tokenAfterOperator);
offsets.matchIndentOf(equalOperator, tokenAfterOperator);
offsets.matchIndentOf(sourceCode.getFirstToken(node), equalOperator);
}
},

Expand Down
70 changes: 70 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -2026,6 +2026,58 @@ 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
} = {
a: 1
};
`,
options: [2]
},
{
code: unIndent`
const
foo = {
bar: 1
}
`,
options: [2]
},
{
code: unIndent`
const [
a
] = [
1
]
`,
options: [2]
},
{

// https://github.com/eslint/eslint/issues/7233
Expand Down Expand Up @@ -6834,6 +6886,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`
Copy link
Member

Choose a reason for hiding this comment

The 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 = [
Expand Down