UNPKG

3 kBJavaScriptView Raw
1"use strict";
2var __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})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var ts = require("typescript");
17var Lint = require("tslint");
18var tsutils = require("tsutils");
19var AstUtils_1 = require("./utils/AstUtils");
20var Rule = (function (_super) {
21 __extends(Rule, _super);
22 function Rule() {
23 return _super !== null && _super.apply(this, arguments) || this;
24 }
25 Rule.prototype.apply = function (sourceFile) {
26 return this.applyWithFunction(sourceFile, walk);
27 };
28 Rule.metadata = {
29 ruleName: 'no-missing-visibility-modifiers',
30 type: 'maintainability',
31 description: 'Deprecated - This rule is in the TSLint product as `member-access`',
32 options: null,
33 optionsDescription: '',
34 typescriptOnly: true,
35 issueClass: 'Ignored',
36 issueType: 'Warning',
37 severity: 'Low',
38 level: 'Opportunity for Excellence',
39 group: 'Deprecated',
40 recommendation: 'false',
41 commonWeaknessEnumeration: '398, 710'
42 };
43 return Rule;
44}(Lint.Rules.AbstractRule));
45exports.Rule = Rule;
46function walk(ctx) {
47 function isMissingVisibilityModifier(node) {
48 return !(AstUtils_1.AstUtils.isPrivate(node) || AstUtils_1.AstUtils.isProtected(node) || AstUtils_1.AstUtils.isPublic(node));
49 }
50 function getFailureCodeSnippet(node) {
51 var message = node.getText();
52 if (message.indexOf('\n') > 0) {
53 return message.substr(0, message.indexOf('\n'));
54 }
55 return message;
56 }
57 function cb(node) {
58 if (tsutils.isPropertyDeclaration(node)) {
59 if (isMissingVisibilityModifier(node)) {
60 var failureString = 'Field missing visibility modifier: ' + getFailureCodeSnippet(node);
61 ctx.addFailureAt(node.getStart(), node.getWidth(), failureString);
62 }
63 }
64 if (tsutils.isMethodDeclaration(node)) {
65 if (isMissingVisibilityModifier(node)) {
66 var failureString = 'Method missing visibility modifier: ' + getFailureCodeSnippet(node);
67 ctx.addFailureAt(node.getStart(), node.getWidth(), failureString);
68 }
69 }
70 return ts.forEachChild(node, cb);
71 }
72 return ts.forEachChild(ctx.sourceFile, cb);
73}
74//# sourceMappingURL=noMissingVisibilityModifiersRule.js.map
\No newline at end of file