Repository: ember-template-lint/ember-template-lint
Pull request #418 (2018-05-29 13:29:56)

Fix line/column reporting when either is 0.
Prior to this change, if either `line` or `column` were `0` the console message would reference location `-:-`.


Patch:
diff --git a/docs/rule/no-attrs-in-components.md b/docs/rule/no-attrs-in-components.md
deleted file mode 100644
index f598738b..00000000
--- a/docs/rule/no-attrs-in-components.md
+++ /dev/null
@@ -1,25 +0,0 @@
-## no-attrs-in-components
-
-This rule prevents the usage of `attrs` property to access values passed to the component since all the values can be accessed directly from the from the template.
-
-For example, doing
-
-```components/templates/layout.hbs
-{{attr.foo}}
-```
-is bad. The correct way would be to directly consume `foo` in the template like,
-
-```components/templates/layout.hbs
-{{foo}}
-```
-
-or if you using Ember 3.1 and above,
-
-```components/templates/layout.hbs
-{{@foo}}
-```
-
-
-The following values are valid configuration:
-
-  * boolean -- `true` for enabled / `false` for disabled
diff --git a/lib/index.js b/lib/index.js
index f2fc32f2..c37a4d03 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -166,11 +166,10 @@ class Linter {
   static _formatError(error, options) {
     let message = '';
 
-    if (error.line && error.column) {
-      message += chalk.dim(`  ${error.line}:${error.column}`);
-    } else {
-      message += chalk.dim('  -:-');
-    }
+    let line = error.line === undefined ? '-' : error.line;
+    let column = error.column === undefined ? '-' : error.column;
+
+    message += chalk.dim(`  ${line}:${column}`);
 
     if (error.severity === WARNING_SEVERITY) {
       message += `  ${chalk.yellow('warning')}`;
diff --git a/lib/rules/index.js b/lib/rules/index.js
index c45a6daa..37759299 100644
--- a/lib/rules/index.js
+++ b/lib/rules/index.js
@@ -36,5 +36,4 @@ module.exports = {
   'no-unnecessary-concat': require('./lint-no-unnecessary-concat'),
   'no-partial': require('./lint-no-partial'),
   'invocable-blacklist': require('./lint-invocable-blacklist'),
-  'no-attr-in-components': require('./lint-no-attr-in-components'),
 };
diff --git a/lib/rules/lint-no-attr-in-components.js b/lib/rules/lint-no-attr-in-components.js
deleted file mode 100644
index 0f98fdb4..00000000
--- a/lib/rules/lint-no-attr-in-components.js
+++ /dev/null
@@ -1,27 +0,0 @@
-'use strict';
-
-const Rule = require('./base');
-const componentTemplateRegex = new RegExp('templates/components|components/.*/template|ui/components|-components/');
-
-module.exports = class LinkNoAttrComponent extends Rule {
-  isComponentTemplate() {
-    return componentTemplateRegex.test(this.templateEnvironmentData.moduleName);
-  }
-  visitor() {
-    return {
-      PathExpression(node) {
-        if (!this.isComponentTemplate()) {
-          return;
-        }
-        if (node.parts && node.parts[0] === 'attrs') {
-          this.log({
-            message: 'Component templates should not contain `attrs`.',
-            line: node.loc && node.loc.start.line,
-            column: node.loc && node.loc.start.column,
-            source: this.sourceForNode(node)
-          });
-        }
-      }
-    };
-  }
-};


Test patch:
diff --git a/test/acceptance-test.js b/test/acceptance-test.js
index 4826d574..466aac4b 100644
--- a/test/acceptance-test.js
+++ b/test/acceptance-test.js
@@ -535,6 +535,17 @@ describe('public api', function() {
       );
     });
 
+    it('formats error with rule, message, line and column numbers even when they are "falsey"', function() {
+      let result = Linter.errorsToMessages('file/path', [
+        { rule: 'some rule', message: 'some message', line: 1, column: 0 }
+      ]);
+
+      expect(result).to.equal(
+        'file/path\n'+
+        '  1:0  error  some message  some rule\n'
+      );
+    });
+
     it('formats error with rule, message, line and column numbers', function() {
       let result = Linter.errorsToMessages('file/path', [
         { rule: 'some rule', message: 'some message', line: 11, column: 12 }
diff --git a/test/unit/rules/lint-no-attr-in-components-test.js b/test/unit/rules/lint-no-attr-in-components-test.js
deleted file mode 100644
index 456b03a2..00000000
--- a/test/unit/rules/lint-no-attr-in-components-test.js
+++ /dev/null
@@ -1,129 +0,0 @@
-'use strict';
-
-const generateRuleTests = require('../../helpers/rule-test-harness');
-
-generateRuleTests({
-  name: 'no-attr-in-components',
-
-  config: 'true',
-  good: [
-    '<div></div>',
-    '{{foo}}',
-    '<div>{{foo.bar}}</div>',
-    '{{attrs.foo}}', // defaults to layout.hbs
-  ],
-  bad: [
-    {
-      template: '{{attrs.foo}}',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 2,
-      }
-    },
-    {
-      template: '<div class={{attrs.foo}}></div>',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 13,
-      }
-    },
-    {
-      template: '{{#if attrs.foo}}bar{{/if}}',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 6,
-      }
-    },
-    {
-      template: '{{bar foo=attrs.foo}}',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 10,
-      }
-    },
-    {
-      template: '{{component attrs.foo}}',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 12,
-      }
-    },
-    {
-      template: '{{bar/baz (hash foo=attrs.foo)}}',
-
-      meta: {
-        moduleId: 'templates/components/layout.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'templates/components/layout.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 20,
-      }
-    },
-    {
-      template: '{{attrs.foo}}',
-
-      meta: {
-        moduleId: 'components/comment/template.hbs',
-      },
-
-      result: {
-        rule: 'no-attr-in-components',
-        message: 'Component templates should not contain `attrs`.',
-        moduleId: 'components/comment/template.hbs',
-        source: 'attrs.foo',
-        line: 1,
-        column: 2,
-      }
-    }
-  ]
-});