Repository: lesshint/lesshint
Pull request #210 (2016-07-12 16:38:55)

more fixes for #200, emptyRule and spaceBeforeBrace
@wareczek this should take care of it


Patch:
diff --git a/lib/linters/empty_rule.js b/lib/linters/empty_rule.js
index 0cba61d..af32a37 100644
--- a/lib/linters/empty_rule.js
+++ b/lib/linters/empty_rule.js
@@ -19,7 +19,7 @@ module.exports = {
          */
         node.walk(function (child) {
             // console.log(child);
-            if (child.type === 'decl' ||
+            if (child.type === 'decl' || child.type === 'atrule' ||
                (child.type === 'rule' && child.ruleWithoutBody)) {
                 hasDeclarations = true;
                 return false;
diff --git a/lib/linters/space_before_brace.js b/lib/linters/space_before_brace.js
index b0fab52..9abde89 100644
--- a/lib/linters/space_before_brace.js
+++ b/lib/linters/space_before_brace.js
@@ -21,8 +21,12 @@ module.exports = {
             throw new Error('Invalid setting value for spaceBeforeBrace: ' + config.style);
         }
 
-        // if the node is a bodiless rule, or it's an import statement, bail.
-        if (node.ruleWithoutBody || node.name === 'import') {
+        // if the node is a bodiless rule, or it's an import statement, or we
+        // are dealing with an atrule without a body, bail.
+        if (node.ruleWithoutBody || node.name === 'import' ||
+           // hopefully node.ruleWithoutBody will be implemented on AtRule nodes
+           // in the future: https://github.com/webschik/postcss-less/issues/55
+           (node.type === 'atrule' && !node.nodes)) {
             return;
         }
 


Test patch:
diff --git a/test/specs/linters/empty_rule.js b/test/specs/linters/empty_rule.js
index a353697..143c51d 100644
--- a/test/specs/linters/empty_rule.js
+++ b/test/specs/linters/empty_rule.js
@@ -59,8 +59,8 @@ describe('lesshint', function () {
             });
         });
 
-        it('should not check mixin calls', function () {
-            var source = '.mixin();';
+        it('should allow rules with only atrules (#200)', function () {
+            var source = '.foo { @atrule(); }';
 
             return spec.parse(source, function (ast) {
                 var result = spec.linter.lint({}, ast.root.first);
@@ -79,6 +79,16 @@ describe('lesshint', function () {
             });
         });
 
+        it('should not check atrule calls (#200)', function () {
+            var source = '@atrule();';
+
+            return spec.parse(source, function (ast) {
+                var result = spec.linter.lint({}, ast.root.first);
+
+                expect(result).to.be.undefined;
+            });
+        });
+
         it('should not check mixin definitions', function () {
             var source = '.header-def(@rules) {h1,h2,h3,h4,h5,h6 {@rules();}}';
 
diff --git a/test/specs/linters/space_before_brace.js b/test/specs/linters/space_before_brace.js
index d2b9088..da648fb 100644
--- a/test/specs/linters/space_before_brace.js
+++ b/test/specs/linters/space_before_brace.js
@@ -364,6 +364,19 @@ describe('lesshint', function () {
             });
         });
 
+        it('should ignore atrule nodes without a following block', function () {
+            var source = '@foo();';
+            var options = {
+                style: 'one_space'
+            };
+
+            return spec.parse(source, function (ast) {
+                var result = spec.linter.lint(options, ast.root.first);
+
+                expect(result).to.be.undefined;
+            });
+        });
+
         it('should throw on invalid "style" value', function () {
             var source = '.foo{}';
             var options = {