.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / commentTypeRule.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2018 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 utils = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 function parseOptions(opts) {
24     return new Set(opts);
25 }
26 // Constant Messages
27 var MULTILINE_FAILURE = "multiline comments are not allowed";
28 var SINGLE_LINE_FAILURE = "singleline comments are not allowed";
29 var DOC_FAILURE = "doc comments are not allowed";
30 var DIRECTIVE_FAILURE = "triple-slash directives are not allowed";
31 // Logic
32 var Rule = /** @class */ (function (_super) {
33     tslib_1.__extends(Rule, _super);
34     function Rule() {
35         return _super !== null && _super.apply(this, arguments) || this;
36     }
37     Rule.prototype.apply = function (sourceFile) {
38         return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments));
39     };
40     // tslint:disable:object-literal-sort-keys
41     Rule.metadata = {
42         ruleName: "comment-type",
43         description: "Allows a limited set of comment types",
44         optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            One or more of the following mutually exclusive comment types may be provided:\n\n            * `singleline`: Comments starting with `//`\n            * `multiline`:  Comments between `/*` and `*/` but are not doc comments\n            * `doc`:        Multiline comments that start with `/**`\n            * 'directive':  Triple-slash directives that are singleline comments starting with `///`"], ["\n            One or more of the following mutually exclusive comment types may be provided:\n\n            * \\`singleline\\`: Comments starting with \\`//\\`\n            * \\`multiline\\`:  Comments between \\`/*\\` and \\`*/\\` but are not doc comments\n            * \\`doc\\`:        Multiline comments that start with \\`/**\\`\n            * \\'directive\\':  Triple-slash directives that are singleline comments starting with \\`///\\`"]))),
45         options: {
46             type: "array",
47             items: {
48                 type: "string",
49                 enum: ["singleline", "multiline", "doc", "directive"],
50             },
51             uniqueItems: true,
52         },
53         optionExamples: [[true, "doc", "singleline"], [true, "singleline"], [true, "multiline"]],
54         hasFix: false,
55         type: "style",
56         typescriptOnly: false,
57     };
58     return Rule;
59 }(Lint.Rules.AbstractRule));
60 exports.Rule = Rule;
61 function walk(ctx) {
62     utils.forEachComment(ctx.sourceFile, function (fullText, _a) {
63         var kind = _a.kind, pos = _a.pos, end = _a.end;
64         if (kind === ts.SyntaxKind.SingleLineCommentTrivia) {
65             // directive
66             if (fullText.slice(pos, pos + 3) === "///" && !ctx.options.has("directive")) {
67                 ctx.addFailure(pos, end, DIRECTIVE_FAILURE);
68                 // singleline
69             }
70             else if (fullText.slice(pos, pos + 3) !== "///" && !ctx.options.has("singleline")) {
71                 ctx.addFailure(pos, end, SINGLE_LINE_FAILURE);
72             }
73         }
74         else if (kind === ts.SyntaxKind.MultiLineCommentTrivia) {
75             // doc
76             if (fullText.slice(pos, pos + 3) === "/**" && !ctx.options.has("doc")) {
77                 ctx.addFailure(pos, end, DOC_FAILURE);
78                 // multiline
79             }
80             else if (fullText.slice(pos, pos + 3) !== "/**" && !ctx.options.has("multiline")) {
81                 ctx.addFailure(pos, end, MULTILINE_FAILURE);
82             }
83         }
84     });
85 }
86 var templateObject_1;