Skip to content

Commit 8b8402f

Browse files
mysticateamichalsnik
authored andcommitted
Fix: vue/html-indent ignores <pre> (fixes #365)
1 parent b4413a5 commit 8b8402f

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

lib/utils/indent-common.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,12 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
798798

799799
VElement (node) {
800800
const startTagToken = tokenStore.getFirstToken(node)
801-
const childTokens = node.children.map(n => tokenStore.getFirstToken(n))
802801
const endTagToken = node.endTag && tokenStore.getFirstToken(node.endTag)
803802

804-
setOffset(childTokens, 1, startTagToken)
803+
if (node.name !== 'pre') {
804+
const childTokens = node.children.map(n => tokenStore.getFirstToken(n))
805+
setOffset(childTokens, 1, startTagToken)
806+
}
805807
setOffset(endTagToken, 0, startTagToken)
806808
},
807809

tests/lib/rules/html-indent.js

+45
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ tester.run('html-indent', rule, loadPatterns(
230230
// Ignore all :D
231231
ignores: ['*']
232232
}]
233+
},
234+
235+
// Pre
236+
{
237+
code: unIndent`
238+
<template>
239+
<pre>
240+
aaa
241+
bbb
242+
ccc
243+
</pre>
244+
</template>
245+
`
233246
}
234247
],
235248

@@ -480,6 +493,38 @@ tester.run('html-indent', rule, loadPatterns(
480493
{ message: 'Expected indentation of 12 spaces but found 8 spaces.', line: 4 },
481494
{ message: 'Expected indentation of 12 spaces but found 8 spaces.', line: 6 }
482495
]
496+
},
497+
498+
// Pre
499+
{
500+
code: unIndent`
501+
<template>
502+
<pre
503+
style=""
504+
>
505+
aaa
506+
bbb
507+
ccc
508+
</pre>
509+
</template>
510+
`,
511+
output: unIndent`
512+
<template>
513+
<pre
514+
style=""
515+
>
516+
aaa
517+
bbb
518+
ccc
519+
</pre>
520+
</template>
521+
`,
522+
errors: [
523+
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 },
524+
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 },
525+
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 },
526+
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 }
527+
]
483528
}
484529
]
485530
))

0 commit comments

Comments
 (0)