From a46fc7b11ed10b9790f19122fcd96b871e5f475b Mon Sep 17 00:00:00 2001 From: David Lomas Date: Wed, 23 Oct 2024 12:00:07 +0100 Subject: [PATCH 1/5] Add option to treat comments as empty space when enforcing rules --- .../multiline-html-element-content-newline.js | 11 +++++-- .../multiline-html-element-content-newline.js | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/rules/multiline-html-element-content-newline.js b/lib/rules/multiline-html-element-content-newline.js index afe89bd2f..5cd272a42 100644 --- a/lib/rules/multiline-html-element-content-newline.js +++ b/lib/rules/multiline-html-element-content-newline.js @@ -23,7 +23,8 @@ function parseOptions(options) { { ignores: ['pre', 'textarea', ...INLINE_ELEMENTS], ignoreWhenEmpty: true, - allowEmptyLines: false + allowEmptyLines: false, + ignoreComments: false }, options ) @@ -80,7 +81,10 @@ module.exports = { }, allowEmptyLines: { type: 'boolean' - } + }, + ignoreComments: { + type: 'boolean' + }, }, additionalProperties: false } @@ -98,6 +102,7 @@ module.exports = { const ignores = options.ignores const ignoreWhenEmpty = options.ignoreWhenEmpty const allowEmptyLines = options.allowEmptyLines + const ignoreComments = options.ignoreComments const sourceCode = context.getSourceCode() const template = sourceCode.parserServices.getTemplateBodyTokenStore && @@ -149,7 +154,7 @@ module.exports = { * @type {SourceCode.CursorWithCountOptions} */ const getTokenOption = { - includeComments: true, + includeComments: !ignoreComments, filter: (token) => token.type !== 'HTMLWhitespace' } if ( diff --git a/tests/lib/rules/multiline-html-element-content-newline.js b/tests/lib/rules/multiline-html-element-content-newline.js index 36aa9cfe4..892004dcd 100644 --- a/tests/lib/rules/multiline-html-element-content-newline.js +++ b/tests/lib/rules/multiline-html-element-content-newline.js @@ -170,6 +170,16 @@ tester.run('multiline-html-element-content-newline', rule, { options: [{ allowEmptyLines: true }] }, + { + code: ` + `, + options: [{ allowEmptyLines: true, ignoreComments: true }] + }, + // self closing ` `, options: [{ allowEmptyLines: true }] }, - { code: `