interfaceNameRule.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Lint = require("../lint");
  8. var Rule = (function (_super) {
  9. __extends(Rule, _super);
  10. function Rule() {
  11. _super.apply(this, arguments);
  12. }
  13. Rule.prototype.apply = function (sourceFile) {
  14. return this.applyWithWalker(new NameWalker(sourceFile, this.getOptions()));
  15. };
  16. Rule.FAILURE_STRING = "interface name must be a capitalized I";
  17. return Rule;
  18. }(Lint.Rules.AbstractRule));
  19. exports.Rule = Rule;
  20. var NameWalker = (function (_super) {
  21. __extends(NameWalker, _super);
  22. function NameWalker() {
  23. _super.apply(this, arguments);
  24. }
  25. NameWalker.prototype.visitInterfaceDeclaration = function (node) {
  26. var interfaceName = node.name.text;
  27. if (!this.startsWithI(interfaceName)) {
  28. this.addFailureAt(node.name.getStart(), node.name.getWidth());
  29. }
  30. _super.prototype.visitInterfaceDeclaration.call(this, node);
  31. };
  32. NameWalker.prototype.startsWithI = function (name) {
  33. if (name.length <= 0) {
  34. return true;
  35. }
  36. var firstCharacter = name.charAt(0);
  37. return (firstCharacter === "I");
  38. };
  39. NameWalker.prototype.addFailureAt = function (position, width) {
  40. var failure = this.createFailure(position, width, Rule.FAILURE_STRING);
  41. this.addFailure(failure);
  42. };
  43. return NameWalker;
  44. }(Lint.RuleWalker));