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: 10 additions & 3 deletions lib/rules/multiline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// ------------------------------------------------------------------------------

const utils = require('../utils')
const casing = require('../utils/casing')

// ------------------------------------------------------------------------------
// Helpers
Expand All @@ -20,7 +21,7 @@ function isMultilineElement (element) {

function parseOptions (options) {
return Object.assign({
'ignores': ['pre', 'textarea']
ignores: ['pre', 'textarea']
}, options)
}

Expand Down Expand Up @@ -80,12 +81,18 @@ module.exports = {

let inIgnoreElement

function isIgnoredElement (node) {
return ignores.includes(node.name) ||
ignores.includes(casing.pascalCase(node.rawName)) ||
ignores.includes(casing.kebabCase(node.rawName))
}

return utils.defineTemplateBodyVisitor(context, {
'VElement' (node) {
if (inIgnoreElement) {
return
}
if (ignores.indexOf(node.name) >= 0) {
if (isIgnoredElement(node)) {
// ignore element name
inIgnoreElement = node
return
Expand Down Expand Up @@ -114,7 +121,7 @@ module.exports = {
},
messageId: 'unexpectedAfterClosingBracket',
data: {
name: node.name,
name: node.rawName,
actual: getPhrase(beforeLineBreaks)
},
fix (fixer) {
Expand Down
34 changes: 33 additions & 1 deletion tests/lib/rules/multiline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,45 @@ tester.run('multiline-html-element-content-newline', rule, {
>content</ignore-tag>
<ignore-tag><div
>content</div></ignore-tag>
<ignore-tag>>content
<ignore-tag>content
content</ignore-tag>
</template>`,
options: [{
ignores: ['ignore-tag']
}]
},
{
code: `
<template>
<IgnoreTag>content</IgnoreTag>
<IgnoreTag
id="test-pre"
>content</IgnoreTag>
<IgnoreTag><div
>content</div></IgnoreTag>
<IgnoreTag>content
content</IgnoreTag>
</template>`,
options: [{
ignores: ['IgnoreTag']
}]
},
{
code: `
<template>
<ignore-tag>content</ignore-tag>
<ignore-tag
id="test-pre"
>content</ignore-tag>
<ignore-tag><div
>content</div></ignore-tag>
<ignore-tag>content
content</ignore-tag>
</template>`,
options: [{
ignores: ['IgnoreTag']
}]
},
// Ignore if no closing brackets
`
<template>
Expand Down