Repository: sasstools/sass-lint (js)

Issue:
New Rules: No Debug/Warn
Two rules, one for debug, one for warn

Pull request:
Add No Debug and No Warn rules
This pull request adds 2 rules. One to detect and flag up the use of @debug and another to detect and flag up the use of @warn

Closes #37 

DCO 1.1 Signed-off-by: Ben Griffith <gt11687@gmail.com>

Patch:
diff --git a/docs/rules/no-debug.md b/docs/rules/no-debug.md
new file mode 100644
index 0000000..23b0b8e
--- /dev/null
+++ b/docs/rules/no-debug.md
@@ -0,0 +1,11 @@
+# No Debug
+
+Rule `no-debug` will enforce that `@debug` statements are not allowed to be used.
+
+## Examples
+
+When enabled, the following are disallowed:
+
+```scss
+@debug 'foo';
+```
diff --git a/docs/rules/no-warn.md b/docs/rules/no-warn.md
new file mode 100644
index 0000000..e929f77
--- /dev/null
+++ b/docs/rules/no-warn.md
@@ -0,0 +1,11 @@
+# No Warn
+
+Rule `no-warn` will enforce that `@warn` statements are not allowed to be used.
+
+## Examples
+
+When enabled, the following are disallowed:
+
+```scss
+@warn 'foo';
+```
diff --git a/lib/config/sass-lint.yml b/lib/config/sass-lint.yml
index 9eaf8da..622d2ec 100644
--- a/lib/config/sass-lint.yml
+++ b/lib/config/sass-lint.yml
@@ -16,10 +16,12 @@ rules:
   single-line-per-selector: 1
 
   # Disallows
+  no-debug: 1
   no-empty-rulesets: 1
   no-extends: 0
   no-ids: 1
   no-important: 1
+  no-warn: 1
 
   # Style Guide
   indentation: 1
diff --git a/lib/rules/no-debug.js b/lib/rules/no-debug.js
new file mode 100644
index 0000000..cb0d5ea
--- /dev/null
+++ b/lib/rules/no-debug.js
@@ -0,0 +1,27 @@
+'use strict';
+
+var helpers = require('../helpers');
+
+module.exports = {
+  'name': 'no-debug',
+  'defaults': {},
+  'detect': function (ast, parser) {
+    var result = [];
+
+    ast.traverseByType('atkeyword', function (keyword) {
+      keyword.traverse(function (item) {
+        if (item.content === 'debug') {
+          result = helpers.addUnique(result, {
+            'ruleId': parser.rule.name,
+            'line': item.start.line,
+            'column': item.start.column,
+            'message': '@debug not allowed',
+            'severity': parser.severity
+          });
+        }
+      });
+    });
+
+    return result;
+  }
+};
diff --git a/lib/rules/no-warn.js b/lib/rules/no-warn.js
new file mode 100644
index 0000000..65a30d9
--- /dev/null
+++ b/lib/rules/no-warn.js
@@ -0,0 +1,27 @@
+'use strict';
+
+var helpers = require('../helpers');
+
+module.exports = {
+  'name': 'no-warn',
+  'defaults': {},
+  'detect': function (ast, parser) {
+    var result = [];
+
+    ast.traverseByType('atkeyword', function (keyword) {
+      keyword.traverse(function (item) {
+        if (item.content === 'warn') {
+          result = helpers.addUnique(result, {
+            'ruleId': parser.rule.name,
+            'line': item.start.line,
+            'column': item.start.column,
+            'message': '@warn not allowed',
+            'severity': parser.severity
+          });
+        }
+      });
+    });
+
+    return result;
+  }
+};


Test patch:
diff --git a/tests/main.js b/tests/main.js
index b253007..a8f56ec 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -305,4 +305,24 @@ describe('rules', function () {
       done();
     });
   });
+
+  //////////////////////////////
+  // No Debug
+  //////////////////////////////
+  it('no debug', function (done) {
+    lintFile('no-debug.scss', function (data) {
+      assert.equal(3, data.warningCount);
+      done();
+    });
+  });
+
+  //////////////////////////////
+  // No Warn
+  //////////////////////////////
+  it('no warn', function (done) {
+    lintFile('no-warn.scss', function (data) {
+      assert.equal(3, data.warningCount);
+      done();
+    });
+  });
 });
diff --git a/tests/sass/no-debug.scss b/tests/sass/no-debug.scss
new file mode 100644
index 0000000..771a665
--- /dev/null
+++ b/tests/sass/no-debug.scss
@@ -0,0 +1,9 @@
+@debug 'foo';
+
+@function foo {
+  @debug 'bar';
+}
+
+@mixin baz {
+  @debug 'qux';
+}
diff --git a/tests/sass/no-warn.scss b/tests/sass/no-warn.scss
new file mode 100644
index 0000000..45a815b
--- /dev/null
+++ b/tests/sass/no-warn.scss
@@ -0,0 +1,9 @@
+@warn 'foo';
+
+@function foo {
+  @warn 'bar';
+}
+
+@mixin baz {
+  @warn 'qux';
+}