.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / completed-docs / tagExclusion.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2013 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 ts = require("typescript");
21 var exclusion_1 = require("./exclusion");
22 var TagExclusion = /** @class */ (function (_super) {
23     tslib_1.__extends(TagExclusion, _super);
24     function TagExclusion() {
25         var _this = _super !== null && _super.apply(this, arguments) || this;
26         _this.contentTags = _this.descriptor.tags === undefined ? {} : _this.descriptor.tags.content;
27         _this.existenceTags = new Set(_this.descriptor.tags !== undefined && _this.descriptor.tags.existence !== undefined
28             ? _this.descriptor.tags.existence
29             : undefined);
30         return _this;
31     }
32     TagExclusion.prototype.excludes = function (node) {
33         var documentationNode = this.getDocumentationNode(node);
34         var tagsWithContents = this.parseTagsWithContents(documentationNode.getFullText());
35         for (var _i = 0, tagsWithContents_1 = tagsWithContents; _i < tagsWithContents_1.length; _i++) {
36             var tagWithContent = tagsWithContents_1[_i];
37             if (this.existenceTags.has(tagWithContent[0])) {
38                 return true;
39             }
40             var matcherBody = this.contentTags[tagWithContent[0]];
41             if (matcherBody === undefined) {
42                 continue;
43             }
44             if (new RegExp(matcherBody).test(tagWithContent[1])) {
45                 return true;
46             }
47         }
48         return false;
49     };
50     TagExclusion.prototype.getDocumentationNode = function (node) {
51         if (node.kind === ts.SyntaxKind.VariableDeclaration) {
52             return node.parent;
53         }
54         return node;
55     };
56     TagExclusion.prototype.parseTagsWithContents = function (nodeText) {
57         if (nodeText === undefined) {
58             return [];
59         }
60         var docMatches = nodeText.match(/\/\*\*\s*\n?([^\*]*(\*[^\/])?)*\*\//);
61         if (docMatches === null || docMatches.length === 0) {
62             return [];
63         }
64         var lines = docMatches[0].match(/[\r\n\s]*\*\s*@.*[\r\n\s]/g);
65         if (lines === null) {
66             return [];
67         }
68         return lines.map(function (line) {
69             var body = line.substring(line.indexOf("@"));
70             var firstSpaceIndex = body.search(/\s/);
71             return [body.substring(1, firstSpaceIndex), body.substring(firstSpaceIndex).trim()];
72         });
73     };
74     return TagExclusion;
75 }(exclusion_1.Exclusion));
76 exports.TagExclusion = TagExclusion;