UNPKG

3.24 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var ts = require("typescript");
14var Lint = require("tslint");
15var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
16var tsutils_1 = require("tsutils");
17var Rule = (function (_super) {
18 __extends(Rule, _super);
19 function Rule() {
20 return _super !== null && _super.apply(this, arguments) || this;
21 }
22 Rule.prototype.apply = function (sourceFile) {
23 return this.applyWithWalker(new NoEmptyLineAfterOpeningBraceWalker(sourceFile, this.getOptions()));
24 };
25 Rule.metadata = {
26 ruleName: 'no-empty-line-after-opening-brace',
27 type: 'maintainability',
28 description: 'Avoid an empty line after an opening brace',
29 options: null,
30 optionsDescription: '',
31 typescriptOnly: true,
32 issueClass: 'Ignored',
33 issueType: 'Warning',
34 severity: 'Low',
35 level: 'Opportunity for Excellence',
36 group: 'Whitespace',
37 recommendation: 'false,',
38 commonWeaknessEnumeration: '710'
39 };
40 Rule.FAILURE_STRING = 'Opening brace cannot be followed by empty line';
41 return Rule;
42}(Lint.Rules.AbstractRule));
43exports.Rule = Rule;
44var NoEmptyLineAfterOpeningBraceWalker = (function (_super) {
45 __extends(NoEmptyLineAfterOpeningBraceWalker, _super);
46 function NoEmptyLineAfterOpeningBraceWalker(sourceFile, options) {
47 var _this = _super.call(this, sourceFile, options) || this;
48 _this.scanner = ts.createScanner(1, false, 0, sourceFile.text);
49 return _this;
50 }
51 NoEmptyLineAfterOpeningBraceWalker.prototype.visitSourceFile = function (node) {
52 this.scanAllTokens(node);
53 _super.prototype.visitSourceFile.call(this, node);
54 };
55 NoEmptyLineAfterOpeningBraceWalker.prototype.scanAllTokens = function (node) {
56 var _this = this;
57 this.scanner.setTextPos(0);
58 var previous;
59 var previousPrevious;
60 tsutils_1.forEachTokenWithTrivia(node, function (_a, tokenSyntaxKind, range) {
61 if (previousPrevious === ts.SyntaxKind.OpenBraceToken &&
62 previous === ts.SyntaxKind.NewLineTrivia &&
63 tokenSyntaxKind === ts.SyntaxKind.NewLineTrivia) {
64 _this.addFailureAt(range.pos, 1, Rule.FAILURE_STRING);
65 }
66 if (tokenSyntaxKind !== ts.SyntaxKind.WhitespaceTrivia) {
67 previousPrevious = previous;
68 previous = tokenSyntaxKind;
69 }
70 });
71 };
72 return NoEmptyLineAfterOpeningBraceWalker;
73}(ErrorTolerantWalker_1.ErrorTolerantWalker));
74//# sourceMappingURL=noEmptyLineAfterOpeningBraceRule.js.map
\No newline at end of file