Skip to content

Fix: singleline-html-element-content-newline case sensitivity #666

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

Merged
merged 1 commit into from
Nov 18, 2018
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
21 changes: 14 additions & 7 deletions lib/rules/singleline-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,8 +21,8 @@ function isSinglelineElement (element) {

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

Expand Down Expand Up @@ -53,10 +54,10 @@ module.exports = {
schema: [{
type: 'object',
properties: {
'ignoreWhenNoAttributes': {
ignoreWhenNoAttributes: {
type: 'boolean'
},
'ignores': {
ignores: {
type: 'array',
items: { type: 'string' },
uniqueItems: true,
Expand All @@ -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
},
fix (fixer) {
const range = [node.startTag.range[1], contentFirst.range[0]]
Expand All @@ -134,7 +141,7 @@ module.exports = {
},
messageId: 'unexpectedBeforeOpeningBracket',
data: {
name: node.name
name: node.rawName
},
fix (fixer) {
const range = [contentLast.range[1], node.endTag.range[0]]
Expand Down
40 changes: 40 additions & 0 deletions tests/lib/rules/singleline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ tester.run('singleline-html-element-content-newline', rule, {
ignores: ['ignore-tag']
}]
},
{
code: `
<template>
<IgnoreTag>content</IgnoreTag>
<IgnoreTag attr>content</IgnoreTag>
<IgnoreTag><span attr>content</span></IgnoreTag>
</template>`,
options: [{
ignores: ['IgnoreTag']
}]
},
{
code: `
<template>
<ignore-tag>content</ignore-tag>
<ignore-tag attr>content</ignore-tag>
<ignore-tag><span attr>content</span></ignore-tag>
</template>`,
options: [{
ignores: ['IgnoreTag']
}]
},
// not target
`
<template>
Expand Down Expand Up @@ -434,6 +456,24 @@ singleline element
errors: [
'Expected 1 line break after opening tag (`<div>`), but no line breaks found.'
]
},
{
code: `
<template>
<Div class="panel">content</Div>
</template>
`,
output: `
<template>
<Div class="panel">
content
</Div>
</template>
`,
errors: [
'Expected 1 line break after opening tag (`<Div>`), but no line breaks found.',
'Expected 1 line break before closing tag (`</Div>`), but no line breaks found.'
]
}
]
})