Repository: rwjblue/ember-cli-template-lint (js)

Issue:
Make symbols free from bare string rule
Sometimes we require symbols such as : , ( , ) , + , - ,etc., to be displayed in the web page. For that we can go for using bare strings instead of translating for each symbols. 
For eg:
`{{translate "firstname.label"}} : {{input type="text"}}`
`{{translate "requestGradePoint"}} : {{input type="number"}} / {{input type="number"}}` 
`<p>&times;</p>` for 'x'


Pull request description:
Add whitelist to bare-strings.
Fixes #53.

Patch:
diff --git a/README.md b/README.md
index 27b7362..886c4e6 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,11 @@ This rule forbids the following:
 <h2>Some string here!</h2>
 ```
 
+The following values are valid configuration:
+
+  * boolean -- `true` for enabled / `false` for disabled
+  * array -- an array of whitelisted strings
+
 
 #### block-indentation
 
diff --git a/ext/plugins/lint-bare-strings.js b/ext/plugins/lint-bare-strings.js
index c2416db..df3f26b 100644
--- a/ext/plugins/lint-bare-strings.js
+++ b/ext/plugins/lint-bare-strings.js
@@ -1,13 +1,22 @@
 'use strict';
 
-// Disallows the use of bare strings in a template
-//
-// passes:
-// <div>{{evaluatesToAString}}</div>
-// <div>{{'A string'}}</div>
-//
-// breaks:
-// <div>A bare string</div>
+/*
+ Disallows the use of bare strings in a template
+
+ ```
+ {{! good }}
+ <div>{{evaluatesToAString}}</div>
+ <div>{{'A string'}}</div>
+
+ {{! bad}}
+ <div>A bare string</div>
+ ```
+
+ The following values are valid configuration:
+
+   * boolean -- `true` for enabled / `false` for disabled
+   * array -- an array of whitelisted strings
+ */
 
 var calculateLocationDisplay = require('../helpers/calculate-location-display');
 var buildPlugin = require('./base');
@@ -15,6 +24,31 @@ var buildPlugin = require('./base');
 module.exports = function(addonContext) {
   var LogStaticStrings = buildPlugin(addonContext, 'bare-strings');
 
+  LogStaticStrings.prototype.parseConfig = function(config) {
+    var configType = typeof config;
+
+    var errorMessage = 'The bare-strings rule accepts one of the following values.\n ' +
+          '  * boolean - `true` to enable / `false` to disable\n' +
+          '  * array -- an array of strings to whitelist\n' +
+          '\nYou specified `' + JSON.stringify(config) + '`';
+
+    switch (configType) {
+    case 'boolean':
+      return config;
+    case 'object':
+      if (Array.isArray(config)) {
+        return config;
+      } else {
+        throw new Error(errorMessage);
+      }
+    case 'undefined':
+      // default value is enabled for now
+      return true;
+    default:
+      throw new Error(errorMessage);
+    }
+  };
+
   LogStaticStrings.prototype.process = function(node) {
     var locationDisplay = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.start);
     var warning = 'Non-translated string used ' + locationDisplay + ' `' + node.chars + '`';
@@ -23,7 +57,20 @@ module.exports = function(addonContext) {
   };
 
   LogStaticStrings.prototype.detect = function(node) {
-    return node.type === 'TextNode' && !node.raw && node.chars.trim() !== '';
+    if (node.type !== 'TextNode') { return false;}
+
+    var string = node.chars;
+    var whitelist = Array.isArray(this.config) ? this.config : null;
+
+    if (whitelist) {
+      for (var i = 0; i < whitelist.length; i++) {
+        var entry = whitelist[i];
+
+        string = string.replace(entry, '');
+      }
+    }
+
+    return string.trim() !== '';
   };
 
   return LogStaticStrings;
diff --git a/ext/plugins/lint-block-indentation.js b/ext/plugins/lint-block-indentation.js
index b541059..db4762b 100644
--- a/ext/plugins/lint-block-indentation.js
+++ b/ext/plugins/lint-block-indentation.js
@@ -177,18 +177,7 @@ module.exports = function(addonContext) {
       if (expectedStartColumn !== childStartColumn) {
         var isElementNode = child.type === 'ElementNode';
         var displayName = isElementNode ? child.tag : child.path.original;
-        var display;
-
-        if (isElementNode) {
-          display = '<' + displayName + '>';
-        } else if (child.type === 'BlockStatement'){
-          display = '{{#' + displayName + '}}';
-        } else if (child.type === 'MustacheStatement') {
-          display = '{{' + displayName + '}}';
-        } else {
-          display = displayName;
-        }
-
+        var display = isElementNode ? '<' + displayName + '>' : '{{#' + displayName + '}}';
         var startLocation = calculateLocationDisplay(this.options.moduleName, child.loc && child.loc.start);
 
         var warning = 'Incorrect indentation for `' + display + '` beginning at ' + startLocation +


Test patch:
diff --git a/node-tests/unit/plugins/lint-bare-strings-test.js b/node-tests/unit/plugins/lint-bare-strings-test.js
index 92951f9..d24f8fd 100644
--- a/node-tests/unit/plugins/lint-bare-strings-test.js
+++ b/node-tests/unit/plugins/lint-bare-strings-test.js
@@ -6,7 +6,19 @@ generateRuleTests({
   name: 'bare-strings',
 
   good: [
-    '{{t "howdy"}}'
+    '{{t "howdy"}}',
+    {
+      config: [','],
+      template: '\n {{translate "greeting"}},'
+    },
+    {
+      config: ['foo'],
+      template: '\nfoo'
+    },
+    {
+      config: ['/', '"'],
+      template: '{{t "foo"}} / "{{name}}"'
+    }
   ],
 
   bad: [
diff --git a/node-tests/unit/plugins/lint-block-indentation-test.js b/node-tests/unit/plugins/lint-block-indentation-test.js
index ae213bd..b07c48c 100644
--- a/node-tests/unit/plugins/lint-block-indentation-test.js
+++ b/node-tests/unit/plugins/lint-block-indentation-test.js
@@ -106,20 +106,6 @@ generateRuleTests({
         '</div>',
 
       message: "Incorrect indentation for `<p>` beginning at ('layout.hbs'@ L2:C2). Expected `<p>` to be at an indentation of 4 but was found at 2."
-    },
-    {
-      template: '<div>\n' +
-        '  <span></span>{{test}}\n' +
-        '</div>',
-
-      message: "Incorrect indentation for `{{test}}` beginning at ('layout.hbs'@ L2:C15). Expected `{{test}}` to be at an indentation of 2 but was found at 15."
-    },
-    {
-      template: '<div>\n' +
-        '  <span></span>{{#test-foo}}{{/test-foo}}\n' +
-        '</div>',
-
-      message: "Incorrect indentation for `{{#test-foo}}` beginning at ('layout.hbs'@ L2:C15). Expected `{{#test-foo}}` to be at an indentation of 2 but was found at 15."
     }
   ]
 });