text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  /*
   * SonarTS
   * Copyright (C) 2017-2018 SonarSource SA
   * mailto:info AT sonarsource DOT com
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 3 of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   */
  const tslint = require("tslint");
  const ts = require("typescript");
  const sonarAnalysis_1 = require("../utils/sonarAnalysis");
  const nodes_1 = require("../utils/nodes");
  class Rule extends tslint.Rules.TypedRule {
      applyWithProgram(sourceFile) {
          return new Visitor(this.getOptions().ruleName).visit(sourceFile).getIssues();
      }
  }
  Rule.metadata = {
      ruleName: "no-redundant-boolean",
      description: "Boolean literals should not be redundant",
      rationale: tslint.Utils.dedent ``,
      optionsDescription: "",
      options: null,
      rspecKey: "RSPEC-1125",
      type: "functionality",
      typescriptOnly: false,
  };
  Rule.MESSAGE = "Remove the unnecessary boolean literal.";
  exports.Rule = Rule;
  class Visitor extends sonarAnalysis_1.SonarRuleVisitor {
      visitBinaryExpression(node) {
          if (isOrFalse(node)) {
              if (nodes_1.is(node.parent, ts.SyntaxKind.ConditionalExpression, ts.SyntaxKind.IfStatement)) {
                  this.addIssue(node.right, Rule.MESSAGE);
              }
          }
          else if (nodes_1.is(node.operatorToken, ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.BarBarToken, ts.SyntaxKind.AmpersandAmpersandToken)) {
              this.check(node.left);
              this.check(node.right);
          }
          super.visitBinaryExpression(node);
      }
      visitPrefixUnaryExpression(node) {
          if (node.operator === ts.SyntaxKind.ExclamationToken) {
              this.check(node.operand);
          }
          super.visitPrefixUnaryExpression(node);
      }
      visitConditionalExpression(node) {
          if (isBooleanLiteral(node.whenTrue) && isBooleanLiteral(node.whenFalse)) {
              this.addIssue(node, "Simplify this expression.");
          }
          super.visitConditionalExpression(node);
      }
      check(expr) {
          if (isBooleanLiteral(expr)) {
              this.addIssue(expr, Rule.MESSAGE);
          }
      }
  }
  function isBooleanLiteral(expr) {
      return nodes_1.is(expr, ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword);
  }
  function isOrFalse(node) {
      return nodes_1.is(node.operatorToken, ts.SyntaxKind.BarBarToken) && nodes_1.is(node.right, ts.SyntaxKind.FalseKeyword);
  }
  //# sourceMappingURL=noRedundantBooleanRule.js.map