Skip to content

Commit d9f442b

Browse files
committed
Fix crash on <textarea> without end tag in vue/html-indent rule
1 parent 2472ffa commit d9f442b

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/utils/indent-common.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,9 @@ module.exports.defineVisitor = function create(
311311
token.type === 'HTMLEndTagOpen' ||
312312
token.type === 'HTMLComment')
313313
}
314-
for (const token of tokenStore.getTokensBetween(
315-
node.startTag,
316-
endToken,
317-
option
318-
)) {
314+
for (const token of endToken
315+
? tokenStore.getTokensBetween(node.startTag, endToken, option)
316+
: tokenStore.getTokensAfter(node.startTag, option)) {
319317
ignoreTokens.add(token)
320318
}
321319
ignoreTokens.add(endToken)

tests/lib/rules/html-indent.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,22 @@ tester.run(
403403
text <span /> <!-- comment --></pre>
404404
</template>
405405
`
406+
},
407+
{
408+
filename: 'test.vue',
409+
code: unIndent`
410+
<template>
411+
<textarea>
412+
</template>
413+
`
414+
},
415+
{
416+
filename: 'test.vue',
417+
code: unIndent`
418+
<template>
419+
<pre>
420+
</template>
421+
`
406422
}
407423
],
408424

@@ -929,6 +945,25 @@ tester.run(
929945
line: 2
930946
}
931947
]
948+
},
949+
{
950+
filename: 'test.vue',
951+
code: unIndent`
952+
<template>
953+
<textarea>
954+
</template>
955+
`,
956+
output: unIndent`
957+
<template>
958+
<textarea>
959+
</template>
960+
`,
961+
errors: [
962+
{
963+
message: 'Expected indentation of 2 spaces but found 4 spaces.',
964+
line: 2
965+
}
966+
]
932967
}
933968
]
934969
)

0 commit comments

Comments
 (0)