Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/rules/block-tag-newline.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
]
}
]
})