Skip to content

Commit ac57432

Browse files
authored
Add externalIgnores option for vue/singleline-html-element-content-newline (#2297)
1 parent a725170 commit ac57432

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

docs/rules/singleline-html-element-content-newline.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ This rule enforces a line break before and after the contents of a singleline el
5656
"vue/singleline-html-element-content-newline": ["error", {
5757
"ignoreWhenNoAttributes": true,
5858
"ignoreWhenEmpty": true,
59-
"ignores": ["pre", "textarea", ...INLINE_ELEMENTS]
59+
"ignores": ["pre", "textarea", ...INLINE_ELEMENTS],
60+
"externalIgnores": []
6061
}]
6162
}
6263
```
@@ -66,7 +67,9 @@ This rule enforces a line break before and after the contents of a singleline el
6667
- `ignoreWhenEmpty` ... disables reporting when element has no content.
6768
default `true`
6869
- `ignores` ... the configuration for element names to ignore line breaks style.
69-
default `["pre", "textarea", ...INLINE_ELEMENTS]`.
70+
default `["pre", "textarea", ...INLINE_ELEMENTS]`
71+
- `externalIgnores` ... the configuration for external element names to ignore line breaks style, it allows avoiding overwrite the default value of ignores.
72+
default `[]`
7073

7174
::: info
7275
All inline non void elements can be found [here](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/utils/inline-non-void-elements.json).

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function parseOptions(options) {
2222
return Object.assign(
2323
{
2424
ignores: ['pre', 'textarea', ...INLINE_ELEMENTS],
25+
externalIgnores: [],
2526
ignoreWhenNoAttributes: true,
2627
ignoreWhenEmpty: true
2728
},
@@ -67,6 +68,12 @@ module.exports = {
6768
items: { type: 'string' },
6869
uniqueItems: true,
6970
additionalItems: false
71+
},
72+
externalIgnores: {
73+
type: 'array',
74+
items: { type: 'string' },
75+
uniqueItems: true,
76+
additionalItems: false
7077
}
7178
},
7279
additionalProperties: false
@@ -82,7 +89,7 @@ module.exports = {
8289
/** @param {RuleContext} context */
8390
create(context) {
8491
const options = parseOptions(context.options[0])
85-
const ignores = options.ignores
92+
const ignores = new Set([...options.ignores, ...options.externalIgnores])
8693
const ignoreWhenNoAttributes = options.ignoreWhenNoAttributes
8794
const ignoreWhenEmpty = options.ignoreWhenEmpty
8895
const template =
@@ -96,9 +103,9 @@ module.exports = {
96103
/** @param {VElement} node */
97104
function isIgnoredElement(node) {
98105
return (
99-
ignores.includes(node.name) ||
100-
ignores.includes(casing.pascalCase(node.rawName)) ||
101-
ignores.includes(casing.kebabCase(node.rawName))
106+
ignores.has(node.name) ||
107+
ignores.has(casing.pascalCase(node.rawName)) ||
108+
ignores.has(casing.kebabCase(node.rawName))
102109
)
103110
}
104111

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,35 @@ tester.run('singleline-html-element-content-newline', rule, {
204204
<div
205205
id=
206206
""
207-
`
207+
`,
208+
{
209+
code: `
210+
<template>
211+
<pre>content</pre>
212+
<IgnoreTag>content</IgnoreTag>
213+
<IgnoreTag attr>content</IgnoreTag>
214+
<IgnoreTag><span attr>content</span></IgnoreTag>
215+
</template>`,
216+
options: [
217+
{
218+
externalIgnores: ['IgnoreTag']
219+
}
220+
]
221+
},
222+
{
223+
code: `
224+
<template>
225+
<pre>content</pre>
226+
<ignore-tag>content</ignore-tag>
227+
<ignore-tag attr>content</ignore-tag>
228+
<ignore-tag><span attr>content</span></ignore-tag>
229+
</template>`,
230+
options: [
231+
{
232+
externalIgnores: ['IgnoreTag']
233+
}
234+
]
235+
}
208236
],
209237
invalid: [
210238
{

0 commit comments

Comments
 (0)