From db2d412049cc2494fe4f1f62d9919e743be5e685 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:08:05 +0800
Subject: [PATCH 1/5] add `externalIgnores` option for
`vue/singleline-html-element-content-newline`
---
...singleline-html-element-content-newline.js | 9 +++++-
...singleline-html-element-content-newline.js | 30 ++++++++++++++++++-
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/lib/rules/singleline-html-element-content-newline.js b/lib/rules/singleline-html-element-content-newline.js
index 1f8b9ef2c..e11716e71 100644
--- a/lib/rules/singleline-html-element-content-newline.js
+++ b/lib/rules/singleline-html-element-content-newline.js
@@ -22,6 +22,7 @@ function parseOptions(options) {
return Object.assign(
{
ignores: ['pre', 'textarea', ...INLINE_ELEMENTS],
+ externalIgnores: [],
ignoreWhenNoAttributes: true,
ignoreWhenEmpty: true
},
@@ -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
@@ -82,7 +89,7 @@ module.exports = {
/** @param {RuleContext} context */
create(context) {
const options = parseOptions(context.options[0])
- const ignores = options.ignores
+ const ignores = options.ignores.concat(options.externalIgnores)
const ignoreWhenNoAttributes = options.ignoreWhenNoAttributes
const ignoreWhenEmpty = options.ignoreWhenEmpty
const template =
diff --git a/tests/lib/rules/singleline-html-element-content-newline.js b/tests/lib/rules/singleline-html-element-content-newline.js
index 5bf2c9392..c93e96e42 100644
--- a/tests/lib/rules/singleline-html-element-content-newline.js
+++ b/tests/lib/rules/singleline-html-element-content-newline.js
@@ -204,7 +204,35 @@ tester.run('singleline-html-element-content-newline', rule, {
+
content
+
content
+
content
+
content
+ `,
+ options: [
+ {
+ externalIgnores: ['IgnoreTag']
+ }
+ ]
+ },
+ {
+ code: `
+
+ content
+ content
+ content
+ content
+ `,
+ options: [
+ {
+ externalIgnores: ['IgnoreTag']
+ }
+ ]
+ }
],
invalid: [
{
From ed4ed1031f29b49efaf1ea167e91d45fc97a7101 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:18:38 +0800
Subject: [PATCH 2/5] update docs
---
docs/rules/singleline-html-element-content-newline.md | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/docs/rules/singleline-html-element-content-newline.md b/docs/rules/singleline-html-element-content-newline.md
index 8e6dadf3d..2cc64f399 100644
--- a/docs/rules/singleline-html-element-content-newline.md
+++ b/docs/rules/singleline-html-element-content-newline.md
@@ -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": []
}]
}
```
@@ -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).
From 934ca8b0e107536be12d3e5d3b7a09e76ff69da7 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:28:15 +0800
Subject: [PATCH 3/5] lint and fix code
---
lib/rules/singleline-html-element-content-newline.js | 8 ++++----
tests/integrations/eslint-plugin-import.js | 10 ++++------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/lib/rules/singleline-html-element-content-newline.js b/lib/rules/singleline-html-element-content-newline.js
index e11716e71..d89fd940a 100644
--- a/lib/rules/singleline-html-element-content-newline.js
+++ b/lib/rules/singleline-html-element-content-newline.js
@@ -89,7 +89,7 @@ module.exports = {
/** @param {RuleContext} context */
create(context) {
const options = parseOptions(context.options[0])
- const ignores = options.ignores.concat(options.externalIgnores)
+ const ignores = new Set([...options.ignores, ...options.externalIgnores])
const ignoreWhenNoAttributes = options.ignoreWhenNoAttributes
const ignoreWhenEmpty = options.ignoreWhenEmpty
const template =
@@ -103,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))
)
}
diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js
index 4e26508ce..a408fdcdd 100644
--- a/tests/integrations/eslint-plugin-import.js
+++ b/tests/integrations/eslint-plugin-import.js
@@ -30,12 +30,10 @@ describe('Integration with eslint-plugin-import', () => {
if (
!semver.satisfies(
process.version,
- require(
- path.join(
- __dirname,
- 'eslint-plugin-import/node_modules/eslint/package.json'
- )
- ).engines.node
+ require(path.join(
+ __dirname,
+ 'eslint-plugin-import/node_modules/eslint/package.json'
+ )).engines.node
)
) {
return
From 534857f1aeb93dbdee1362bea73f2a5275637196 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:32:31 +0800
Subject: [PATCH 4/5] lint and fix code
---
tests/integrations/eslint-plugin-import.js | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js
index a408fdcdd..638d7a174 100644
--- a/tests/integrations/eslint-plugin-import.js
+++ b/tests/integrations/eslint-plugin-import.js
@@ -30,10 +30,12 @@ describe('Integration with eslint-plugin-import', () => {
if (
!semver.satisfies(
process.version,
- require(path.join(
- __dirname,
- 'eslint-plugin-import/node_modules/eslint/package.json'
- )).engines.node
+ require(
+ path.join(
+ __dirname,
+ 'eslint-plugin-import/node_modules/eslint/package.json'
+ )
+ ).engines.node
)
) {
return
@@ -41,4 +43,4 @@ describe('Integration with eslint-plugin-import', () => {
cp.execSync(`${ESLINT} a.vue`, { stdio: 'inherit' })
})
-})
+})
\ No newline at end of file
From 5e93ba2c2e1813d135a9a30186fe420944912ef3 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:33:12 +0800
Subject: [PATCH 5/5] lint and fix code
---
tests/integrations/eslint-plugin-import.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js
index 638d7a174..4e26508ce 100644
--- a/tests/integrations/eslint-plugin-import.js
+++ b/tests/integrations/eslint-plugin-import.js
@@ -43,4 +43,4 @@ describe('Integration with eslint-plugin-import', () => {
cp.execSync(`${ESLINT} a.vue`, { stdio: 'inherit' })
})
-})
\ No newline at end of file
+})