.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / tripleEqualsRule.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 tsutils_1 = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 var OPTION_ALLOW_NULL_CHECK = "allow-null-check";
24 var OPTION_ALLOW_UNDEFINED_CHECK = "allow-undefined-check";
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             allowNull: this.ruleArguments.indexOf(OPTION_ALLOW_NULL_CHECK) !== -1,
33             allowUndefined: this.ruleArguments.indexOf(OPTION_ALLOW_UNDEFINED_CHECK) !== -1,
34         });
35     };
36     /* tslint:disable:object-literal-sort-keys */
37     Rule.metadata = {
38         ruleName: "triple-equals",
39         description: "Requires `===` and `!==` in place of `==` and `!=`.",
40         optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Two arguments may be optionally provided:\n\n            * `\"allow-null-check\"` allows `==` and `!=` when comparing to `null`.\n            * `\"allow-undefined-check\"` allows `==` and `!=` when comparing to `undefined`."], ["\n            Two arguments may be optionally provided:\n\n            * \\`\"allow-null-check\"\\` allows \\`==\\` and \\`!=\\` when comparing to \\`null\\`.\n            * \\`\"allow-undefined-check\"\\` allows \\`==\\` and \\`!=\\` when comparing to \\`undefined\\`."]))),
41         options: {
42             type: "array",
43             items: {
44                 type: "string",
45                 enum: [OPTION_ALLOW_NULL_CHECK, OPTION_ALLOW_UNDEFINED_CHECK],
46             },
47             minLength: 0,
48             maxLength: 2,
49         },
50         optionExamples: [true, [true, "allow-null-check"], [true, "allow-undefined-check"]],
51         type: "functionality",
52         typescriptOnly: false,
53     };
54     /* tslint:enable:object-literal-sort-keys */
55     Rule.EQ_FAILURE_STRING = "== should be ===";
56     Rule.NEQ_FAILURE_STRING = "!= should be !==";
57     return Rule;
58 }(Lint.Rules.AbstractRule));
59 exports.Rule = Rule;
60 function walk(ctx) {
61     return ts.forEachChild(ctx.sourceFile, function cb(node) {
62         if (tsutils_1.isBinaryExpression(node)) {
63             if ((node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken ||
64                 node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken) &&
65                 !(isExpressionAllowed(node.right, ctx.options) ||
66                     isExpressionAllowed(node.left, ctx.options))) {
67                 ctx.addFailureAtNode(node.operatorToken, node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken
68                     ? Rule.EQ_FAILURE_STRING
69                     : Rule.NEQ_FAILURE_STRING);
70             }
71         }
72         return ts.forEachChild(node, cb);
73     });
74 }
75 function isExpressionAllowed(node, options) {
76     if (node.kind === ts.SyntaxKind.NullKeyword) {
77         return options.allowNull;
78     }
79     return (options.allowUndefined &&
80         node.kind === ts.SyntaxKind.Identifier &&
81         node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword);
82 }
83 var templateObject_1;