From 97287918fba848c271e3e75a93162459973f7f56 Mon Sep 17 00:00:00 2001 From: ota Date: Tue, 13 Nov 2018 17:50:44 +0900 Subject: [PATCH] Revert "Fix: ignore preformatted tokens in `html-indent`" This reverts commit 0f27d019e68e49878ef1145ab6d4469ae8401f11. --- lib/utils/indent-common.js | 31 -------- tests/lib/rules/html-indent.js | 135 +-------------------------------- 2 files changed, 2 insertions(+), 164 deletions(-) diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index ab4981edb..c8c867250 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -258,7 +258,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions) const sourceCode = context.getSourceCode() const offsets = new Map() - const preformattedTokens = new Set() /** * Set offset to the given tokens. @@ -302,29 +301,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti } } - /** - * Sets preformatted tokens to the given element node. - * @param {Node} node The node to set. - * @returns {void} - */ - function setPreformattedTokens (node) { - const endToken = node.endTag && tokenStore.getFirstToken(node.endTag) || tokenStore.getTokenAfter(node) - - const option = { - includeComments: true, - filter: token => token != null && ( - token.type === 'HTMLText' || - token.type === 'HTMLTagOpen' || - token.type === 'HTMLEndTagOpen' || - token.type === 'HTMLComment' - ) - } - for (const token of tokenStore.getTokensBetween(node.startTag, endToken, option)) { - preformattedTokens.add(token) - } - preformattedTokens.add(endToken) - } - /** * Get the first and last tokens of the given node. * If the node is parenthesized, this gets the outermost parentheses. @@ -806,11 +782,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti } } - // It does not validate preformatted tokens. - if (preformattedTokens.has(firstToken)) { - return - } - // Calculate the expected indents for comments. // It allows the same indent level with the previous line. const lastOffsetInfo = offsets.get(lastToken) @@ -850,8 +821,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti if (node.name !== 'pre') { const childTokens = node.children.map(n => tokenStore.getFirstToken(n)) setOffset(childTokens, 1, startTagToken) - } else { - setPreformattedTokens(node) } setOffset(endTagToken, 0, startTagToken) }, diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js index e5e47e2c9..a0613009a 100644 --- a/tests/lib/rules/html-indent.js +++ b/tests/lib/rules/html-indent.js @@ -281,72 +281,6 @@ tester.run('html-indent', rule, loadPatterns( ` - }, - { - filename: 'test.vue', - code: unIndent` - - ` - }, - { - filename: 'test.vue', - code: unIndent` - - ` - }, - { - filename: 'test.vue', - code: unIndent` - - ` - }, - { - filename: 'test.vue', - code: unIndent` - - ` - }, - { - filename: 'test.vue', - code: unIndent` - - ` } ], @@ -630,78 +564,13 @@ tester.run('html-indent', rule, loadPatterns( aaa bbb ccc - - - `, - 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 } - ] - }, - { - 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 } - ] - }, - { - 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 6 spaces but found 0 spaces.', line: 4 }, - { message: 'Expected indentation of 6 spaces but found 0 spaces.', line: 5 }, - { message: 'Expected indentation of 6 spaces but found 0 spaces.', line: 6 }, - { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 }, + { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 }, { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 } ] }