.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / noRedundantJsdocRule.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2017 Palantir Technologies, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var tsutils_1 = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 var Rule = /** @class */ (function (_super) {
24     tslib_1.__extends(Rule, _super);
25     function Rule() {
26         return _super !== null && _super.apply(this, arguments) || this;
27     }
28     Rule.FAILURE_STRING_REDUNDANT_TAG = function (tagName) {
29         return "JSDoc tag '@" + tagName + "' is redundant in TypeScript code.";
30     };
31     Rule.FAILURE_STRING_NO_COMMENT = function (tagName) {
32         return "'@" + tagName + "' is redundant in TypeScript code if it has no description.";
33     };
34     Rule.prototype.apply = function (sourceFile) {
35         return this.applyWithFunction(sourceFile, walk);
36     };
37     /* tslint:disable:object-literal-sort-keys */
38     Rule.metadata = {
39         ruleName: "no-redundant-jsdoc",
40         description: "Forbids JSDoc which duplicates TypeScript functionality.",
41         optionsDescription: "Not configurable.",
42         options: null,
43         optionExamples: [true],
44         type: "style",
45         typescriptOnly: true,
46     };
47     /* tslint:enable:object-literal-sort-keys */
48     Rule.FAILURE_STRING_REDUNDANT_TYPE = "Type annotation in JSDoc is redundant in TypeScript code.";
49     return Rule;
50 }(Lint.Rules.AbstractRule));
51 exports.Rule = Rule;
52 function walk(ctx) {
53     var sourceFile = ctx.sourceFile;
54     // Intentionally exclude EndOfFileToken: it can have JSDoc, but it is only relevant in JavaScript files
55     return sourceFile.statements.forEach(function cb(node) {
56         if (tsutils_1.canHaveJsDoc(node)) {
57             for (var _i = 0, _a = tsutils_1.getJsDoc(node, sourceFile); _i < _a.length; _i++) {
58                 var tags = _a[_i].tags;
59                 if (tags !== undefined) {
60                     for (var _b = 0, tags_1 = tags; _b < tags_1.length; _b++) {
61                         var tag = tags_1[_b];
62                         checkTag(tag);
63                     }
64                 }
65             }
66         }
67         return ts.forEachChild(node, cb);
68     });
69     function checkTag(tag) {
70         switch (tag.kind) {
71             case ts.SyntaxKind.JSDocTag:
72                 if (redundantTags.has(tag.tagName.text)) {
73                     ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_REDUNDANT_TAG(tag.tagName.text));
74                 }
75                 break;
76             case ts.SyntaxKind.JSDocAugmentsTag:
77                 // OK
78                 break;
79             case ts.SyntaxKind.JSDocClassTag:
80             case ts.SyntaxKind.JSDocThisTag:
81             case ts.SyntaxKind.JSDocTypeTag:
82             case ts.SyntaxKind.JSDocTypedefTag:
83             case ts.SyntaxKind.JSDocPropertyTag:
84                 // Always redundant
85                 ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_REDUNDANT_TAG(tag.tagName.text));
86                 break;
87             case ts.SyntaxKind.JSDocTemplateTag:
88                 if (tag.comment === undefined ||
89                     tag.comment === "") {
90                     ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_NO_COMMENT(tag.tagName.text));
91                 }
92                 break;
93             case ts.SyntaxKind.JSDocReturnTag:
94             case ts.SyntaxKind.JSDocParameterTag: {
95                 var _a = tag, typeExpression = _a.typeExpression, comment = _a.comment;
96                 if (typeExpression !== undefined) {
97                     ctx.addFailureAtNode(typeExpression, Rule.FAILURE_STRING_REDUNDANT_TYPE);
98                 }
99                 if (comment === undefined || comment === "") {
100                     // Redundant if no documentation
101                     ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_NO_COMMENT(tag.tagName.text));
102                 }
103                 break;
104             }
105             default:
106                 throw new Error("Unexpected tag kind: " + ts.SyntaxKind[tag.kind]);
107         }
108     }
109 }
110 var redundantTags = new Set([
111     "abstract",
112     "access",
113     "class",
114     "constant",
115     "constructs",
116     "default",
117     "enum",
118     "exports",
119     "function",
120     "global",
121     "implements",
122     "interface",
123     "instance",
124     "member",
125     "memberof",
126     "mixes",
127     "mixin",
128     "module",
129     "name",
130     "namespace",
131     "override",
132     "private",
133     "property",
134     "protected",
135     "public",
136     "readonly",
137     "requires",
138     "static",
139     "this",
140 ]);