Repository: lesshint/lesshint
Pull request #379 (2017-04-22 18:59:05)

#368 spaceAfterPropertyValue bug with !important
**Which issue, if any, does this resolve?**
#368 


Patch:
diff --git a/lib/linters/space_after_property_value.js b/lib/linters/space_after_property_value.js
index 88c3ae3..b420ce2 100644
--- a/lib/linters/space_after_property_value.js
+++ b/lib/linters/space_after_property_value.js
@@ -12,7 +12,7 @@ module.exports = {
 
         switch (config.style) {
             case 'no_space':
-                if (node.raws.value && /.*\s$/.test(node.raws.value.raw)) {
+                if (/.*\s$/.test(node.raws.important) || node.raws.value && /.*\s$/.test(node.raws.value.raw)) {
                     results.push({
                         column: node.source.start.column + node.prop.length + node.raws.between.length + node.value.length,
                         line: node.source.end.line,
@@ -22,7 +22,7 @@ module.exports = {
 
                 break;
             case 'one_space':
-                if (!node.raws.value) {
+                if (!/.*\s$/.test(node.raws.important) && !node.raws.value) {
                     results.push({
                         column: node.source.start.column + node.prop.length + node.raws.between.length + node.value.length,
                         line: node.source.end.line,


Test patch:
diff --git a/test/specs/linters/space_after_property_value.js b/test/specs/linters/space_after_property_value.js
index 493e6ce..c023596 100644
--- a/test/specs/linters/space_after_property_value.js
+++ b/test/specs/linters/space_after_property_value.js
@@ -26,6 +26,19 @@ describe('lesshint', function () {
             });
         });
 
+        it('should allow a missing space after "!important" when "style" is "no_space"', function () {
+            const source = '.foo { color: red !important; }';
+            const options = {
+                style: 'no_space'
+            };
+
+            return spec.parse(source, function (ast) {
+                const result = spec.linter.lint(options, ast.root.first.first);
+
+                expect(result).to.be.undefined;
+            });
+        });
+
         it('should not allow any space when "style" is "no_space"', function () {
             const source = '.foo { color: red ; }';
             const expected = [{
@@ -45,6 +58,25 @@ describe('lesshint', function () {
             });
         });
 
+        it('should not allow any space after "!important" when "style" is "no_space"', function () {
+            const source = '.foo { color: red !important ; }';
+            const expected = [{
+                column: 18,
+                line: 1,
+                message: 'Semicolon after property value should not be preceded by any space.'
+            }];
+
+            const options = {
+                style: 'no_space'
+            };
+
+            return spec.parse(source, function (ast) {
+                const result = spec.linter.lint(options, ast.root.first.first);
+
+                expect(result).to.deep.equal(expected);
+            });
+        });
+
         it('should allow one space when "style" is "one_space"', function () {
             const source = '.foo { color: red ; }';
             const options = {
@@ -58,6 +90,19 @@ describe('lesshint', function () {
             });
         });
 
+        it('should allow one space after "!important" when "style" is "one_space"', function () {
+            const source = '.foo { color: red !important ; }';
+            const options = {
+                style: 'one_space'
+            };
+
+            return spec.parse(source, function (ast) {
+                const result = spec.linter.lint(options, ast.root.first.first);
+
+                expect(result).to.be.undefined;
+            });
+        });
+
         it('should not allow a missing space when "style" is "one_space"', function () {
             const source = '.foo { color: red; }';
             const expected = [{
@@ -77,6 +122,24 @@ describe('lesshint', function () {
             });
         });
 
+        it('should not allow a missing space after "!important" when "style" is "one_space"', function () {
+            const source = '.foo { color: red !important; }';
+            const expected = [{
+                column: 18,
+                line: 1,
+                message: 'Semicolon after property value should be preceded by one space.'
+            }];
+
+            const options = {
+                style: 'one_space'
+            };
+
+            return spec.parse(source, function (ast) {
+                const result = spec.linter.lint(options, ast.root.first.first);
+
+                expect(result).to.deep.equal(expected);
+            });
+        });
 
         it('should throw on invalid "style" value', function () {
             const source = '.foo { color: red ; }';