Skip to content

Commit 1543f1c

Browse files
committed
refactor: simplify code and avoid unnecessary array allocations
1 parent e6b0ad0 commit 1543f1c

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lib/rules/no-multiple-template-root.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66

77
const utils = require('../utils')
88

9-
/**
10-
* Get all comments that need to be reported
11-
* @param {(HTMLComment | HTMLBogusComment | Comment)[]} comments
12-
* @param {Range[]} elementRanges
13-
* @returns {(HTMLComment | HTMLBogusComment | Comment)[]}
14-
*/
15-
function getReportComments(comments, elementRanges) {
16-
return comments.filter(
17-
(comment) => !elementRanges.some((range) => utils.inRange(range, comment))
18-
)
19-
}
20-
219
module.exports = {
2210
meta: {
2311
type: 'problem',
@@ -65,9 +53,12 @@ module.exports = {
6553
const comments = element.comments.filter((comment) =>
6654
utils.inRange(element, comment)
6755
)
68-
const elementRanges = element.children.map((child) => child.range)
69-
if (disallowComments && comments.length > 0) {
70-
for (const comment of getReportComments(comments, elementRanges)) {
56+
const reportComments = comments.filter(
57+
(comment) =>
58+
!element.children.some((child) => utils.inRange(child, comment))
59+
)
60+
if (disallowComments) {
61+
for (const comment of reportComments) {
7162
context.report({
7263
node: comment,
7364
loc: comment.loc,

0 commit comments

Comments
 (0)