.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / noAnyRule.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 _a, _b;
21 var tsutils_1 = require("tsutils");
22 var ts = require("typescript");
23 var Lint = require("../index");
24 var noAny_examples_1 = require("./code-examples/noAny.examples");
25 var OPTION_IGNORE_REST_ARGS = "ignore-rest-args";
26 var Rule = /** @class */ (function (_super) {
27     tslib_1.__extends(Rule, _super);
28     function Rule() {
29         return _super !== null && _super.apply(this, arguments) || this;
30     }
31     Rule.prototype.apply = function (sourceFile) {
32         var options = getOptions(this.ruleArguments[0]);
33         return this.applyWithFunction(sourceFile, walk, options);
34     };
35     /* tslint:disable:object-literal-sort-keys */
36     Rule.metadata = {
37         ruleName: "no-any",
38         description: "Disallows usages of `any` as a type declaration.",
39         hasFix: false,
40         rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Using `any` as a type declaration nullifies the compile-time benefits of the type system.\n\n            If you're dealing with data of unknown or \"any\" types, you shouldn't be accessing members of it.\n            Either add type annotations for properties that may exist or change the data type to the empty object type `{}`.\n\n            Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures\n            or serialization, use `<T>` template types for generic type handling.\n\n            Also see the `no-unsafe-any` rule.\n        "], ["\n            Using \\`any\\` as a type declaration nullifies the compile-time benefits of the type system.\n\n            If you're dealing with data of unknown or \"any\" types, you shouldn't be accessing members of it.\n            Either add type annotations for properties that may exist or change the data type to the empty object type \\`{}\\`.\n\n            Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures\n            or serialization, use \\`<T>\\` template types for generic type handling.\n\n            Also see the \\`no-unsafe-any\\` rule.\n        "]))),
41         optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n            If `\"", "\": true` is provided rest arguments will be ignored.\n        "], ["\n            If \\`\"", "\": true\\` is provided rest arguments will be ignored.\n        "])), OPTION_IGNORE_REST_ARGS),
42         options: {
43             type: "object",
44             properties: (_a = {},
45                 _a[OPTION_IGNORE_REST_ARGS] = { type: "boolean" },
46                 _a),
47         },
48         optionExamples: [true, [true, (_b = {}, _b[OPTION_IGNORE_REST_ARGS] = true, _b)]],
49         type: "typescript",
50         typescriptOnly: true,
51         codeExamples: noAny_examples_1.codeExamples,
52     };
53     /* tslint:enable:object-literal-sort-keys */
54     Rule.FAILURE_STRING = "Type declaration of 'any' loses type-safety. Consider replacing it with a more precise type.";
55     return Rule;
56 }(Lint.Rules.AbstractRule));
57 exports.Rule = Rule;
58 function getOptions(options) {
59     var _a;
60     return tslib_1.__assign((_a = {}, _a[OPTION_IGNORE_REST_ARGS] = false, _a), options);
61 }
62 function walk(ctx) {
63     return ts.forEachChild(ctx.sourceFile, function cb(node) {
64         if (node.kind === ts.SyntaxKind.AnyKeyword) {
65             if (ctx.options[OPTION_IGNORE_REST_ARGS] && isRestParameterArrayType(node)) {
66                 return;
67             }
68             var start = node.end - 3;
69             return ctx.addFailure(start, node.end, Rule.FAILURE_STRING);
70         }
71         return ts.forEachChild(node, cb);
72     });
73 }
74 function isRestParameterArrayType(anyTypeNode) {
75     return (tsutils_1.isArrayTypeNode(anyTypeNode.parent) &&
76         tsutils_1.isParameterDeclaration(anyTypeNode.parent.parent) &&
77         anyTypeNode.parent.parent.getChildAt(0).kind === ts.SyntaxKind.DotDotDotToken);
78 }
79 var templateObject_1, templateObject_2;