Repository: rwjblue/ember-template-lint
Pull request #222 (2017-06-22 14:22:47)

Rename `Rule.prototype.visitors` to `Rule.prototype.visitor`.
Closes https://github.com/rwjblue/ember-template-lint/issues/221


Patch:
diff --git a/docs/plugins.md b/docs/plugins.md
index f72263c..cd169fb 100644
--- a/docs/plugins.md
+++ b/docs/plugins.md
@@ -105,7 +105,7 @@ Sample rule:
 const Rule = require('ember-template-lint').Rule;
 
 module.exports = class NoEmptyComments extends Rule {
-  visitors() {
+  visitor() {
     return {
       CommentStatement(node) {
         if (node.value.trim() === '') {
@@ -124,9 +124,9 @@ module.exports = class NoEmptyComments extends Rule {
 
 You can override the following methods on the base plugin class:
 
-* `function visitors(): visitorsObject`
+* `function visitor(): visitorObject`
 
-  The `visitors` function should return an object that maps Handlebars node types to functions. Whenever the Handlebars parser encounters a particular type of node, any visitor function that you define for that node will be called on it. You can reference the [Handlebars Compiler API](https://github.com/wycats/handlebars.js/blob/master/docs/compiler-api.md) for more detail on the types of nodes and their interfaces.
+  The `visitor` function should return an object that maps Handlebars node types to functions. Whenever the Handlebars parser encounters a particular type of node, any handler function that you define for that node will be called on it. You can reference the [Handlebars Compiler API](https://github.com/wycats/handlebars.js/blob/master/docs/compiler-api.md) for more detail on the types of nodes and their interfaces.
 
 The base rule also has a few helper functions that can be useful in defining rule behavior:
 
diff --git a/lib/index.js b/lib/index.js
index b802faf..eac2bad 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -59,11 +59,11 @@ class Linter {
       astPlugins.push(env => {
         plugin.templateEnvironmentData = env;
 
-        let visitors = plugin.getVisitors();
+        let visitor = plugin.getVisitor();
 
         return {
           name: pluginName,
-          visitors
+          visitors: visitor
         };
       });
     }
diff --git a/lib/rules/base.js b/lib/rules/base.js
index f0b6cf0..646b527 100644
--- a/lib/rules/base.js
+++ b/lib/rules/base.js
@@ -78,16 +78,10 @@ module.exports = class BaseRule {
     return config;
   }
 
-  transform(ast) {
-    this.syntax.traverse(ast, this.getVisitors());
-
-    return ast;
-  }
-
-  getVisitors() {
+  getVisitor() {
     let pluginContext = this;
-    let visitors = {};
-    let ruleVisitors = this.visitors();
+    let visitor = {};
+    let ruleVisitor = this.visitor();
     // We use this structure to advise/unadvise on AST events. The walkers we
     // set up read this structure every time they get an AST event and call the
     // appropriate functions. Handlers get added to the before/after list
@@ -131,19 +125,19 @@ module.exports = class BaseRule {
     let inElementComments = false;
 
     //
-    // Wrap all visitors supplied by the rule, plus make sure we have entries
-    // for the visitors we use internally for instruction processing. This is
+    // Wrap the visitor handlers supplied by the rule, plus make sure we have entries
+    // for the handlers we use internally for instruction processing. This is
     // done for two reasons -- one is to support instruction processing, but
     // the other is to allow the rule's visitor handlers to have their this
     // context set to the plugin, which isn't what HTMLBars does.
     //
-    for (let key in ruleVisitors) {
-      visitors[key] = this._wrapVisitor(ruleVisitors[key], astHandlers[key]);
+    for (let key in ruleVisitor) {
+      visitor[key] = this._wrapVisitor(ruleVisitor[key], astHandlers[key]);
     }
 
-    visitors.CommentStatement = visitors.CommentStatement || this._wrapVisitor(null, astHandlers.CommentStatement);
-    visitors.MustacheCommentStatement = visitors.MustacheCommentStatement || this._wrapVisitor(null, astHandlers.MustacheCommentStatement);
-    visitors.ElementNode = visitors.ElementNode || this._wrapVisitor(null, astHandlers.ElementNode);
+    visitor.CommentStatement = visitor.CommentStatement || this._wrapVisitor(null, astHandlers.CommentStatement);
+    visitor.MustacheCommentStatement = visitor.MustacheCommentStatement || this._wrapVisitor(null, astHandlers.MustacheCommentStatement);
+    visitor.ElementNode = visitor.ElementNode || this._wrapVisitor(null, astHandlers.ElementNode);
 
     //
     // Set up our handlers
@@ -267,10 +261,10 @@ module.exports = class BaseRule {
       });
     });
 
-    return visitors;
+    return visitor;
   }
 
-  visitors() { }
+  visitor() { }
 
   // Generate a visitor handler function for a specific node type/event that
   // will call the internal handlers and the rule handler for that node
diff --git a/lib/rules/deprecations/lint-deprecated-each-syntax.js b/lib/rules/deprecations/lint-deprecated-each-syntax.js
index f00a2c5..36ab0e0 100644
--- a/lib/rules/deprecations/lint-deprecated-each-syntax.js
+++ b/lib/rules/deprecations/lint-deprecated-each-syntax.js
@@ -5,7 +5,7 @@ const Rule = require('../base');
 const DEPRECATION_URL = 'http://emberjs.com/deprecations/v1.x/#toc_code-in-code-syntax-for-code-each-code';
 
 module.exports = class DeprecatedEachSyntax extends Rule {
-  visitors() {
+  visitor() {
     return {
       BlockStatement(node) {
         if (node.path.original === 'each') {
diff --git a/lib/rules/deprecations/lint-deprecated-inline-view-helper.js b/lib/rules/deprecations/lint-deprecated-inline-view-helper.js
index 75aa92f..da41895 100644
--- a/lib/rules/deprecations/lint-deprecated-inline-view-helper.js
+++ b/lib/rules/deprecations/lint-deprecated-inline-view-helper.js
@@ -51,7 +51,7 @@ function manageMustacheViewInvocation(context, node, isBlockStatement) {
 }
 
 module.exports = class DeprecatedInlineViewHelper extends Rule {
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         let attributes = node.attributes;
diff --git a/lib/rules/lint-bare-strings.js b/lib/rules/lint-bare-strings.js
index 589b5bc..cd10384 100644
--- a/lib/rules/lint-bare-strings.js
+++ b/lib/rules/lint-bare-strings.js
@@ -100,7 +100,7 @@ module.exports = class LogStaticStrings extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       TextNode(node) {
         if (!node.loc) { return; }
diff --git a/lib/rules/lint-block-indentation.js b/lib/rules/lint-block-indentation.js
index 6c34bd6..1cf22ae 100644
--- a/lib/rules/lint-block-indentation.js
+++ b/lib/rules/lint-block-indentation.js
@@ -101,7 +101,7 @@ module.exports = class BlockIndentation extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       BlockStatement(node) {
         this.process(node);
diff --git a/lib/rules/lint-html-comments.js b/lib/rules/lint-html-comments.js
index 08b6148..0e9120e 100644
--- a/lib/rules/lint-html-comments.js
+++ b/lib/rules/lint-html-comments.js
@@ -21,7 +21,7 @@ module.exports = class LogHtmlComments extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       CommentStatement(node) {
         if (AstNodeInfo.isNonConfigurationHtmlComment(node)) {
diff --git a/lib/rules/lint-img-alt-attributes.js b/lib/rules/lint-img-alt-attributes.js
index 187cbc3..49c8b61 100644
--- a/lib/rules/lint-img-alt-attributes.js
+++ b/lib/rules/lint-img-alt-attributes.js
@@ -19,7 +19,7 @@ const Rule = require('./base');
  ```
 */
 module.exports = class ImgAltAttributes extends Rule {
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         let isImg = AstNodeInfo.isImgElement(node);
diff --git a/lib/rules/lint-inline-link-to.js b/lib/rules/lint-inline-link-to.js
index dac9b70..03cbe67 100644
--- a/lib/rules/lint-inline-link-to.js
+++ b/lib/rules/lint-inline-link-to.js
@@ -4,7 +4,7 @@ const Rule = require('./base');
 const message = 'The inline form of link-to is not allowed. Use the block form instead.';
 
 module.exports = class InlineLinkTo extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'link-to') {
diff --git a/lib/rules/lint-inline-styles.js b/lib/rules/lint-inline-styles.js
index 8c5eb2c..9421777 100644
--- a/lib/rules/lint-inline-styles.js
+++ b/lib/rules/lint-inline-styles.js
@@ -19,7 +19,7 @@ const Rule = require('./base');
  ```
  */
 module.exports = class InlineStyles extends Rule {
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         let style = AstNodeInfo.findAttribute(node, 'style');
diff --git a/lib/rules/lint-invalid-interactive.js b/lib/rules/lint-invalid-interactive.js
index eaa5374..cb8f36b 100644
--- a/lib/rules/lint-invalid-interactive.js
+++ b/lib/rules/lint-invalid-interactive.js
@@ -19,7 +19,7 @@ module.exports = class InvalidInteractive extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     this._element = null;
 
     let visitor = {
diff --git a/lib/rules/lint-link-rel-noopener.js b/lib/rules/lint-link-rel-noopener.js
index 5e25cf7..6ae88c3 100644
--- a/lib/rules/lint-link-rel-noopener.js
+++ b/lib/rules/lint-link-rel-noopener.js
@@ -54,7 +54,7 @@ module.exports = class LinkRelNoopener extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         let isLink = AstNodeInfo.isLinkElement(node);
diff --git a/lib/rules/lint-nested-interactive.js b/lib/rules/lint-nested-interactive.js
index b064534..509348f 100644
--- a/lib/rules/lint-nested-interactive.js
+++ b/lib/rules/lint-nested-interactive.js
@@ -70,7 +70,7 @@ module.exports = class LogNestedInteractive extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     this._parentInteractiveNode = null;
 
     let visitor = {
diff --git a/lib/rules/lint-no-debugger.js b/lib/rules/lint-no-debugger.js
index a0a272e..4cf652a 100644
--- a/lib/rules/lint-no-debugger.js
+++ b/lib/rules/lint-no-debugger.js
@@ -15,7 +15,7 @@ module.exports = class NoDebugger extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         this._checkForDebugger(node);
diff --git a/lib/rules/lint-no-log.js b/lib/rules/lint-no-log.js
index c046269..ff08bb2 100644
--- a/lib/rules/lint-no-log.js
+++ b/lib/rules/lint-no-log.js
@@ -15,7 +15,7 @@ module.exports = class NoLog extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         this._checkForLog(node);
diff --git a/lib/rules/lint-self-closing-void-elements.js b/lib/rules/lint-self-closing-void-elements.js
index 1b2c981..23fafae 100644
--- a/lib/rules/lint-self-closing-void-elements.js
+++ b/lib/rules/lint-self-closing-void-elements.js
@@ -41,7 +41,7 @@ const VOID_TAGS = {
 };
 
 module.exports = class LogSelfClosingVoidElements extends Rule {
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         if (VOID_TAGS[node.tag]) {
diff --git a/lib/rules/lint-style-concatenation.js b/lib/rules/lint-style-concatenation.js
index 9884948..84c1a27 100644
--- a/lib/rules/lint-style-concatenation.js
+++ b/lib/rules/lint-style-concatenation.js
@@ -4,7 +4,7 @@ const AstNodeInfo = require('../helpers/ast-node-info');
 const Rule = require('./base');
 
 module.exports = class StyleConcat extends Rule {
-  visitors() {
+  visitor() {
     return {
       ElementNode(node) {
         let style = AstNodeInfo.findAttribute(node, 'style');
diff --git a/lib/rules/lint-triple-curlies.js b/lib/rules/lint-triple-curlies.js
index a7b6ece..fded3e0 100644
--- a/lib/rules/lint-triple-curlies.js
+++ b/lib/rules/lint-triple-curlies.js
@@ -20,7 +20,7 @@ module.exports = class LogTripleCurlies extends Rule {
     }
   }
 
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (!node.escaped) {
diff --git a/lib/rules/lint-unused-block-params.js b/lib/rules/lint-unused-block-params.js
index c81f236..65a854e 100644
--- a/lib/rules/lint-unused-block-params.js
+++ b/lib/rules/lint-unused-block-params.js
@@ -43,7 +43,7 @@
 const Rule = require('./base');
 
 module.exports = class UnusedBlockParams extends Rule {
-  visitors() {
+  visitor() {
     let scope = new Scope();
 
     return {


Test patch:
diff --git a/test/eslint-test.js b/test/eslint-test.js
index fe7fd42..236d622 100644
--- a/test/eslint-test.js
+++ b/test/eslint-test.js
@@ -7,5 +7,6 @@ const paths = [
   'test'
 ];
 
-const options = {};
-lint(paths, options);
+lint(paths, {
+  timeout: 5000
+});
diff --git a/test/fixtures/with-inline-plugins/rules/lint-inline-component.js b/test/fixtures/with-inline-plugins/rules/lint-inline-component.js
index d8d0e76..e5fe6b6 100644
--- a/test/fixtures/with-inline-plugins/rules/lint-inline-component.js
+++ b/test/fixtures/with-inline-plugins/rules/lint-inline-component.js
@@ -5,7 +5,7 @@ var Rule = require('../../../../lib/rules/base');
 var message = 'The inline form of component is not allowed';
 
 module.exports = class InlineComponent extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'component') {
diff --git a/test/fixtures/with-multiple-extends/plugins/lint-inline-component.js b/test/fixtures/with-multiple-extends/plugins/lint-inline-component.js
index d8d0e76..e5fe6b6 100644
--- a/test/fixtures/with-multiple-extends/plugins/lint-inline-component.js
+++ b/test/fixtures/with-multiple-extends/plugins/lint-inline-component.js
@@ -5,7 +5,7 @@ var Rule = require('../../../../lib/rules/base');
 var message = 'The inline form of component is not allowed';
 
 module.exports = class InlineComponent extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'component') {
diff --git a/test/fixtures/with-plugin-with-configurations/plugins/lint-inline-component.js b/test/fixtures/with-plugin-with-configurations/plugins/lint-inline-component.js
index d8d0e76..e5fe6b6 100644
--- a/test/fixtures/with-plugin-with-configurations/plugins/lint-inline-component.js
+++ b/test/fixtures/with-plugin-with-configurations/plugins/lint-inline-component.js
@@ -5,7 +5,7 @@ var Rule = require('../../../../lib/rules/base');
 var message = 'The inline form of component is not allowed';
 
 module.exports = class InlineComponent extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'component') {
diff --git a/test/fixtures/with-plugins-overwriting/plugins/lint-inline-component.js b/test/fixtures/with-plugins-overwriting/plugins/lint-inline-component.js
index d8d0e76..e5fe6b6 100644
--- a/test/fixtures/with-plugins-overwriting/plugins/lint-inline-component.js
+++ b/test/fixtures/with-plugins-overwriting/plugins/lint-inline-component.js
@@ -5,7 +5,7 @@ var Rule = require('../../../../lib/rules/base');
 var message = 'The inline form of component is not allowed';
 
 module.exports = class InlineComponent extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'component') {
diff --git a/test/fixtures/with-plugins/plugins/lint-inline-component.js b/test/fixtures/with-plugins/plugins/lint-inline-component.js
index d8d0e76..e5fe6b6 100644
--- a/test/fixtures/with-plugins/plugins/lint-inline-component.js
+++ b/test/fixtures/with-plugins/plugins/lint-inline-component.js
@@ -5,7 +5,7 @@ var Rule = require('../../../../lib/rules/base');
 var message = 'The inline form of component is not allowed';
 
 module.exports = class InlineComponent extends Rule {
-  visitors() {
+  visitor() {
     return {
       MustacheStatement(node) {
         if (node.path.original === 'component') {
diff --git a/test/unit/base-plugin-test.js b/test/unit/base-plugin-test.js
index 6acb9f0..3c34b2c 100644
--- a/test/unit/base-plugin-test.js
+++ b/test/unit/base-plugin-test.js
@@ -21,7 +21,7 @@ describe('base plugin', function() {
     config = {};
   });
 
-  function buildPlugin(visitors) {
+  function buildPlugin(visitor) {
     class FakeRule extends Rule {
       log(result) {
         messages.push(result.source);
@@ -36,8 +36,8 @@ describe('base plugin', function() {
         });
       }
 
-      visitors() {
-        return visitors;
+      visitor() {
+        return visitor;
       }
     }
 
@@ -50,14 +50,14 @@ describe('base plugin', function() {
     return env => {
       plugin.templateEnvironmentData = env;
 
-      let visitors = plugin.getVisitors();
+      let visitor = plugin.getVisitor();
 
-      return { name, visitors };
+      return { name, visitors: visitor};
     };
   }
 
   describe('parses templates', function() {
-    let visitors = {
+    let visitor = {
       ElementNode(node) {
         this.process(node);
       },
@@ -72,7 +72,7 @@ describe('base plugin', function() {
     };
 
     function precompile(template) {
-      precompileTemplate(template, [ plugin(buildPlugin(visitors), 'fake', config) ]);
+      precompileTemplate(template, [ plugin(buildPlugin(visitor), 'fake', config) ]);
     }
 
     function expectSource(config) {
@@ -245,7 +245,7 @@ describe('base plugin', function() {
           messages.push(result.source);
         }
 
-        visitors() {
+        visitor() {
           var pluginContext = this;
 
           return {