Repository: rwjblue/ember-template-lint
Pull request #224 (2017-06-22 18:05:49)

Rename `unless-helper` to `simple-unless` and enable by default.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index abb8c4a..5601194 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ Changelog
 - Drop support for Node < 4.
 - Fix a number of issues with `block-indentation` rule when using "whitespace control" characters (e.g. `{{~if foo~}}`).
 - Add support for globs in `.template-lintrc.js`'s `ignore` option.
-- Add `unless-helper` rule which forbids using `{{unless` with an inverse (or from an inverse), and with complex helper invocations as the predicate.
+- Add `simple-unless` rule which forbids using `{{unless` with an inverse (or from an inverse), and with complex helper invocations as the predicate.
 
   ```hbs
   {{! good }}
@@ -29,7 +29,7 @@ Changelog
   {{#unless (complex (helper (invocation)))}}
   {{/unless}}
   ```
-- Add `unless-helper` to the recommended configuration.
+- Add `simple-unless` to the recommended configuration.
 - Allow `<form onsubmit={{action 'foo'}}></form>` from the `invalid-interactive` rule.
 - Remove `deprecated-each-syntax` from `recommended` config.
 - Add configurable option to `link-rel-noopener` to require **both** `noopener` and `noreferrer`. See the [documentation](https://github.com/rwjblue/ember-template-lint#link-rel-noopener) for more details.
diff --git a/README.md b/README.md
index c8d1109..81eceb4 100644
--- a/README.md
+++ b/README.md
@@ -490,7 +490,7 @@ whereas this is allowed:
 <div style={{make-background url}}>
 ```
 
-#### unless-helper (default === false)
+#### simple-unless (default === false)
 
 This rule strongly advises against `{{unless}}` blocks used in conjunction with other
 block helpers (e.g. `{{else}}`, `{{else if}}`), and template helpers.
diff --git a/docs/plugins.md b/docs/plugins.md
index 59f4959..cd169fb 100644
--- a/docs/plugins.md
+++ b/docs/plugins.md
@@ -150,13 +150,7 @@ The base rule also has a few helper functions that can be useful in defining rul
 
 #### AST Node Helpers
 
-There are a number of helper functions exported by [`ember-template-lint`](../lib/helpers/ast-node-info.js) that can be used with AST nodes in your rule's visitor handlers.
-
-You can access these helpers via:
-
-```js
-const helpers = require('ember-template-lint').ASTHelpers;
-```
+There are a number of helper functions exported by [`ember-template-lint/lib/helpers/ast-node-info.js`](../lib/helpers/ast-node-info.js) that can be used with AST nodes in your rule's visitor functions.
 
 * `function isConfigurationHtmlComment(node): boolean`
 
diff --git a/lib/config/recommended.js b/lib/config/recommended.js
index 91d1824..8d760a6 100644
--- a/lib/config/recommended.js
+++ b/lib/config/recommended.js
@@ -14,7 +14,7 @@ module.exports = {
     'img-alt-attributes': true,
     'style-concatenation': true,
     'deprecated-inline-view-helper': true,
-    'unless-helper': false,
+    'simple-unless': true,
     'unused-block-params': true
   }
 };
diff --git a/lib/index.js b/lib/index.js
index d03ba7c..aacdcfb 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -164,4 +164,3 @@ class Linter {
 
 module.exports = Linter;
 module.exports.Rule = require('./rules/base');
-module.exports.ASTHelpers = require('./helpers/ast-node-info');
diff --git a/lib/rules/index.js b/lib/rules/index.js
index 69af2e1..dc9a0fe 100644
--- a/lib/rules/index.js
+++ b/lib/rules/index.js
@@ -17,6 +17,6 @@ module.exports = {
   'deprecated-inline-view-helper': require('./deprecations/lint-deprecated-inline-view-helper'),
   'invalid-interactive': require('./lint-invalid-interactive'),
   'style-concatenation': require('./lint-style-concatenation'),
-  'unless-helper': require('./lint-unless-helper'),
+  'simple-unless': require('./lint-simple-unless'),
   'unused-block-params': require('./lint-unused-block-params')
 };
diff --git a/lib/rules/lint-unless-helper.js b/lib/rules/lint-simple-unless.js
similarity index 94%
rename from lib/rules/lint-unless-helper.js
rename to lib/rules/lint-simple-unless.js
index 3c32111..db6ae55 100644
--- a/lib/rules/lint-unless-helper.js
+++ b/lib/rules/lint-simple-unless.js
@@ -8,11 +8,11 @@ const messages = {
   withHelper: 'Using {{unless}} in combination with other helpers should be avoided.'
 };
 
-module.exports = class LintUnlessHelper extends Rule {
+module.exports = class LintSimpleUnless extends Rule {
   visitor() {
     return {
       MustacheStatement(node) {
-        if (node.params[0].path) {
+        if (node.path.original === 'unless' && node.params[0].path) {
           this._withHelper(node);
         }
       },


Test patch:
diff --git a/test/acceptance-test.js b/test/acceptance-test.js
index efa4561..ed189ab 100644
--- a/test/acceptance-test.js
+++ b/test/acceptance-test.js
@@ -434,8 +434,8 @@ describe('public api', function() {
 
       expect(result).to.deep.equal(expected);
     });
-
   });
+
   describe('Linter using plugins (inline plugins)', function() {
     let basePath = path.join(fixturePath, 'with-inline-plugins');
     let linter;
diff --git a/test/unit/rules/lint-unless-helper-test.js b/test/unit/rules/lint-simple-unless-test.js
similarity index 89%
rename from test/unit/rules/lint-unless-helper-test.js
rename to test/unit/rules/lint-simple-unless-test.js
index 7dcf7c4..8c75929 100644
--- a/test/unit/rules/lint-unless-helper-test.js
+++ b/test/unit/rules/lint-simple-unless-test.js
@@ -1,16 +1,17 @@
 'use strict';
 
 const generateRuleTests = require('../../helpers/rule-test-harness');
-const messages = require('../../../lib/rules/lint-unless-helper').messages;
+const messages = require('../../../lib/rules/lint-simple-unless').messages;
 
 generateRuleTests({
-  name: 'unless-helper',
+  name: 'simple-unless',
   config: true,
 
   good: [
     '{{#unless isRed}}I\'m blue, da ba dee da ba daa{{/unless}}',
     '<div class="{{unless foo \'no-foo\'}}"></div>',
     '<div class="{{if foo \'foo\'}}"></div>',
+    '{{unrelated-mustache-without-params}}',
     [
       '{{#unless hamburger}}',
       '  HOT DOG!',
@@ -23,7 +24,7 @@ generateRuleTests({
       template: '{{unless (if true)  \'Please no\'}}',
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.withHelper,
         moduleId: 'layout.hbs',
         source: '{{unless (if ...',
@@ -35,7 +36,7 @@ generateRuleTests({
       template: '{{unless (and isBad isAwful)  \'notBadAndAwful\'}}',
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.withHelper,
         moduleId: 'layout.hbs',
         source: '{{unless (and ...',
@@ -53,7 +54,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.followingElseBlock,
         moduleId: 'layout.hbs',
         source: '{{else}}',
@@ -71,7 +72,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.followingElseBlock,
         moduleId: 'layout.hbs',
         source: '{{else if goHawks}}',
@@ -91,7 +92,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.followingElseBlock,
         moduleId: 'layout.hbs',
         source: '{{else if goPats}}',
@@ -111,7 +112,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.followingElseBlock,
         moduleId: 'layout.hbs',
         source: '{{else if goBengals}}',
@@ -129,7 +130,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.asElseUnlessBlock,
         moduleId: 'layout.hbs',
         source: '{{else unless ...',
@@ -145,7 +146,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.withHelper,
         moduleId: 'layout.hbs',
         source: '{{unless (and ...',
@@ -161,7 +162,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.withHelper,
         moduleId: 'layout.hbs',
         source: '{{unless (not ...',
@@ -179,7 +180,7 @@ generateRuleTests({
       ].join('\n'),
 
       result: {
-        rule: 'unless-helper',
+        rule: 'simple-unless',
         message: messages.followingElseBlock,
         moduleId: 'layout.hbs',
         source: '{{else}}',