Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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