eoflineRule.js 1.1 KB

123456789101112131415161718192021222324252627282930
  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. if (sourceFile.text === "") {
  15. return [];
  16. }
  17. var eofToken = sourceFile.endOfFileToken;
  18. var eofTokenFullText = eofToken.getFullText();
  19. if (eofTokenFullText.length === 0 || eofTokenFullText.charAt(eofTokenFullText.length - 1) !== "\n") {
  20. var start = eofToken.getStart();
  21. return [
  22. new Lint.RuleFailure(sourceFile, start, start, Rule.FAILURE_STRING, this.getOptions().ruleName)
  23. ];
  24. }
  25. return [];
  26. };
  27. Rule.FAILURE_STRING = "file should end with a newline";
  28. return Rule;
  29. }(Lint.Rules.AbstractRule));
  30. exports.Rule = Rule;