radixRule.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var ts = require("typescript");
  8. var Lint = require("../lint");
  9. var Rule = (function (_super) {
  10. __extends(Rule, _super);
  11. function Rule() {
  12. _super.apply(this, arguments);
  13. }
  14. Rule.prototype.apply = function (sourceFile) {
  15. var radixWalker = new RadixWalker(sourceFile, this.getOptions());
  16. return this.applyWithWalker(radixWalker);
  17. };
  18. Rule.FAILURE_STRING = "missing radix parameter";
  19. return Rule;
  20. }(Lint.Rules.AbstractRule));
  21. exports.Rule = Rule;
  22. var RadixWalker = (function (_super) {
  23. __extends(RadixWalker, _super);
  24. function RadixWalker() {
  25. _super.apply(this, arguments);
  26. }
  27. RadixWalker.prototype.visitCallExpression = function (node) {
  28. var expression = node.expression;
  29. if (expression.kind === ts.SyntaxKind.Identifier
  30. && node.getFirstToken().getText() === "parseInt"
  31. && node.arguments.length < 2) {
  32. this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
  33. }
  34. _super.prototype.visitCallExpression.call(this, node);
  35. };
  36. return RadixWalker;
  37. }(Lint.RuleWalker));