4 * Copyright 2013 Palantir Technologies, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var abstractFormatter_1 = require("../language/formatter/abstractFormatter");
21 var Formatter = /** @class */ (function (_super) {
22 tslib_1.__extends(Formatter, _super);
23 function Formatter() {
24 return _super !== null && _super.apply(this, arguments) || this;
26 /* tslint:enable:object-literal-sort-keys */
27 Formatter.prototype.format = function (failures, fixes) {
28 if (failures.length === 0 && (fixes === undefined || fixes.length === 0)) {
31 failures = this.sortFailures(failures);
33 if (fixes !== undefined) {
34 var perFileFixes = new Map();
35 for (var _i = 0, fixes_1 = fixes; _i < fixes_1.length; _i++) {
36 var fix = fixes_1[_i];
37 var prevFixes = perFileFixes.get(fix.getFileName());
38 perFileFixes.set(fix.getFileName(), (prevFixes !== undefined ? prevFixes : 0) + 1);
40 perFileFixes.forEach(function (fixCount, fixedFile) {
41 fixLines.push("Fixed " + fixCount + " error(s) in " + fixedFile);
43 fixLines.push(""); // add a blank line between fixes and failures
45 var errorLines = failures.map(function (failure) {
46 var fileName = failure.getFileName();
47 var failureString = failure.getFailure();
48 var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
49 var positionTuple = lineAndCharacter.line + 1 + ":" + (lineAndCharacter.character + 1);
52 .toUpperCase() + ": " + fileName + ":" + positionTuple + " - " + failureString;
54 return fixLines.concat(errorLines).join("\n") + "\n";
56 /* tslint:disable:object-literal-sort-keys */
57 Formatter.metadata = {
58 formatterName: "prose",
59 description: "The default formatter which outputs simple human-readable messages.",
60 sample: "ERROR: myFile.ts:1:14 - Missing semicolon",
64 }(abstractFormatter_1.AbstractFormatter));
65 exports.Formatter = Formatter;