Skip to content

Commit

Permalink
Refactor block-no-empty rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Oct 1, 2022
1 parent 3d55f7f commit 9e44543
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/rules/block-no-empty/index.js
Expand Up @@ -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;
}

Expand All @@ -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;
});
}
};
};

Expand Down

0 comments on commit 9e44543

Please sign in to comment.