diff --git a/lib/rules/block-no-empty/index.js b/lib/rules/block-no-empty/index.js index d83120e8da..7e25e23be9 100644 --- a/lib/rules/block-no-empty/index.js +++ b/lib/rules/block-no-empty/index.js @@ -49,25 +49,17 @@ const rule = (primary, secondaryOptions) => { root.walkRules(check); root.walkAtRules(check); + /** @typedef {import('postcss').Rule | import('postcss').AtRule} Statement */ + /** - * @param {import('postcss').Rule | import('postcss').AtRule} statement + * @param {Statement} statement */ function check(statement) { if (!hasBlock(statement)) { return; } - const children = statement.nodes.filter((child) => { - if (isComment(child)) { - if (ignoreComments) return false; - - if (isStylelintCommand(child)) return false; - } - - return true; - }); - - if (children.length > 0) { + if (hasNotableChildren(statement)) { return; } @@ -86,6 +78,22 @@ const rule = (primary, secondaryOptions) => { ruleName, }); } + + /** + * @param {Statement} statement + * @returns {boolean} + */ + function hasNotableChildren(statement) { + return statement.nodes.some((child) => { + if (isComment(child)) { + if (ignoreComments) return false; + + if (isStylelintCommand(child)) return false; + } + + return true; + }); + } }; };