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

Issue:
One-line block helper/components are not handled correctly
```hbs
{{#x-foo}}bar{{/x-foo}}
```
will report
```
Incorrect indentation for `x-foo` beginning at ('template.hbs'@ L1:C0). 
Expected `{{/x-foo}}` ending at ('template.hbs'@ L1:C14) to be at an indentation of 0 but was found at 14.
```

Which is incorrect IMO.

Pull request description:
Remove requirement that all block statements are multiline.
Fixes #37.

Patch:
diff --git a/ext/plugins/lint-block-indentation.js b/ext/plugins/lint-block-indentation.js
index 2b83803..fcf361c 100644
--- a/ext/plugins/lint-block-indentation.js
+++ b/ext/plugins/lint-block-indentation.js
@@ -21,35 +21,15 @@ module.exports = function(addonContext) {
   };
 
   BlockIndentation.prototype.process = function(node) {
-    this['process' + node.type](node);
-  };
-
-  BlockIndentation.prototype.buildWarning = function(name, locationInfo) {
-    return 'Incorrect `' + name + '` block indention at beginning at ' + locationInfo;
-  };
-
-  BlockIndentation.prototype.processElementNode = function(node) {
     // HTML elements that start and end on the same line are fine
     if (node.loc.start.line === node.loc.end.line) {
       return;
     }
 
-    var startColumn = node.loc.start.column;
-    var endColumn   = node.loc.end.column;
-
-    var correctedEndColumn = endColumn - node.tag.length - 3;
-    if(correctedEndColumn !== startColumn) {
-      var startLocation = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.start);
-      var endLocation = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.end);
-
-      var warning = 'Incorrect indentation for `' + node.tag + '` beginning at ' + startLocation +
-            '. Expected `</' + node.tag + '>` ending at ' + endLocation + 'to be at an indentation of ' + startColumn + ' but ' +
-            'was found at ' + correctedEndColumn + '.';
-      this.log(warning);
-    }
-  };
-
-  BlockIndentation.prototype.processBlockStatement = function(node) {
+    var isElementNode = node.type === 'ElementNode';
+    var openCloseCharOffset = isElementNode ? 3 : 5;
+    var displayName = isElementNode ? node.tag : node.path.original;
+    var display = isElementNode ? '</' + displayName + '>' : '{{/' + displayName + '}}';
     var startColumn = node.loc.start.column;
     var endColumn   = node.loc.end.column;
 
@@ -58,15 +38,14 @@ module.exports = function(addonContext) {
     }
 
     var startOffset = node._startOffset || 0;
-    var correctedEndColumn = endColumn - node.path.original.length - 5 + startOffset;
+    var correctedEndColumn = endColumn - displayName.length - openCloseCharOffset + startOffset;
     if(correctedEndColumn !== startColumn) {
       var startLocation = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.start);
       var endLocation = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.end);
 
-      var warning = 'Incorrect indentation for `' + node.path.original + '` beginning at ' + startLocation +
-            '. Expected `{{/' + node.path.original + '}}` ending at ' + endLocation + 'to be at an indentation of ' + startColumn + ' but ' +
+      var warning = 'Incorrect indentation for `' + displayName + '` beginning at ' + startLocation +
+            '. Expected `' + display + '` ending at ' + endLocation + 'to be at an indentation of ' + startColumn + ' but ' +
             'was found at ' + correctedEndColumn + '.';
-
       this.log(warning);
     }
   };


Test patch:
diff --git a/node-tests/unit/plugins/lint-block-indentation-test.js b/node-tests/unit/plugins/lint-block-indentation-test.js
index 1bfd77b..d69a750 100644
--- a/node-tests/unit/plugins/lint-block-indentation-test.js
+++ b/node-tests/unit/plugins/lint-block-indentation-test.js
@@ -31,7 +31,8 @@ generateRuleTests({
       '  {{else}}\n' +
       '    Good night\n' +
       '  {{/if}}\n' +
-      '</div>'
+      '</div>',
+    '{{#link-to "foo.bar"}}Blah{{/link-to}}'
   ],
 
   bad: [
@@ -41,12 +42,6 @@ generateRuleTests({
 
       message: "Incorrect indentation for `each` beginning at ('layout.hbs'@ L2:C2). Expected `{{/each}}` ending at ('layout.hbs'@ L3:C17)to be at an indentation of 2 but was found at 8."
     },
-    {
-      // block statements must be multiline
-      template: '{{#each cats as |dog|}}{{/each}}',
-
-      message: "Incorrect indentation for `each` beginning at ('layout.hbs'@ L1:C0). Expected `{{/each}}` ending at ('layout.hbs'@ L1:C32)to be at an indentation of 0 but was found at 23."
-    },
     {
       template: '<div>\n  <p>Stuff goes here</p></div>',