Skip to content
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

Add externalIgnores option for vue/singleline-html-element-content-newline #2297

Merged
merged 5 commits into from
Nov 29, 2023
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
7 changes: 5 additions & 2 deletions docs/rules/singleline-html-element-content-newline.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ This rule enforces a line break before and after the contents of a singleline el
"vue/singleline-html-element-content-newline": ["error", {
"ignoreWhenNoAttributes": true,
"ignoreWhenEmpty": true,
"ignores": ["pre", "textarea", ...INLINE_ELEMENTS]
"ignores": ["pre", "textarea", ...INLINE_ELEMENTS],
"externalIgnores": []
}]
}
```
Expand All @@ -66,7 +67,9 @@ This rule enforces a line break before and after the contents of a singleline el
- `ignoreWhenEmpty` ... disables reporting when element has no content.
default `true`
- `ignores` ... the configuration for element names to ignore line breaks style.
default `["pre", "textarea", ...INLINE_ELEMENTS]`.
default `["pre", "textarea", ...INLINE_ELEMENTS]`
- `externalIgnores` ... the configuration for external element names to ignore line breaks style, it allows avoiding overwrite the default value of ignores.
default `[]`

::: info
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).
Expand Down
15 changes: 11 additions & 4 deletions lib/rules/singleline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function parseOptions(options) {
return Object.assign(
{
ignores: ['pre', 'textarea', ...INLINE_ELEMENTS],
externalIgnores: [],
ignoreWhenNoAttributes: true,
ignoreWhenEmpty: true
},
Expand Down Expand Up @@ -67,6 +68,12 @@ module.exports = {
items: { type: 'string' },
uniqueItems: true,
additionalItems: false
},
externalIgnores: {
type: 'array',
items: { type: 'string' },
uniqueItems: true,
additionalItems: false
}
},
additionalProperties: false
Expand All @@ -82,7 +89,7 @@ module.exports = {
/** @param {RuleContext} context */
create(context) {
const options = parseOptions(context.options[0])
const ignores = options.ignores
const ignores = new Set([...options.ignores, ...options.externalIgnores])
const ignoreWhenNoAttributes = options.ignoreWhenNoAttributes
const ignoreWhenEmpty = options.ignoreWhenEmpty
const template =
Expand All @@ -96,9 +103,9 @@ module.exports = {
/** @param {VElement} node */
function isIgnoredElement(node) {
return (
ignores.includes(node.name) ||
ignores.includes(casing.pascalCase(node.rawName)) ||
ignores.includes(casing.kebabCase(node.rawName))
ignores.has(node.name) ||
ignores.has(casing.pascalCase(node.rawName)) ||
ignores.has(casing.kebabCase(node.rawName))
)
}

Expand Down
30 changes: 29 additions & 1 deletion tests/lib/rules/singleline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,35 @@ tester.run('singleline-html-element-content-newline', rule, {
<div
id=
""
`
`,
{
code: `
<template>
<pre>content</pre>
<IgnoreTag>content</IgnoreTag>
<IgnoreTag attr>content</IgnoreTag>
<IgnoreTag><span attr>content</span></IgnoreTag>
</template>`,
options: [
{
externalIgnores: ['IgnoreTag']
}
]
},
{
code: `
<template>
<pre>content</pre>
<ignore-tag>content</ignore-tag>
<ignore-tag attr>content</ignore-tag>
<ignore-tag><span attr>content</span></ignore-tag>
</template>`,
options: [
{
externalIgnores: ['IgnoreTag']
}
]
}
],
invalid: [
{
Expand Down
Loading