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

Enable vue/html-closing-bracket-* for top-level tags #1883

Merged
merged 3 commits into from May 11, 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
13 changes: 4 additions & 9 deletions lib/rules/block-tag-newline.js
Expand Up @@ -347,13 +347,6 @@ module.exports = {

const verify = normalizeOptionValue(context.options[0])

/**
* @returns {VElement[]}
*/
function getTopLevelHTMLElements() {
return documentFragment.children.filter(utils.isVElement)
}

return utils.defineTemplateBodyVisitor(
context,
{},
Expand All @@ -364,8 +357,10 @@ module.exports = {
return
}

for (const element of getTopLevelHTMLElements()) {
verify(element)
for (const element of documentFragment.children) {
if (utils.isVElement(element)) {
verify(element)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-closing-bracket-newline.js
Expand Up @@ -68,7 +68,7 @@ module.exports = {
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()

return utils.defineTemplateBodyVisitor(context, {
return utils.defineDocumentVisitor(context, {
/** @param {VStartTag | VEndTag} node */
'VStartTag, VEndTag'(node) {
const closingBracketToken = template.getLastToken(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-closing-bracket-spacing.js
Expand Up @@ -92,7 +92,7 @@ module.exports = {
context.parserServices.getTemplateBodyTokenStore()
const options = parseOptions(context.options[0], tokens)

return utils.defineTemplateBodyVisitor(context, {
return utils.defineDocumentVisitor(context, {
/** @param {VStartTag | VEndTag} node */
'VStartTag, VEndTag'(node) {
const type = options.detectType(node)
Expand Down
150 changes: 150 additions & 0 deletions tests/lib/rules/html-closing-bracket-newline.js
Expand Up @@ -337,6 +337,156 @@ tester.run('html-closing-bracket-newline', rule, {
'Expected 1 line break before closing bracket, but no line breaks found.',
'Expected 1 line break before closing bracket, but no line breaks found.'
]
},
{
code: `
<template
>
</template
>
<script
>
</script
>
<style
></style
>
`,
output: `
<template>
</template>
<script>
</script>
<style></style>
`,
options: [
{
singleline: 'never',
multiline: 'never'
}
],
errors: [
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 2,
column: 18,
endLine: 3,
endColumn: 9
},
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 4,
column: 19,
endLine: 5,
endColumn: 9
},
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 6,
column: 16,
endLine: 7,
endColumn: 9
},
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 8,
column: 17,
endLine: 9,
endColumn: 9
},
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 10,
column: 15,
endLine: 11,
endColumn: 9
},
{
message:
'Expected no line breaks before closing bracket, but 1 line break found.',
line: 11,
column: 17,
endLine: 12,
endColumn: 9
}
]
},
{
code: `
<template>
</template>
<script>
</script>
<style></style>
`,
output: `
<template
>
</template
>
<script
>
</script
>
<style
></style
>
`,
options: [
{
singleline: 'always',
multiline: 'always'
}
],
errors: [
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 2,
column: 18,
endColumn: 18
},
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 3,
column: 19,
endColumn: 19
},
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 4,
column: 16,
endColumn: 16
},
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 5,
column: 17,
endColumn: 17
},
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 6,
column: 15,
endColumn: 15
},
{
message:
'Expected 1 line break before closing bracket, but no line breaks found.',
line: 6,
column: 23,
endColumn: 23
}
]
}
]
})
107 changes: 107 additions & 0 deletions tests/lib/rules/html-closing-bracket-spacing.js
Expand Up @@ -114,6 +114,56 @@ ruleTester.run('html-closing-bracket-spacing', rule, {
}
]
},
{
code: `
<template ></template >
<script ></script >
<style ></style >
`,
output: `
<template></template>
<script></script>
<style></style>
`,
errors: [
{
message: "Expected no space before '>', but found.",
line: 2,
column: 18,
endColumn: 20
},
{
message: "Expected no space before '>', but found.",
line: 2,
column: 30,
endColumn: 32
},
{
message: "Expected no space before '>', but found.",
line: 3,
column: 16,
endColumn: 18
},
{
message: "Expected no space before '>', but found.",
line: 3,
column: 26,
endColumn: 28
},
{
message: "Expected no space before '>', but found.",
line: 4,
column: 15,
endColumn: 17
},
{
message: "Expected no space before '>', but found.",
line: 4,
column: 24,
endColumn: 26
}
]
},
{
code: '<template >\n <div>\n </div>\n <div />\n</template >',
output: '<template >\n <div >\n </div >\n <div/>\n</template >',
Expand Down Expand Up @@ -144,6 +194,63 @@ ruleTester.run('html-closing-bracket-spacing', rule, {
endColumn: 10
}
]
},
{
code: `
<template></template>
<script></script>
<style></style>
`,
output: `
<template ></template >
<script ></script >
<style ></style >
`,
options: [
{
startTag: 'always',
endTag: 'always',
selfClosingTag: 'never'
}
],
errors: [
{
message: "Expected a space before '>', but not found.",
line: 2,
column: 18,
endColumn: 19
},
{
message: "Expected a space before '>', but not found.",
line: 2,
column: 29,
endColumn: 30
},
{
message: "Expected a space before '>', but not found.",
line: 3,
column: 16,
endColumn: 17
},
{
message: "Expected a space before '>', but not found.",
line: 3,
column: 25,
endColumn: 26
},
{
message: "Expected a space before '>', but not found.",
line: 4,
column: 15,
endColumn: 16
},
{
message: "Expected a space before '>', but not found.",
line: 4,
column: 23,
endColumn: 24
}
]
}
]
})