.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / language / walker / ruleWalker.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 rule_1 = require("../rule/rule");
21 var syntaxWalker_1 = require("./syntaxWalker");
22 /**
23  * @deprecated
24  * RuleWalker-based rules are slow,
25  * so it's generally preferable to use applyWithFunction instead of applyWithWalker.
26  * @see https://github.com/palantir/tslint/issues/2522
27  */
28 var RuleWalker = /** @class */ (function (_super) {
29     tslib_1.__extends(RuleWalker, _super);
30     function RuleWalker(sourceFile, options) {
31         var _this = _super.call(this) || this;
32         _this.sourceFile = sourceFile;
33         _this.failures = [];
34         _this.options = options.ruleArguments;
35         _this.limit = _this.sourceFile.getFullWidth();
36         _this.ruleName = options.ruleName;
37         return _this;
38     }
39     RuleWalker.prototype.getSourceFile = function () {
40         return this.sourceFile;
41     };
42     RuleWalker.prototype.getLineAndCharacterOfPosition = function (position) {
43         return this.sourceFile.getLineAndCharacterOfPosition(position);
44     };
45     RuleWalker.prototype.getFailures = function () {
46         return this.failures;
47     };
48     RuleWalker.prototype.getLimit = function () {
49         return this.limit;
50     };
51     RuleWalker.prototype.getOptions = function () {
52         return this.options;
53     };
54     RuleWalker.prototype.hasOption = function (option) {
55         if (this.options !== undefined) {
56             return this.options.indexOf(option) !== -1;
57         }
58         else {
59             return false;
60         }
61     };
62     /** @deprecated Prefer `addFailureAt` and its variants. */
63     RuleWalker.prototype.createFailure = function (start, width, failure, fix) {
64         var from = start > this.limit ? this.limit : start;
65         var to = start + width > this.limit ? this.limit : start + width;
66         return new rule_1.RuleFailure(this.sourceFile, from, to, failure, this.ruleName, fix);
67     };
68     /** @deprecated Prefer `addFailureAt` and its variants. */
69     RuleWalker.prototype.addFailure = function (failure) {
70         this.failures.push(failure);
71     };
72     /** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */
73     RuleWalker.prototype.addFailureAt = function (start, width, failure, fix) {
74         // tslint:disable-next-line deprecation
75         this.addFailure(this.createFailure(start, width, failure, fix));
76     };
77     /** Like `addFailureAt` but uses start and end instead of start and width. */
78     RuleWalker.prototype.addFailureFromStartToEnd = function (start, end, failure, fix) {
79         this.addFailureAt(start, end - start, failure, fix);
80     };
81     /** Add a failure using a node's span. */
82     RuleWalker.prototype.addFailureAtNode = function (node, failure, fix) {
83         this.addFailureAt(node.getStart(this.sourceFile), node.getWidth(this.sourceFile), failure, fix);
84     };
85     RuleWalker.prototype.createReplacement = function (start, length, text) {
86         return new rule_1.Replacement(start, length, text);
87     };
88     RuleWalker.prototype.appendText = function (start, text) {
89         return this.createReplacement(start, 0, text);
90     };
91     RuleWalker.prototype.deleteText = function (start, length) {
92         return this.createReplacement(start, length, "");
93     };
94     RuleWalker.prototype.deleteFromTo = function (start, end) {
95         return this.createReplacement(start, end - start, "");
96     };
97     RuleWalker.prototype.getRuleName = function () {
98         return this.ruleName;
99     };
100     return RuleWalker;
101 }(syntaxWalker_1.SyntaxWalker));
102 exports.RuleWalker = RuleWalker;