Skip to content

Commit

Permalink
Fix crash on <textarea> without end tag in vue/html-indent rule (#…
Browse files Browse the repository at this point in the history
…1755)

* Fix crash on `<textarea>` without end tag in `vue/html-indent` rule

* refactor
  • Loading branch information
ota-meshi committed Jan 8, 2022
1 parent e7b77aa commit a475176
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/utils/indent-common.js
Expand Up @@ -301,7 +301,7 @@ module.exports.defineVisitor = function create(
tokenStore.getTokenAfter(node)

/** @type {SourceCode.CursorWithSkipOptions} */
const option = {
const cursorOptions = {
includeComments: true,
filter: (token) =>
token != null &&
Expand All @@ -311,11 +311,11 @@ module.exports.defineVisitor = function create(
token.type === 'HTMLEndTagOpen' ||
token.type === 'HTMLComment')
}
for (const token of tokenStore.getTokensBetween(
node.startTag,
endToken,
option
)) {
const contentTokens = endToken
? tokenStore.getTokensBetween(node.startTag, endToken, cursorOptions)
: tokenStore.getTokensAfter(node.startTag, cursorOptions)

for (const token of contentTokens) {
ignoreTokens.add(token)
}
ignoreTokens.add(endToken)
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/rules/html-indent.js
Expand Up @@ -403,6 +403,22 @@ tester.run(
text <span /> <!-- comment --></pre>
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<textarea>
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<pre>
</template>
`
}
],

Expand Down Expand Up @@ -929,6 +945,25 @@ tester.run(
line: 2
}
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
<textarea>
</template>
`,
output: unIndent`
<template>
<textarea>
</template>
`,
errors: [
{
message: 'Expected indentation of 2 spaces but found 4 spaces.',
line: 2
}
]
}
]
)
Expand Down

0 comments on commit a475176

Please sign in to comment.