Skip to content

Commit 276fe20

Browse files
ota-meshimichalsnik
authored andcommitted
Fix: singleline-html-element-content-newline case sensitivity (#666)
1 parent 07a7d9f commit 276fe20

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

lib/rules/singleline-html-element-content-newline.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// ------------------------------------------------------------------------------
1010

1111
const utils = require('../utils')
12+
const casing = require('../utils/casing')
1213

1314
// ------------------------------------------------------------------------------
1415
// Helpers
@@ -20,8 +21,8 @@ function isSinglelineElement (element) {
2021

2122
function parseOptions (options) {
2223
return Object.assign({
23-
'ignores': ['pre', 'textarea'],
24-
'ignoreWhenNoAttributes': true
24+
ignores: ['pre', 'textarea'],
25+
ignoreWhenNoAttributes: true
2526
}, options)
2627
}
2728

@@ -53,10 +54,10 @@ module.exports = {
5354
schema: [{
5455
type: 'object',
5556
properties: {
56-
'ignoreWhenNoAttributes': {
57+
ignoreWhenNoAttributes: {
5758
type: 'boolean'
5859
},
59-
'ignores': {
60+
ignores: {
6061
type: 'array',
6162
items: { type: 'string' },
6263
uniqueItems: true,
@@ -80,12 +81,18 @@ module.exports = {
8081

8182
let inIgnoreElement
8283

84+
function isIgnoredElement (node) {
85+
return ignores.includes(node.name) ||
86+
ignores.includes(casing.pascalCase(node.rawName)) ||
87+
ignores.includes(casing.kebabCase(node.rawName))
88+
}
89+
8390
return utils.defineTemplateBodyVisitor(context, {
8491
'VElement' (node) {
8592
if (inIgnoreElement) {
8693
return
8794
}
88-
if (ignores.indexOf(node.name) >= 0) {
95+
if (isIgnoredElement(node)) {
8996
// ignore element name
9097
inIgnoreElement = node
9198
return
@@ -114,7 +121,7 @@ module.exports = {
114121
},
115122
messageId: 'unexpectedAfterClosingBracket',
116123
data: {
117-
name: node.name
124+
name: node.rawName
118125
},
119126
fix (fixer) {
120127
const range = [node.startTag.range[1], contentFirst.range[0]]
@@ -134,7 +141,7 @@ module.exports = {
134141
},
135142
messageId: 'unexpectedBeforeOpeningBracket',
136143
data: {
137-
name: node.name
144+
name: node.rawName
138145
},
139146
fix (fixer) {
140147
const range = [contentLast.range[1], node.endTag.range[0]]

tests/lib/rules/singleline-html-element-content-newline.js

+40
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,28 @@ tester.run('singleline-html-element-content-newline', rule, {
141141
ignores: ['ignore-tag']
142142
}]
143143
},
144+
{
145+
code: `
146+
<template>
147+
<IgnoreTag>content</IgnoreTag>
148+
<IgnoreTag attr>content</IgnoreTag>
149+
<IgnoreTag><span attr>content</span></IgnoreTag>
150+
</template>`,
151+
options: [{
152+
ignores: ['IgnoreTag']
153+
}]
154+
},
155+
{
156+
code: `
157+
<template>
158+
<ignore-tag>content</ignore-tag>
159+
<ignore-tag attr>content</ignore-tag>
160+
<ignore-tag><span attr>content</span></ignore-tag>
161+
</template>`,
162+
options: [{
163+
ignores: ['IgnoreTag']
164+
}]
165+
},
144166
// not target
145167
`
146168
<template>
@@ -434,6 +456,24 @@ singleline element
434456
errors: [
435457
'Expected 1 line break after opening tag (`<div>`), but no line breaks found.'
436458
]
459+
},
460+
{
461+
code: `
462+
<template>
463+
<Div class="panel">content</Div>
464+
</template>
465+
`,
466+
output: `
467+
<template>
468+
<Div class="panel">
469+
content
470+
</Div>
471+
</template>
472+
`,
473+
errors: [
474+
'Expected 1 line break after opening tag (`<Div>`), but no line breaks found.',
475+
'Expected 1 line break before closing tag (`</Div>`), but no line breaks found.'
476+
]
437477
}
438478
]
439479
})

0 commit comments

Comments
 (0)