From 98512881f1fc2417011247931fa089d987ee8cc6 Mon Sep 17 00:00:00 2001 From: Victor Hom Date: Tue, 20 Jun 2017 01:31:49 -0400 Subject: [PATCH] Update: fix indent errors on multiline destructure (fixes #8729) (#8756) --- lib/rules/indent.js | 3 +- tests/lib/rules/indent.js | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 5a8feee8ff1..52d08ff3d59 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -658,7 +658,6 @@ module.exports = { while (astUtils.isOpeningParenToken(token) && token !== startToken) { token = sourceCode.getTokenBefore(token); } - return sourceCode.getTokenAfter(token); } @@ -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)); @@ -1242,6 +1240,7 @@ module.exports = { offsets.ignoreToken(equalOperator); offsets.ignoreToken(tokenAfterOperator); offsets.matchIndentOf(equalOperator, tokenAfterOperator); + offsets.matchIndentOf(sourceCode.getFirstToken(node), equalOperator); } }, diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index fd2619ef917..12b42d7124d 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -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 @@ -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` var foo = [