Repository: lesshint/lesshint
Pull request #275 (2016-10-28 20:01:31)

Fix for 2.2.0 newlineAfterBlock regression


Patch:
diff --git a/.travis.yml b/.travis.yml
index 881864c..e6e4d84 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,6 +9,7 @@ node_js:
   - "4"
   - "5"
   - "6"
+  - "7"
 
 before_script:
   - node --version
diff --git a/appveyor.yml b/appveyor.yml
index aebc6fb..0ae5a81 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -9,6 +9,7 @@ environment:
     - nodejs_version: "4"
     - nodejs_version: "5"
     - nodejs_version: "6"
+    - nodejs_version: "7"
 
 install:
   - ps: Install-Product node $env:nodejs_version
diff --git a/lib/linters/newline_after_block.js b/lib/linters/newline_after_block.js
index 7ecd469..26099d5 100644
--- a/lib/linters/newline_after_block.js
+++ b/lib/linters/newline_after_block.js
@@ -6,7 +6,7 @@ module.exports = {
     message: 'All blocks should be followed by a new line.',
 
     lint: function newlineAfterBlockLinter (config, node) {
-        var regexp = /\n[ \t]*\n?/;
+        var regexp = /\n[ \t]*\n/;
         var parent = node.parent;
         var prev;
 


Test patch:
diff --git a/test/specs/linters/newline_after_block.js b/test/specs/linters/newline_after_block.js
index 62c1276..3e8384f 100644
--- a/test/specs/linters/newline_after_block.js
+++ b/test/specs/linters/newline_after_block.js
@@ -13,18 +13,34 @@ describe('lesshint', function () {
             });
         });
 
-        it('should not allow adjacent blocks without a new line', function () {
-            var source = '';
+        it('should not allow adjacent blocks without a blank line', function () {
+            var source = [
+                '.foo { color: red; }',
+                '.bar { color: blue; }'
+            ];
             var expected = [{
                 message: 'All blocks should be followed by a new line.'
             }];
 
-            source += '.foo {';
-            source += '    color: red;';
-            source += '}';
-            source += '.bar {';
-            source += '    color: blue;';
-            source += '}';
+            source = source.join('\n');
+
+            return spec.parse(source, function (ast) {
+                var result = spec.linter.lint({}, ast.root.last);
+
+                expect(result).to.deep.equal(expected);
+            });
+        });
+
+        it('should not allow adjacent blocks on the same line', function () {
+            var source = [
+                '.foo { color: red; }',
+                '.bar { color: blue; }'
+            ];
+            var expected = [{
+                message: 'All blocks should be followed by a new line.'
+            }];
+
+            source = source.join('');
 
             return spec.parse(source, function (ast) {
                 var result = spec.linter.lint({}, ast.root.last);
@@ -34,15 +50,12 @@ describe('lesshint', function () {
         });
 
         it('should allow adjacent blocks with a new line', function () {
-            var source = '';
+            var source = [
+                '.foo { color: red; }',
+                '.bar { color: blue; }'
+            ];
 
-            source += '.foo {';
-            source += '    color: red;';
-            source += '}';
-            source += '\n\n';
-            source += '.bar {';
-            source += '    color: blue;';
-            source += '}';
+            source = source.join('\n\n');
 
             return spec.parse(source, function (ast) {
                 var result = spec.linter.lint({}, ast.root.last);
@@ -52,16 +65,15 @@ describe('lesshint', function () {
         });
 
         it('should not allow adjacent blocks without a new line', function () {
-            var source = '';
+            var source = [
+                '.bar { color: blue; }',
+                '@media (screen) {}'
+            ];
             var expected = [{
                 message: 'All blocks should be followed by a new line.'
             }];
 
-            source += '.bar {';
-            source += '    color: blue;';
-            source += '}';
-            source += '@media (screen) {';
-            source += '}';
+            source = source.join('');
 
             return spec.parse(source, function (ast) {
                 var result = spec.linter.lint({}, ast.root.last);
@@ -71,14 +83,12 @@ describe('lesshint', function () {
         });
 
         it('should allow adjacent at-rule blocks with a new line', function () {
-            var source = '';
+            var source = [
+                '.bar { color: blue; }',
+                '@media (screen) {}'
+            ];
 
-            source += '.bar {';
-            source += '    color: blue;';
-            source += '}';
-            source += '\n\n';
-            source += '@media (screen) {';
-            source += '}';
+            source = source.join('\n\n');
 
             return spec.parse(source, function (ast) {
                 var result = spec.linter.lint({}, ast.root.last);