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 = 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 | if (Rule.isWarningShown === false) {
|
26 | console.warn('Warning: no-empty-interfaces rule is deprecated. Replace your usage with the TSLint no-empty-interface rule.');
|
27 | Rule.isWarningShown = true;
|
28 | }
|
29 | return this.applyWithFunction(sourceFile, walk);
|
30 | };
|
31 | Rule.metadata = {
|
32 | ruleName: 'no-empty-interfaces',
|
33 | type: 'maintainability',
|
34 | description: 'Do not use empty interfaces.',
|
35 | options: null,
|
36 | optionsDescription: '',
|
37 | typescriptOnly: true,
|
38 | issueClass: 'Ignored',
|
39 | issueType: 'Warning',
|
40 | severity: 'Moderate',
|
41 | level: 'Opportunity for Excellence',
|
42 | group: 'Deprecated',
|
43 | recommendation: 'false',
|
44 | commonWeaknessEnumeration: '398, 710'
|
45 | };
|
46 | Rule.FAILURE_STRING = 'Do not declare empty interfaces: ';
|
47 | Rule.isWarningShown = false;
|
48 | return Rule;
|
49 | }(Lint.Rules.AbstractRule));
|
50 | exports.Rule = Rule;
|
51 | function walk(ctx) {
|
52 | function cb(node) {
|
53 | if (tsutils.isInterfaceDeclaration(node) && isInterfaceEmpty(node) && !hasMultipleParents(node)) {
|
54 | ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + "'" + node.name.getText() + "'");
|
55 | }
|
56 | return ts.forEachChild(node, cb);
|
57 | }
|
58 | return ts.forEachChild(ctx.sourceFile, cb);
|
59 | function isInterfaceEmpty(node) {
|
60 | return node.members === undefined || node.members.length === 0;
|
61 | }
|
62 | function hasMultipleParents(node) {
|
63 | if (node.heritageClauses === undefined || node.heritageClauses.length === 0) {
|
64 | return false;
|
65 | }
|
66 | return node.heritageClauses[0].types.length >= 2;
|
67 | }
|
68 | }
|
69 |
|
\ | No newline at end of file |