.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / typeLiteralDelimiterRule.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 _a;
21 var tsutils_1 = require("tsutils");
22 var ts = require("typescript");
23 var Lint = require("../index");
24 var singeLineConfigOptionName = "singleLine";
25 var Rule = /** @class */ (function (_super) {
26     tslib_1.__extends(Rule, _super);
27     function Rule() {
28         return _super !== null && _super.apply(this, arguments) || this;
29     }
30     Rule.prototype.apply = function (sourceFile) {
31         return this.applyWithFunction(sourceFile, walk, this.getRuleOptions());
32     };
33     Rule.prototype.getRuleOptions = function () {
34         if (this.ruleArguments[0] === undefined) {
35             return {};
36         }
37         else {
38             return this.ruleArguments[0];
39         }
40     };
41     /* tslint:disable:object-literal-sort-keys */
42     Rule.metadata = {
43         ruleName: "type-literal-delimiter",
44         description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Checks that type literal members are separated by semicolons.\n            Enforces a trailing semicolon for multiline type literals."], ["\n            Checks that type literal members are separated by semicolons.\n            Enforces a trailing semicolon for multiline type literals."]))),
45         optionsDescription: "`{" + singeLineConfigOptionName + ": \"always\"}` enforces semicolon for one liners",
46         options: {
47             type: "object",
48             properties: (_a = {},
49                 _a[singeLineConfigOptionName] = {
50                     type: "string",
51                     enum: ["always", "never"],
52                 },
53                 _a),
54         },
55         hasFix: true,
56         optionExamples: [true],
57         type: "style",
58         typescriptOnly: true,
59     };
60     /* tslint:enable:object-literal-sort-keys */
61     Rule.FAILURE_STRING_MISSING = "Expected type literal to use ';' to separate members.";
62     Rule.FAILURE_STRING_COMMA = "Expected type literal to use ';' instead of ','.";
63     Rule.FAILURE_STRING_TRAILING = "Did not expect single-line type literal to have a trailing ';'.";
64     return Rule;
65 }(Lint.Rules.AbstractRule));
66 exports.Rule = Rule;
67 function walk(ctx) {
68     var sourceFile = ctx.sourceFile, options = ctx.options;
69     ts.forEachChild(sourceFile, function cb(node) {
70         if (tsutils_1.isTypeLiteralNode(node)) {
71             check(node);
72         }
73         ts.forEachChild(node, cb);
74     });
75     function check(node) {
76         node.members.forEach(function (member, idx) {
77             var end = member.end - 1;
78             // Check if delimiter should be ommitted for a single-line type literal.
79             var shouldOmit = options.singleLine === "always"
80                 ? false
81                 : idx === node.members.length - 1 &&
82                     tsutils_1.isSameLine(sourceFile, node.getStart(sourceFile), node.getEnd());
83             var delimiter = sourceFile.text[end];
84             switch (delimiter) {
85                 case ";":
86                     if (shouldOmit) {
87                         ctx.addFailureAt(end, 1, Rule.FAILURE_STRING_TRAILING, Lint.Replacement.replaceFromTo(end, end + 1, ""));
88                     }
89                     break;
90                 case ",":
91                     ctx.addFailureAt(end, 1, Rule.FAILURE_STRING_COMMA, Lint.Replacement.replaceFromTo(end, end + 1, ";"));
92                     break;
93                 default:
94                     if (!shouldOmit) {
95                         ctx.addFailureAt(end, 1, Rule.FAILURE_STRING_MISSING, Lint.Replacement.replaceFromTo(end + 1, end + 1, ";"));
96                     }
97             }
98         });
99     }
100 }
101 var templateObject_1;