Repository: sasstools/sass-lint
Pull request #106 (2015-09-05 12:59:20)

Fix Space Before Colon and paren issue
Fixes an issue with Space Before Colon that was fixed for the Space After Colon rule. The issue is that colons within parens are not linted.

See issue #98 

DCO 1.1 Signed-off-by: Ben Griffith <gt11687@gmail.com>


Patch:
diff --git a/.travis.yml b/.travis.yml
index 4fee618..79bc77b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ node_js:
   - '0.10'
   - node
   - iojs
-before_install: npm install -g sass-lint
 notifications:
   slack:
     secure: RrEbq2xE1hWdog4AckkaKDnIYYwo5VdjPcFNhRJbn/7KI0fKeZVCKZy1Ww7aaJGth7R7UX415sEV1U6RrjFyhnBb6Sh+rh8fKTvcvuTbENZW45SbtUD+xmgOvb2kfk4PzgD5Q457DpchAZD7W+E+9qr3xI3Uvh4II1uhDmSKiLI=
diff --git a/lib/rules/space-before-colon.js b/lib/rules/space-before-colon.js
index 6d3c4dd..0d82b46 100644
--- a/lib/rules/space-before-colon.js
+++ b/lib/rules/space-before-colon.js
@@ -10,29 +10,31 @@ module.exports = {
   'detect': function (ast, parser) {
     var result = [];
 
-    ast.traverseByType('propertyDelimiter', function (delimiter, i, parent) {
-      var previous = parent.content[i - 1];
+    ast.traverseByTypes(['propertyDelimiter', 'operator'], function (delimiter, i, parent) {
+      if (delimiter.content === ':') {
+        var previous = parent.content[i - 1];
 
-      if (previous.is('space')) {
-        if (!parser.options.include) {
-          result = helpers.addUnique(result, {
-            'ruleId': parser.rule.name,
-            'line': previous.start.line,
-            'column': previous.start.column,
-            'message': 'No space allowed before `:`',
-            'severity': parser.severity
-          });
+        if (previous.is('space')) {
+          if (!parser.options.include) {
+            result = helpers.addUnique(result, {
+              'ruleId': parser.rule.name,
+              'line': previous.start.line,
+              'column': previous.start.column,
+              'message': 'No space allowed before `:`',
+              'severity': parser.severity
+            });
+          }
         }
-      }
-      else {
-        if (parser.options.include) {
-          result = helpers.addUnique(result, {
-            'ruleId': parser.rule.name,
-            'line': delimiter.start.line,
-            'column': delimiter.start.column - 1,
-            'message': 'Space expected before `:`',
-            'severity': parser.severity
-          });
+        else {
+          if (parser.options.include) {
+            result = helpers.addUnique(result, {
+              'ruleId': parser.rule.name,
+              'line': delimiter.start.line,
+              'column': delimiter.start.column - 1,
+              'message': 'Space expected before `:`',
+              'severity': parser.severity
+            });
+          }
         }
       }
     });


Test patch:
diff --git a/tests/cli.js b/tests/cli.js
deleted file mode 100644
index 6b416b7..0000000
--- a/tests/cli.js
+++ /dev/null
@@ -1,42 +0,0 @@
-var assert = require('assert'),
-    should = require('should'),
-    childProcess = require('child_process');
-
-
-describe('CLI', function () {
-  describe('#help', function () {
-    it('should return help instructions', function (done) {
-
-      var command = 'sass-lint -h';
-
-      childProcess.exec(command, function (err, stdout) {
-        if (err) {
-          return done(err);
-        }
-
-        assert(stdout.indexOf('Usage') > 0);
-
-        done(null);
-      });
-
-    });
-  });
-
-  describe('#version', function () {
-    it('should return a version', function (done) {
-
-      var command = 'sass-lint -V';
-
-      childProcess.exec(command, function (err, stdout) {
-        if (err) {
-          return done(err);
-        }
-
-        should(stdout).match(/^[0-9]+.[0-9]+(.[0-9]+)?/);
-
-        done(null);
-      });
-
-    });
-  });
-});
diff --git a/tests/lint.js b/tests/lint.js
index 6afcd0f..f6f3863 100644
--- a/tests/lint.js
+++ b/tests/lint.js
@@ -47,17 +47,6 @@ describe('code style guide', function () {
     done();
   });
 
-  it('tests/cli.js should follow our JavaScript style guide', function (done) {
-    report = cli.executeOnFiles(['tests/cli.js']);
-    if (report.errorCount > 0 || report.warningCount > 0) {
-      console.log(formatter(report.results));
-    }
-
-    should(report.errorCount).equal(0);
-    should(report.warningCount).equal(0);
-    done();
-  });
-
   it('tesst/lint.js should follow our JavaScript style guide', function (done) {
     cli = new eslint.CLIEngine({
       'rules': {
diff --git a/tests/main.js b/tests/main.js
index 7dd3e97..059732a 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -516,7 +516,9 @@ describe('rule', function () {
   //////////////////////////////
   // Space Before Colon
   //////////////////////////////
-  it('space before colon', function (done) {
+
+  // Default
+  it('space before colon - [include: false]', function (done) {
     lintFile('space-before-colon.scss', {
       'options': {
         'merge-default-rules': false
@@ -525,7 +527,26 @@ describe('rule', function () {
         'space-before-colon': 1
       }
     }, function (data) {
-      assert.equal(1, data.warningCount);
+      assert.equal(3, data.warningCount);
+      done();
+    });
+  });
+
+  it('space before colon - [include: true]', function (done) {
+    lintFile('space-before-colon.scss', {
+      'options': {
+        'merge-default-rules': false
+      },
+      'rules': {
+        'space-before-colon': [
+          1,
+          {
+            'include': true
+          }
+        ]
+      }
+    }, function (data) {
+      assert.equal(4, data.warningCount);
       done();
     });
   });
diff --git a/tests/sass/space-before-colon.scss b/tests/sass/space-before-colon.scss
index cccfe9a..368052f 100644
--- a/tests/sass/space-before-colon.scss
+++ b/tests/sass/space-before-colon.scss
@@ -1,4 +1,16 @@
 .foo {
-  content: 'bar';
-  content : 'bar';
+  content :'foo';
 }
+
+.bar {
+  content:'bar';
+}
+
+.baz {
+  @media (max-width :50em) and (orientation:landscape) {
+    content: 'baz';
+  }
+}
+
+$qux: 'qux';
+$norf :'norf';