Blame view

node_modules/eslint/lib/rules/no-lonely-if.js 937 Bytes
c39994410   Ryan Glover   wip converting to...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  /**
   * @fileoverview Rule to disallow if as the only statmenet in an else block
   * @author Brandon Mills
   */
  "use strict";
  
  //------------------------------------------------------------------------------
  // Rule Definition
  //------------------------------------------------------------------------------
  
  module.exports = function(context) {
  
      return {
          "IfStatement": function(node) {
              var ancestors = context.getAncestors(),
                  parent = ancestors.pop(),
                  grandparent = ancestors.pop();
  
              if (parent && parent.type === "BlockStatement" &&
                      parent.body.length === 1 && grandparent &&
                      grandparent.type === "IfStatement" &&
                      parent === grandparent.alternate) {
                  context.report(node, "Unexpected if as the only statement in an else block.");
              }
          }
      };
  
  };
  
  module.exports.schema = [];