.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / language / rule / rule.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 utils_1 = require("../../utils");
20 function isTypedRule(rule) {
21     return "applyWithProgram" in rule;
22 }
23 exports.isTypedRule = isTypedRule;
24 var Replacement = /** @class */ (function () {
25     function Replacement(start, length, text) {
26         this.start = start;
27         this.length = length;
28         this.text = text;
29     }
30     Replacement.applyFixes = function (content, fixes) {
31         return Replacement.applyAll(content, utils_1.flatMap(fixes, utils_1.arrayify));
32     };
33     Replacement.applyAll = function (content, replacements) {
34         // sort in reverse so that diffs are properly applied
35         replacements.sort(function (a, b) { return (b.end !== a.end ? b.end - a.end : b.start - a.start); });
36         return replacements.reduce(function (text, r) { return r.apply(text); }, content);
37     };
38     Replacement.replaceNode = function (node, text, sourceFile) {
39         return Replacement.replaceFromTo(node.getStart(sourceFile), node.getEnd(), text);
40     };
41     Replacement.replaceFromTo = function (start, end, text) {
42         return new Replacement(start, end - start, text);
43     };
44     Replacement.deleteText = function (start, length) {
45         return new Replacement(start, length, "");
46     };
47     Replacement.deleteFromTo = function (start, end) {
48         return new Replacement(start, end - start, "");
49     };
50     Replacement.appendText = function (start, text) {
51         return new Replacement(start, 0, text);
52     };
53     Object.defineProperty(Replacement.prototype, "end", {
54         get: function () {
55             return this.start + this.length;
56         },
57         enumerable: true,
58         configurable: true
59     });
60     Replacement.prototype.apply = function (content) {
61         return (content.substring(0, this.start) +
62             this.text +
63             content.substring(this.start + this.length));
64     };
65     Replacement.prototype.toJson = function () {
66         // tslint:disable object-literal-sort-keys
67         return {
68             innerStart: this.start,
69             innerLength: this.length,
70             innerText: this.text,
71         };
72         // tslint:enable object-literal-sort-keys
73     };
74     return Replacement;
75 }());
76 exports.Replacement = Replacement;
77 var RuleFailurePosition = /** @class */ (function () {
78     function RuleFailurePosition(position, lineAndCharacter) {
79         this.position = position;
80         this.lineAndCharacter = lineAndCharacter;
81     }
82     RuleFailurePosition.prototype.getPosition = function () {
83         return this.position;
84     };
85     RuleFailurePosition.prototype.getLineAndCharacter = function () {
86         return this.lineAndCharacter;
87     };
88     RuleFailurePosition.prototype.toJson = function () {
89         return {
90             character: this.lineAndCharacter.character,
91             line: this.lineAndCharacter.line,
92             position: this.position,
93         };
94     };
95     RuleFailurePosition.prototype.equals = function (ruleFailurePosition) {
96         var ll = this.lineAndCharacter;
97         var rr = ruleFailurePosition.lineAndCharacter;
98         return (this.position === ruleFailurePosition.position &&
99             ll.line === rr.line &&
100             ll.character === rr.character);
101     };
102     return RuleFailurePosition;
103 }());
104 exports.RuleFailurePosition = RuleFailurePosition;
105 var RuleFailure = /** @class */ (function () {
106     function RuleFailure(sourceFile, start, end, failure, ruleName, fix) {
107         this.sourceFile = sourceFile;
108         this.failure = failure;
109         this.ruleName = ruleName;
110         this.fix = fix;
111         this.fileName = sourceFile.fileName;
112         this.startPosition = this.createFailurePosition(start);
113         this.endPosition = this.createFailurePosition(end);
114         this.rawLines = sourceFile.text;
115         this.ruleSeverity = "error";
116     }
117     RuleFailure.compare = function (a, b) {
118         if (a.fileName !== b.fileName) {
119             return a.fileName < b.fileName ? -1 : 1;
120         }
121         return a.startPosition.getPosition() - b.startPosition.getPosition();
122     };
123     RuleFailure.prototype.getFileName = function () {
124         return this.fileName;
125     };
126     RuleFailure.prototype.getRuleName = function () {
127         return this.ruleName;
128     };
129     RuleFailure.prototype.getStartPosition = function () {
130         return this.startPosition;
131     };
132     RuleFailure.prototype.getEndPosition = function () {
133         return this.endPosition;
134     };
135     RuleFailure.prototype.getFailure = function () {
136         return this.failure;
137     };
138     RuleFailure.prototype.hasFix = function () {
139         return this.fix !== undefined;
140     };
141     RuleFailure.prototype.getFix = function () {
142         return this.fix;
143     };
144     RuleFailure.prototype.getRawLines = function () {
145         return this.rawLines;
146     };
147     RuleFailure.prototype.getRuleSeverity = function () {
148         return this.ruleSeverity;
149     };
150     RuleFailure.prototype.setRuleSeverity = function (value) {
151         this.ruleSeverity = value;
152     };
153     RuleFailure.prototype.toJson = function () {
154         return {
155             endPosition: this.endPosition.toJson(),
156             failure: this.failure,
157             fix: this.fix === undefined
158                 ? undefined
159                 : Array.isArray(this.fix)
160                     ? this.fix.map(function (r) { return r.toJson(); })
161                     : this.fix.toJson(),
162             name: this.fileName,
163             ruleName: this.ruleName,
164             ruleSeverity: this.ruleSeverity.toUpperCase(),
165             startPosition: this.startPosition.toJson(),
166         };
167     };
168     RuleFailure.prototype.equals = function (ruleFailure) {
169         return (this.failure === ruleFailure.getFailure() &&
170             this.fileName === ruleFailure.getFileName() &&
171             this.startPosition.equals(ruleFailure.getStartPosition()) &&
172             this.endPosition.equals(ruleFailure.getEndPosition()));
173     };
174     RuleFailure.prototype.createFailurePosition = function (position) {
175         var lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position);
176         return new RuleFailurePosition(position, lineAndCharacter);
177     };
178     return RuleFailure;
179 }());
180 exports.RuleFailure = RuleFailure;