ruleWalker.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 rule_1 = require("../rule/rule");
  8. var utils_1 = require("../utils");
  9. var syntaxWalker_1 = require("./syntaxWalker");
  10. var RuleWalker = (function (_super) {
  11. __extends(RuleWalker, _super);
  12. function RuleWalker(sourceFile, options) {
  13. _super.call(this);
  14. this.position = 0;
  15. this.failures = [];
  16. this.options = options.ruleArguments;
  17. this.sourceFile = sourceFile;
  18. this.limit = this.sourceFile.getFullWidth();
  19. this.disabledIntervals = options.disabledIntervals;
  20. this.ruleName = options.ruleName;
  21. }
  22. RuleWalker.prototype.getSourceFile = function () {
  23. return this.sourceFile;
  24. };
  25. RuleWalker.prototype.getFailures = function () {
  26. return this.failures;
  27. };
  28. RuleWalker.prototype.getLimit = function () {
  29. return this.limit;
  30. };
  31. RuleWalker.prototype.getOptions = function () {
  32. return this.options;
  33. };
  34. RuleWalker.prototype.hasOption = function (option) {
  35. if (this.options) {
  36. return this.options.indexOf(option) !== -1;
  37. }
  38. else {
  39. return false;
  40. }
  41. };
  42. RuleWalker.prototype.skip = function (node) {
  43. this.position += node.getFullWidth();
  44. };
  45. RuleWalker.prototype.createFailure = function (start, width, failure) {
  46. var from = (start > this.limit) ? this.limit : start;
  47. var to = ((start + width) > this.limit) ? this.limit : (start + width);
  48. return new rule_1.RuleFailure(this.sourceFile, from, to, failure, this.ruleName);
  49. };
  50. RuleWalker.prototype.addFailure = function (failure) {
  51. if (!this.existsFailure(failure) && !utils_1.doesIntersect(failure, this.disabledIntervals)) {
  52. this.failures.push(failure);
  53. }
  54. };
  55. RuleWalker.prototype.existsFailure = function (failure) {
  56. return this.failures.some(function (f) { return f.equals(failure); });
  57. };
  58. return RuleWalker;
  59. }(syntaxWalker_1.SyntaxWalker));
  60. exports.RuleWalker = RuleWalker;