Skip to content

Commit

Permalink
Fix crash in block-no-empty (#4110)
Browse files Browse the repository at this point in the history
* Fix crash in block-no-empty

`block-no-empty` should allow `@import` statements, but it's currently crashing with error "Cannot read property 'every' of undefined"

* use hasBlock helper
  • Loading branch information
ghiculescu authored and hudochenkov committed Jun 22, 2019
1 parent 46b3a44 commit 0bbe61f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/block-no-empty/__tests__/index.js
Expand Up @@ -133,6 +133,9 @@ testRule(rule, {
},
{
code: "a {\n/* foo */\ncolor: pink;\n}"
},
{
code: '@import "foo.css";'
}
],

Expand Down
5 changes: 5 additions & 0 deletions lib/rules/block-no-empty/index.js
Expand Up @@ -2,6 +2,7 @@

const _ = require("lodash");
const beforeBlockString = require("../../utils/beforeBlockString");
const hasBlock = require("../../utils/hasBlock");
const hasEmptyBlock = require("../../utils/hasEmptyBlock");
const optionsMatches = require("../../utils/optionsMatches");
const report = require("../../utils/report");
Expand Down Expand Up @@ -47,6 +48,10 @@ const rule = function(primary, options = {}) {
return;
}

if (!hasBlock(statement)) {
return;
}

const hasCommentsOnly = statement.nodes.every(
node => node.type === "comment"
);
Expand Down

0 comments on commit 0bbe61f

Please sign in to comment.