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