diff --git a/lib/rules/singleline-html-element-content-newline.js b/lib/rules/singleline-html-element-content-newline.js index 309f789d4..7e8a54084 100644 --- a/lib/rules/singleline-html-element-content-newline.js +++ b/lib/rules/singleline-html-element-content-newline.js @@ -9,6 +9,7 @@ // ------------------------------------------------------------------------------ const utils = require('../utils') +const casing = require('../utils/casing') // ------------------------------------------------------------------------------ // Helpers @@ -20,8 +21,8 @@ function isSinglelineElement (element) { function parseOptions (options) { return Object.assign({ - 'ignores': ['pre', 'textarea'], - 'ignoreWhenNoAttributes': true + ignores: ['pre', 'textarea'], + ignoreWhenNoAttributes: true }, options) } @@ -53,10 +54,10 @@ module.exports = { schema: [{ type: 'object', properties: { - 'ignoreWhenNoAttributes': { + ignoreWhenNoAttributes: { type: 'boolean' }, - 'ignores': { + ignores: { type: 'array', items: { type: 'string' }, uniqueItems: true, @@ -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 @@ -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]] @@ -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]] diff --git a/tests/lib/rules/singleline-html-element-content-newline.js b/tests/lib/rules/singleline-html-element-content-newline.js index dcb65fd7d..a5c9bce03 100644 --- a/tests/lib/rules/singleline-html-element-content-newline.js +++ b/tests/lib/rules/singleline-html-element-content-newline.js @@ -141,6 +141,28 @@ tester.run('singleline-html-element-content-newline', rule, { ignores: ['ignore-tag'] }] }, + { + code: ` + `, + options: [{ + ignores: ['IgnoreTag'] + }] + }, + { + code: ` + `, + options: [{ + ignores: ['IgnoreTag'] + }] + }, // not target `