From 6965fac4a323c4dcb6023cde311860f0cd390856 Mon Sep 17 00:00:00 2001 From: michalsnik Date: Mon, 7 Jan 2019 15:45:05 +0100 Subject: [PATCH 1/3] fix(html-indent): Don't nest closeBracket of closing tag --- lib/utils/indent-common.js | 2 +- tests/lib/rules/html-indent.js | 86 ++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index 28e68b0a8..8860673d7 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -909,7 +909,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti const closeToken = tokenStore.getLastToken(node) if (closeToken.type.endsWith('TagClose')) { - setOffset(closeToken, options.closeBracket, openToken) + setOffset(closeToken, 0, openToken) } }, diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js index 724ee961f..79cdc0e07 100644 --- a/tests/lib/rules/html-indent.js +++ b/tests/lib/rules/html-indent.js @@ -381,6 +381,33 @@ tester.run('html-indent', rule, loadPatterns( text ` + }, + // Close bracket + { + filename: 'test.vue', + code: unIndent` + + `, + options: [2, { + closeBracket: 1 + }] + }, + { + filename: 'test.vue', + code: unIndent` + + `, + options: [2, { + closeBracket: 2 + }] } ], @@ -756,6 +783,65 @@ tester.run('html-indent', rule, loadPatterns( { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 }, { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 } ] + }, + { + filename: 'test.vue', + code: unIndent` + + `, + output: unIndent` + + `, + errors: [ + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 }, + { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 }, + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 }, + { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 5 }, + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 6 } + ] + }, + { + filename: 'test.vue', + code: unIndent` + + `, + options: [2, { + closeBracket: 1 + }], + output: unIndent` + + `, + errors: [ + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 }, + { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 }, + { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 4 }, + { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 5 }, + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 6 } + ] } ] )) From f72c85285bc07cde53c8cf60270c9a28cdcce496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sajn=C3=B3g?= Date: Sat, 26 Jan 2019 17:26:52 +0700 Subject: [PATCH 2/3] chore(html-indent): Move test cases to fixtures --- .../fixtures/html-indent/close-bracket-01.vue | 14 +++ .../fixtures/html-indent/close-bracket-02.vue | 8 ++ tests/lib/rules/html-indent.js | 86 ------------------- 3 files changed, 22 insertions(+), 86 deletions(-) create mode 100644 tests/fixtures/html-indent/close-bracket-01.vue create mode 100644 tests/fixtures/html-indent/close-bracket-02.vue diff --git a/tests/fixtures/html-indent/close-bracket-01.vue b/tests/fixtures/html-indent/close-bracket-01.vue new file mode 100644 index 000000000..ea4a69d98 --- /dev/null +++ b/tests/fixtures/html-indent/close-bracket-01.vue @@ -0,0 +1,14 @@ + + diff --git a/tests/fixtures/html-indent/close-bracket-02.vue b/tests/fixtures/html-indent/close-bracket-02.vue new file mode 100644 index 000000000..1f899644e --- /dev/null +++ b/tests/fixtures/html-indent/close-bracket-02.vue @@ -0,0 +1,8 @@ + + diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js index 79cdc0e07..724ee961f 100644 --- a/tests/lib/rules/html-indent.js +++ b/tests/lib/rules/html-indent.js @@ -381,33 +381,6 @@ tester.run('html-indent', rule, loadPatterns( text ` - }, - // Close bracket - { - filename: 'test.vue', - code: unIndent` - - `, - options: [2, { - closeBracket: 1 - }] - }, - { - filename: 'test.vue', - code: unIndent` - - `, - options: [2, { - closeBracket: 2 - }] } ], @@ -783,65 +756,6 @@ tester.run('html-indent', rule, loadPatterns( { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 }, { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 } ] - }, - { - filename: 'test.vue', - code: unIndent` - - `, - output: unIndent` - - `, - errors: [ - { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 }, - { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 5 }, - { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 6 } - ] - }, - { - filename: 'test.vue', - code: unIndent` - - `, - options: [2, { - closeBracket: 1 - }], - output: unIndent` - - `, - errors: [ - { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 4 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 5 }, - { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 6 } - ] } ] )) From 11a61494b10d9ccd5a35fc8f94dea5619419ae65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sajn=C3=B3g?= Date: Sat, 26 Jan 2019 17:28:17 +0700 Subject: [PATCH 3/3] tests(html-indent): Add more test cases --- tests/fixtures/html-indent/close-bracket-02.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/html-indent/close-bracket-02.vue b/tests/fixtures/html-indent/close-bracket-02.vue index 1f899644e..f8158c617 100644 --- a/tests/fixtures/html-indent/close-bracket-02.vue +++ b/tests/fixtures/html-indent/close-bracket-02.vue @@ -1,8 +1,14 @@