Skip to content

Commit 0fd0f7b

Browse files
authored
Merge pull request #658 from vuejs/revert-html-indent
Revert "Fix: ignore preformatted tokens in `html-indent`"
2 parents 0f27d01 + 9728791 commit 0fd0f7b

File tree

2 files changed

+2
-164
lines changed

2 files changed

+2
-164
lines changed

Diff for: lib/utils/indent-common.js

-31
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
258258
const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions)
259259
const sourceCode = context.getSourceCode()
260260
const offsets = new Map()
261-
const preformattedTokens = new Set()
262261

263262
/**
264263
* Set offset to the given tokens.
@@ -302,29 +301,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
302301
}
303302
}
304303

305-
/**
306-
* Sets preformatted tokens to the given element node.
307-
* @param {Node} node The node to set.
308-
* @returns {void}
309-
*/
310-
function setPreformattedTokens (node) {
311-
const endToken = node.endTag && tokenStore.getFirstToken(node.endTag) || tokenStore.getTokenAfter(node)
312-
313-
const option = {
314-
includeComments: true,
315-
filter: token => token != null && (
316-
token.type === 'HTMLText' ||
317-
token.type === 'HTMLTagOpen' ||
318-
token.type === 'HTMLEndTagOpen' ||
319-
token.type === 'HTMLComment'
320-
)
321-
}
322-
for (const token of tokenStore.getTokensBetween(node.startTag, endToken, option)) {
323-
preformattedTokens.add(token)
324-
}
325-
preformattedTokens.add(endToken)
326-
}
327-
328304
/**
329305
* Get the first and last tokens of the given node.
330306
* If the node is parenthesized, this gets the outermost parentheses.
@@ -806,11 +782,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
806782
}
807783
}
808784

809-
// It does not validate preformatted tokens.
810-
if (preformattedTokens.has(firstToken)) {
811-
return
812-
}
813-
814785
// Calculate the expected indents for comments.
815786
// It allows the same indent level with the previous line.
816787
const lastOffsetInfo = offsets.get(lastToken)
@@ -850,8 +821,6 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
850821
if (node.name !== 'pre') {
851822
const childTokens = node.children.map(n => tokenStore.getFirstToken(n))
852823
setOffset(childTokens, 1, startTagToken)
853-
} else {
854-
setPreformattedTokens(node)
855824
}
856825
setOffset(endTagToken, 0, startTagToken)
857826
},

Diff for: tests/lib/rules/html-indent.js

+2-133
Original file line numberDiff line numberDiff line change
@@ -281,72 +281,6 @@ tester.run('html-indent', rule, loadPatterns(
281281
</pre>
282282
</template>
283283
`
284-
},
285-
{
286-
filename: 'test.vue',
287-
code: unIndent`
288-
<template>
289-
<pre>
290-
<span>aaa</span>
291-
<span>bbb</span>
292-
<span>ccc</span>
293-
</pre>
294-
</template>
295-
`
296-
},
297-
{
298-
filename: 'test.vue',
299-
code: unIndent`
300-
<template>
301-
<pre>aaa
302-
bbb ccc
303-
ddd
304-
fff</pre>
305-
</template>
306-
`
307-
},
308-
{
309-
filename: 'test.vue',
310-
code: unIndent`
311-
<template>
312-
<pre><span>aaa</span>
313-
<span>bbb</span> <span>ccc</span>
314-
<span>ddd</span>
315-
<span>fff</span></pre>
316-
</template>
317-
`
318-
},
319-
{
320-
filename: 'test.vue',
321-
code: unIndent`
322-
<template>
323-
<pre>
324-
<!-- comment -->
325-
<!-- comment --> <!-- comment -->
326-
<!-- comment --></pre>
327-
</template>
328-
`
329-
},
330-
{
331-
filename: 'test.vue',
332-
code: unIndent`
333-
<template>
334-
<pre>
335-
<!-- comment --> text <span />
336-
<span /> <!-- comment --> text
337-
text <span /> <!-- comment -->
338-
</pre>
339-
<div>
340-
<input>
341-
</div>
342-
<pre>
343-
<!-- comment --> text <span /></pre>
344-
<pre>
345-
<span /> <!-- comment --> text</pre>
346-
<pre>
347-
text <span /> <!-- comment --></pre>
348-
</template>
349-
`
350284
}
351285
],
352286

@@ -630,78 +564,13 @@ tester.run('html-indent', rule, loadPatterns(
630564
aaa
631565
bbb
632566
ccc
633-
</pre>
634-
</template>
635-
`,
636-
errors: [
637-
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 },
638-
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 },
639-
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 }
640-
]
641-
},
642-
{
643-
filename: 'test.vue',
644-
code: unIndent`
645-
<template>
646-
<pre
647-
style=""
648-
>
649-
no end tag
650-
</template>
651-
`,
652-
output: unIndent`
653-
<template>
654-
<pre
655-
style=""
656-
>
657-
no end tag
658-
</template>
659-
`,
660-
errors: [
661-
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 },
662-
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 },
663-
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 }
664-
]
665-
},
666-
{
667-
filename: 'test.vue',
668-
code: unIndent`
669-
<template>
670-
<pre
671-
:class="[
672-
'a',
673-
'b',
674-
'c'
675-
]"
676-
>
677-
aaa
678-
bbb
679-
ccc
680-
</pre>
567+
</pre>
681568
</template>
682569
`,
683-
output: unIndent`
684-
<template>
685-
<pre
686-
:class="[
687-
'a',
688-
'b',
689-
'c'
690-
]"
691-
>
692-
aaa
693-
bbb
694-
ccc
695-
</pre>
696-
</template>
697-
`,
698570
errors: [
699571
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 },
700572
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 },
701-
{ message: 'Expected indentation of 6 spaces but found 0 spaces.', line: 4 },
702-
{ message: 'Expected indentation of 6 spaces but found 0 spaces.', line: 5 },
703-
{ message: 'Expected indentation of 6 spaces but found 0 spaces.', line: 6 },
704-
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 },
573+
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 },
705574
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 }
706575
]
707576
}

0 commit comments

Comments
 (0)