.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / oneVariablePerDeclarationRule.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 tsutils_1 = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 var oneVariablePerDeclaration_examples_1 = require("./code-examples/oneVariablePerDeclaration.examples");
24 var OPTION_IGNORE_FOR_LOOP = "ignore-for-loop";
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, {
32             ignoreForLoop: this.ruleArguments.indexOf(OPTION_IGNORE_FOR_LOOP) !== -1,
33         });
34     };
35     /* tslint:disable:object-literal-sort-keys */
36     Rule.metadata = {
37         ruleName: "one-variable-per-declaration",
38         description: "Disallows multiple variable definitions in the same declaration statement.",
39         optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            One argument may be optionally provided:\n\n            * `", "` allows multiple variable definitions in a for loop declaration."], ["\n            One argument may be optionally provided:\n\n            * \\`", "\\` allows multiple variable definitions in a for loop declaration."])), OPTION_IGNORE_FOR_LOOP),
40         options: {
41             type: "array",
42             items: {
43                 type: "string",
44                 enum: [OPTION_IGNORE_FOR_LOOP],
45             },
46             minLength: 0,
47             maxLength: 1,
48         },
49         optionExamples: [true, [true, OPTION_IGNORE_FOR_LOOP]],
50         type: "style",
51         typescriptOnly: false,
52         codeExamples: oneVariablePerDeclaration_examples_1.codeExamples,
53     };
54     /* tslint:enable:object-literal-sort-keys */
55     Rule.FAILURE_STRING = "Multiple variable declarations in the same statement are forbidden";
56     return Rule;
57 }(Lint.Rules.AbstractRule));
58 exports.Rule = Rule;
59 function walk(ctx) {
60     ts.forEachChild(ctx.sourceFile, function cb(node) {
61         if (tsutils_1.isVariableStatement(node) && node.declarationList.declarations.length > 1) {
62             ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
63         }
64         else if (tsutils_1.isForStatement(node) && !ctx.options.ignoreForLoop) {
65             var initializer = node.initializer;
66             if (initializer !== undefined &&
67                 initializer.kind === ts.SyntaxKind.VariableDeclarationList &&
68                 initializer.declarations.length > 1) {
69                 ctx.addFailureAtNode(initializer, Rule.FAILURE_STRING);
70             }
71         }
72         ts.forEachChild(node, cb);
73     });
74 }
75 var templateObject_1;