title: Asynchronous code in custom ESLint rules
body: <p><strong>The Story and Motivation:</strong></p>
  
  <p>We have a rather huge end-to-end Protractor test codebase. Sometimes it happens that a test waits for a specific fix to be implemented - usually as a part of a TDD approach and to demonstrate how a problem is reproduced and what is the intended behavior. What we are currently doing is using Jasmine's <code>pending()</code> with a Jira issue number inside. Example:</p>
  
  <pre><code>pending("Missing functionality (AP-1234)", function () {
      // some testing is done here
  });
  </code></pre>
  
  <p>Now, we'd like to know when we can rename the <code>pending()</code> back to <code>it()</code> and run the test. Or, in other words, when the issue <code>AP-1234</code> is resolved or sent to testing. </p>
  
  <p><strong>The Current Approach:</strong></p>
  
  <p>At the moment, I'm trying to solve it with a <a href="http://eslint.org/docs/developer-guide/working-with-rules" rel="noreferrer">custom <code>ESLint</code> rule</a>, <a href="https://github.com/steves/node-jira" rel="noreferrer"><code>jira</code> NodeJS module</a>, and <a href="https://github.com/kriskowal/q" rel="noreferrer"><code>Q</code></a>. The custom <code>ESLint</code> rule searches for <code>pending()</code> calls with at least one argument. Extracts the ticket numbers in format of <code>AP-</code> followed by 4 digits and uses <code>jira.findIssue()</code> to check its status in Jira. If status is <code>Resolved</code> - report an error.</p>
  
  <p>Here is what I've got so far:</p>
  
  <pre><code>"use strict";
  
  var JiraApi = require("jira").JiraApi,
      Q = require('q');
  var jira = new JiraApi("https",
      "jira.url.com",
      "443",
      "user",
      "password",
      "2");
  
  module.exports = function (context) {
      var jiraTicketRegex = /AP\-\d+/g;
  
      return {
          CallExpression: function (node) {
              if (node.callee.name === "pending" &amp;&amp; node.arguments.length &gt; 0) {
                  var match = node.arguments[0].value.match(jiraTicketRegex);
  
                  if (match) {
                      match.forEach(function(ticket) {
                          console.log(ticket);  // I see the ticket numbers printed
                          getTicket(ticket).then(function (status) {
                              console.log(status);  // I don't see statuses printed
                              if (status === "Resolved") {
                                  context.report(node, 'Ticket {{ticket}} is already resolved.', {
                                      ticket: ticket
                                  })
                              }
                          });
                      });
  
                  }
              }
          }
      }
  };
  </code></pre>
  
  <p>Where <code>getTicket()</code> is defined as:</p>
  
  <pre><code>function getTicket(ticket) {
      var deferred = Q.defer();
  
      jira.findIssue(ticket, function(error, issue) {
          if (error) {
              deferred.reject(new Error(error));
          } else {
              deferred.resolve(issue.fields.status.name);
          }
      });
  
      return deferred.promise;
  }
  </code></pre>
  
  <p><em>The problem is:</em> currently, it successfully extracts the ticket numbers from the <code>pending()</code> calls, but doesn't print ticket statuses. No errors though.</p>
  
  <p><strong>The Question:</strong></p>
  
  <p>The general question is, I guess, would be: can I use asynchronous code blocks, wait for callbacks, resolve promises in custom <code>ESLint</code> rules? And, if not, what are my options?</p>
  
  <p>A more specific question would be: what am I doing wrong and how can I use Node.js <code>jira</code> module with <code>ESLint</code>?</p>
  
  <p><sub>Would appreciate any insights or alternative approaches.</sub></p>