.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / formatters / codeFrameFormatter.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 code_frame_1 = require("@babel/code-frame");
21 var chalk_1 = require("chalk");
22 var abstractFormatter_1 = require("../language/formatter/abstractFormatter");
23 var Utils = require("../utils");
24 var Formatter = /** @class */ (function (_super) {
25     tslib_1.__extends(Formatter, _super);
26     function Formatter() {
27         return _super !== null && _super.apply(this, arguments) || this;
28     }
29     /* tslint:enable:object-literal-sort-keys */
30     Formatter.prototype.format = function (failures) {
31         if (typeof failures[0] === "undefined") {
32             return "\n";
33         }
34         failures = this.sortFailures(failures);
35         var outputLines = [];
36         var currentFile;
37         for (var _i = 0, failures_1 = failures; _i < failures_1.length; _i++) {
38             var failure = failures_1[_i];
39             var fileName = failure.getFileName();
40             // Output the name of each file once
41             if (currentFile !== fileName) {
42                 outputLines.push("");
43                 outputLines.push(fileName);
44                 currentFile = fileName;
45             }
46             var failureString = failure.getFailure();
47             failureString =
48                 failure.getRuleSeverity() === "warning"
49                     ? chalk_1.default.yellow(failureString)
50                     : chalk_1.default.red(failureString);
51             // Rule
52             var ruleName = failure.getRuleName();
53             ruleName = chalk_1.default.gray("(" + ruleName + ")");
54             // Frame
55             var _a = failure.getStartPosition().getLineAndCharacter(), column = _a.character, line = _a.line;
56             var frame = code_frame_1.codeFrameColumns(failure.getRawLines(), { start: { line: line + 1, column: column } }, // babel-code-frame is 1 index
57             {
58                 forceColor: chalk_1.default.enabled,
59                 highlightCode: true,
60             });
61             // Ouput
62             outputLines.push(failureString + " " + ruleName);
63             outputLines.push(frame);
64             outputLines.push("");
65         }
66         // Removes initial blank line
67         if (outputLines[0] === "") {
68             outputLines.shift();
69         }
70         return outputLines.join("\n") + "\n";
71     };
72     /* tslint:disable:object-literal-sort-keys */
73     Formatter.metadata = {
74         formatterName: "codeFrame",
75         description: "Framed formatter which creates a frame of error code.",
76         descriptionDetails: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Prints syntax highlighted code in a frame with a pointer to where\n            exactly lint error is happening."], ["\n            Prints syntax highlighted code in a frame with a pointer to where\n            exactly lint error is happening."]))),
77         sample: Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n            src/components/Payment.tsx\n            Parentheses are required around the parameters of an arrow function definition (arrow-parens)\n              21 |     public componentDidMount() {\n              22 |         this.input.focus();\n            > 23 |         loadStripe().then(Stripe => Stripe.pay());\n                 |                          ^\n              24 |     }\n              25 |\n              26 |     public render() {"], ["\n            src/components/Payment.tsx\n            Parentheses are required around the parameters of an arrow function definition (arrow-parens)\n              21 |     public componentDidMount() {\n              22 |         this.input.focus();\n            > 23 |         loadStripe().then(Stripe => Stripe.pay());\n                 |                          ^\n              24 |     }\n              25 |\n              26 |     public render() {"]))),
78         consumer: "human",
79     };
80     return Formatter;
81 }(abstractFormatter_1.AbstractFormatter));
82 exports.Formatter = Formatter;
83 var templateObject_1, templateObject_2;