Repository: rwjblue/ember-template-lint
Pull request #131 (2016-11-08 04:06:27)

Add `ignore` configuration option.
Fixes https://github.com/rwjblue/ember-template-lint/issues/32.


Patch:
diff --git a/README.md b/README.md
index 13fd98e..5d139e1 100644
--- a/README.md
+++ b/README.md
@@ -102,6 +102,7 @@ The following properties are allowed in the root of the `.template-lintrc.js` co
 * `pending` -- An array of module id's that are still pending. The goal of this array is to allow incorporating template linting
   into an existing project, without changing every single template file. You can add all existing templates to this `pending` listing
   and slowly work through them, while at the same time ensuring that new templates added to the project pass all defined rules.
+* `ignore` -- An array of module id's that are to be completely ignored.
 
 ## Rules
 
diff --git a/lib/config/recommended.js b/lib/config/recommended.js
index f5b6870..629fb17 100644
--- a/lib/config/recommended.js
+++ b/lib/config/recommended.js
@@ -15,5 +15,6 @@ module.exports = {
     'deprecated-inline-view-helper': true
   },
 
-  pending: []
+  pending: [],
+  ignore: []
 };
diff --git a/lib/get-config.js b/lib/get-config.js
index 9c26e71..e230b29 100644
--- a/lib/get-config.js
+++ b/lib/get-config.js
@@ -6,7 +6,7 @@ var existsSync = require('exists-sync');
 var chalk = require('chalk');
 var rules = require('./rules');
 
-var KNOWN_ROOT_PROPERTIES = ['extends', 'rules', 'pending'];
+var KNOWN_ROOT_PROPERTIES = ['extends', 'rules', 'pending', 'ignore'];
 
 function readConfigFromDisk(options) {
   var providedConfigPath = options.configPath;
@@ -22,6 +22,7 @@ function readConfigFromDisk(options) {
 function ensureRootProperties(config) {
   config.rules = config.rules || {};
   config.pending = config.pending || [];
+  config.ignore = config.ignore || [];
 }
 
 function migrateRulesFromRoot(config, options) {
diff --git a/lib/index.js b/lib/index.js
index 7824cad..3067bd6 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -58,10 +58,12 @@ Linter.prototype = {
     return astPlugins;
   },
 
-  pendingStatusForModule: function(moduleId) {
-    var pendingList = this.config.pending;
-    for (var i = 0; i < pendingList.length; i++) {
-      var item = pendingList[i];
+  statusForModule: function(type, moduleId) {
+    var list = this.config[type];
+    if (!list) { return false; }
+
+    for (var i = 0; i < list.length; i++) {
+      var item = list[i];
 
       if (typeof item === 'string' && moduleId === item) {
         return true;
@@ -75,7 +77,12 @@ Linter.prototype = {
 
   verify: function(options) {
     var messages = [];
-    var pendingStatus = this.pendingStatusForModule(options.moduleId);
+    var pendingStatus = this.statusForModule('pending', options.moduleId);
+    var shouldIgnore = this.statusForModule('ignore', options.moduleId);
+
+    if (shouldIgnore) {
+      return messages;
+    }
 
     var pluginConfig = {
       results: messages,


Test patch:
diff --git a/test/acceptance-test.js b/test/acceptance-test.js
index a3048ea..00abbf2 100644
--- a/test/acceptance-test.js
+++ b/test/acceptance-test.js
@@ -280,9 +280,28 @@ describe('public api', function() {
 
       assert.deepEqual(result, [expected]);
     });
+
+    it('does not include errors when marked as ignored', function() {
+      linter = new Linter({
+        console: mockConsole,
+        config: {
+          rules: { 'bare-strings': true, 'block-indentation': true },
+          ignore: [ 'some/path/here' ]
+        }
+      });
+
+      var template = '<div>bare string</div>';
+      var result = linter.verify({
+        source: template,
+        moduleId: 'some/path/here'
+      });
+
+      assert.deepEqual(result, []);
+    });
+
   });
 
-  describe('Linter.prototype.pendingStatusForModule', function() {
+  describe('Linter.prototype.statusForModule', function() {
     it('returns true when the provided moduleId is listed in `pending`', function() {
       var linter = new Linter({
         console: mockConsole,
@@ -294,9 +313,9 @@ describe('public api', function() {
         }
       });
 
-      assert(linter.pendingStatusForModule('some/path/here'));
-      assert(linter.pendingStatusForModule('foo/bar/baz'));
-      assert(!linter.pendingStatusForModule('some/other/path'));
+      assert(linter.statusForModule('pending', 'some/path/here'));
+      assert(linter.statusForModule('pending', 'foo/bar/baz'));
+      assert(!linter.statusForModule('pending', 'some/other/path'));
     });
   });
 });
diff --git a/test/unit/get-config-test.js b/test/unit/get-config-test.js
index f5f7528..b20aa96 100644
--- a/test/unit/get-config-test.js
+++ b/test/unit/get-config-test.js
@@ -72,7 +72,7 @@ describe('get-config', function() {
   });
 
   it('migrates rules in the config root into `rules` property', function() {
-    var expected = { pending: [], rules: { 'bare-strings': true }};
+    var expected = { ignore: [], pending: [], rules: { 'bare-strings': true }};
     var actual = getConfig({
       console: { log: function() { }},
       config: {