Skip to content

Commit 5f57e49

Browse files
author
David Lomas
committed
Add for singleline- version of rule; update tests
1 parent f2d4d6a commit 5f57e49

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function parseOptions(options) {
2424
ignores: ['pre', 'textarea', ...INLINE_ELEMENTS],
2525
externalIgnores: [],
2626
ignoreWhenNoAttributes: true,
27-
ignoreWhenEmpty: true
27+
ignoreWhenEmpty: true,
28+
ignoreComments: false
2829
},
2930
options
3031
)
@@ -63,6 +64,9 @@ module.exports = {
6364
ignoreWhenEmpty: {
6465
type: 'boolean'
6566
},
67+
ignoreComments: {
68+
type: 'boolean'
69+
},
6670
ignores: {
6771
type: 'array',
6872
items: { type: 'string' },
@@ -92,6 +96,7 @@ module.exports = {
9296
const ignores = new Set([...options.ignores, ...options.externalIgnores])
9397
const ignoreWhenNoAttributes = options.ignoreWhenNoAttributes
9498
const ignoreWhenEmpty = options.ignoreWhenEmpty
99+
const ignoreComments = options.ignoreComments
95100
const sourceCode = context.getSourceCode()
96101
const template =
97102
sourceCode.parserServices.getTemplateBodyTokenStore &&
@@ -136,7 +141,7 @@ module.exports = {
136141

137142
/** @type {SourceCode.CursorWithCountOptions} */
138143
const getTokenOption = {
139-
includeComments: true,
144+
includeComments: !ignoreComments,
140145
filter: (token) => token.type !== 'HTMLWhitespace'
141146
}
142147
if (

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ tester.run('multiline-html-element-content-newline', rule, {
169169
</template>`,
170170
options: [{ allowEmptyLines: true }]
171171
},
172-
173172
{
174173
code: `
175174
<template>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ tester.run('singleline-html-element-content-newline', rule, {
229229
externalIgnores: ['IgnoreTag']
230230
}
231231
]
232+
},
233+
// Ignore comments
234+
{
235+
code: `
236+
<template>
237+
<div><!-- comment --></div>
238+
<div attr><!-- comment --></div>
239+
</template>`,
240+
options: [
241+
{
242+
ignoreComments: true
243+
}
244+
]
232245
}
233246
],
234247
invalid: [

0 commit comments

Comments
 (0)