noNullKeywordRule.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. return this.applyWithWalker(new NullWalker(sourceFile, this.getOptions()));
  16. };
  17. Rule.FAILURE_STRING = "Use 'undefined' instead of 'null'";
  18. return Rule;
  19. }(Lint.Rules.AbstractRule));
  20. exports.Rule = Rule;
  21. var NullWalker = (function (_super) {
  22. __extends(NullWalker, _super);
  23. function NullWalker() {
  24. _super.apply(this, arguments);
  25. }
  26. NullWalker.prototype.visitNode = function (node) {
  27. _super.prototype.visitNode.call(this, node);
  28. if (node.kind === ts.SyntaxKind.NullKeyword) {
  29. this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
  30. }
  31. };
  32. return NullWalker;
  33. }(Lint.RuleWalker));