From 77e5e5be4de59d8c41ff0c63a851234e91b97406 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Mon, 24 Dec 2018 14:20:32 +0100 Subject: [PATCH 1/7] feat: ignore anchor tags in multiline rule --- lib/rules/multiline-html-element-content-newline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/multiline-html-element-content-newline.js b/lib/rules/multiline-html-element-content-newline.js index 5252786ef..5b2377784 100644 --- a/lib/rules/multiline-html-element-content-newline.js +++ b/lib/rules/multiline-html-element-content-newline.js @@ -21,7 +21,7 @@ function isMultilineElement (element) { function parseOptions (options) { return Object.assign({ - ignores: ['pre', 'textarea'], + ignores: ['pre', 'textarea', 'a'], ignoreWhenEmpty: true }, options) } From 600e257e9a9e762f0bff4c2f9367f3813c9c5ad6 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Mon, 24 Dec 2018 14:24:57 +0100 Subject: [PATCH 2/7] Update singleline-html-element-content-newline.js --- lib/rules/singleline-html-element-content-newline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/singleline-html-element-content-newline.js b/lib/rules/singleline-html-element-content-newline.js index 81fb0a248..225827be1 100644 --- a/lib/rules/singleline-html-element-content-newline.js +++ b/lib/rules/singleline-html-element-content-newline.js @@ -21,7 +21,7 @@ function isSinglelineElement (element) { function parseOptions (options) { return Object.assign({ - ignores: ['pre', 'textarea'], + ignores: ['pre', 'textarea', 'a'], ignoreWhenNoAttributes: true, ignoreWhenEmpty: true }, options) From 8cc5364ebc8ef9d931501ea5856a09e06db396f3 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sun, 30 Dec 2018 11:52:46 +0100 Subject: [PATCH 3/7] Update singleline-html-element-content-newline.md --- docs/rules/singleline-html-element-content-newline.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/rules/singleline-html-element-content-newline.md b/docs/rules/singleline-html-element-content-newline.md index 560e0e167..da267cb18 100644 --- a/docs/rules/singleline-html-element-content-newline.md +++ b/docs/rules/singleline-html-element-content-newline.md @@ -53,7 +53,7 @@ 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"] + "ignores": ["pre", "textarea", "a"] }] } ``` @@ -63,7 +63,7 @@ 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"]` + default `["pre", "textarea", "a"]` ### `"ignoreWhenNoAttributes": true` From ab139738b125eba120587c3d45b1155f6d907761 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sun, 30 Dec 2018 11:53:19 +0100 Subject: [PATCH 4/7] Update multiline-html-element-content-newline.md --- docs/rules/multiline-html-element-content-newline.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/rules/multiline-html-element-content-newline.md b/docs/rules/multiline-html-element-content-newline.md index 1e9357a78..79d598d0a 100644 --- a/docs/rules/multiline-html-element-content-newline.md +++ b/docs/rules/multiline-html-element-content-newline.md @@ -76,7 +76,7 @@ This rule enforces a line break before and after the contents of a multiline ele { "vue/multiline-html-element-content-newline": ["error", { "ignoreWhenEmpty": true, - "ignores": ["pre", "textarea"] + "ignores": ["pre", "textarea", "a"] }] } ``` @@ -84,7 +84,7 @@ This rule enforces a line break before and after the contents of a multiline ele - `ignoreWhenEmpty` ... disables reporting when element has no content. default `true` - `ignores` ... the configuration for element names to ignore line breaks style. - default `["pre", "textarea"]` + default `["pre", "textarea", "a"]` ### `"ignores": ["VueComponent", "pre", "textarea"]` From b1e2b6f5d1f929a2204811f9d133d30fa6f7ce8d Mon Sep 17 00:00:00 2001 From: michalsnik Date: Mon, 7 Jan 2019 12:52:52 +0100 Subject: [PATCH 5/7] feat(singleline-html-element-content-newline): Ignore all inline elements --- ...singleline-html-element-content-newline.md | 10 +++-- ...singleline-html-element-content-newline.js | 9 ++++- lib/utils/inline-non-void-elements.json | 40 +++++++++++++++++++ ...singleline-html-element-content-newline.js | 33 ++++++++++++--- 4 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 lib/utils/inline-non-void-elements.json diff --git a/docs/rules/singleline-html-element-content-newline.md b/docs/rules/singleline-html-element-content-newline.md index da267cb18..8fc797846 100644 --- a/docs/rules/singleline-html-element-content-newline.md +++ b/docs/rules/singleline-html-element-content-newline.md @@ -53,7 +53,7 @@ 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", "a"] + "ignores": ["pre", "textarea"] }] } ``` @@ -62,8 +62,12 @@ This rule enforces a line break before and after the contents of a singleline el default `true` - `ignoreWhenEmpty` ... disables reporting when element has no content. default `true` -- `ignores` ... the configuration for element names to ignore line breaks style. - default `["pre", "textarea", "a"]` +- `ignores` ... the configuration for element names to ignore line breaks style. + default `["pre", "textarea"]` + +::: warning + All inline elements, like `a`, `strong` etc. are implicitly ignored by default. +::: ### `"ignoreWhenNoAttributes": true` diff --git a/lib/rules/singleline-html-element-content-newline.js b/lib/rules/singleline-html-element-content-newline.js index 225827be1..bb76f61e1 100644 --- a/lib/rules/singleline-html-element-content-newline.js +++ b/lib/rules/singleline-html-element-content-newline.js @@ -10,6 +10,7 @@ const utils = require('../utils') const casing = require('../utils/casing') +const INLINE_ELEMENTS = require('../utils/inline-non-void-elements.json') // ------------------------------------------------------------------------------ // Helpers @@ -20,11 +21,15 @@ function isSinglelineElement (element) { } function parseOptions (options) { - return Object.assign({ - ignores: ['pre', 'textarea', 'a'], + const newOptions = Object.assign({ + ignores: ['pre', 'textarea'], ignoreWhenNoAttributes: true, ignoreWhenEmpty: true }, options) + + newOptions.ignores = newOptions.ignores.concat(INLINE_ELEMENTS) + + return newOptions } /** diff --git a/lib/utils/inline-non-void-elements.json b/lib/utils/inline-non-void-elements.json new file mode 100644 index 000000000..b3dda839f --- /dev/null +++ b/lib/utils/inline-non-void-elements.json @@ -0,0 +1,40 @@ +[ + "a", + "abbr", + "audio", + "b", + "bdi", + "bdo", + "canvas", + "cite", + "code", + "data", + "del", + "dfn", + "em", + "i", + "iframe", + "ins", + "kbd", + "label", + "map", + "mark", + "noscript", + "object", + "output", + "picture", + "q", + "ruby", + "s", + "samp", + "small", + "span", + "strong", + "sub", + "sup", + "svg", + "time", + "u", + "var", + "video" +] diff --git a/tests/lib/rules/singleline-html-element-content-newline.js b/tests/lib/rules/singleline-html-element-content-newline.js index 679e48682..bc4c0af9c 100644 --- a/tests/lib/rules/singleline-html-element-content-newline.js +++ b/tests/lib/rules/singleline-html-element-content-newline.js @@ -33,39 +33,59 @@ tester.run('singleline-html-element-content-newline', rule, {
content
- `, + + `, ` `, + + `, ` `, + + `, ` `, + + `, ` `, + + `, ` `, + + `, + ` + + `, + ` + + `, + // ignoreWhenNoAttributes: true ` `, + + `, ` `, + + `, + ` + + `, + ` + + `, + ` + + `, + ` + + `, + ` + + `, + ` + + `, ` `, - `
multiline end tag
`, + + `, + ` +
multiline end tag
+ `, + // empty ``, ` @@ -71,12 +140,16 @@ tester.run('multiline-html-element-content-newline', rule, {
- `, + + `, + // self closing ` `, + + `, + // ignores `