jsonFormatter.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 abstractFormatter_1 = require("../language/formatter/abstractFormatter");
  21. var Utils = require("../utils");
  22. var Formatter = /** @class */ (function (_super) {
  23. tslib_1.__extends(Formatter, _super);
  24. function Formatter() {
  25. return _super !== null && _super.apply(this, arguments) || this;
  26. }
  27. /* tslint:enable:object-literal-sort-keys */
  28. Formatter.prototype.format = function (failures) {
  29. var failuresJSON = failures.map(function (failure) { return failure.toJson(); });
  30. return JSON.stringify(failuresJSON);
  31. };
  32. /* tslint:disable:object-literal-sort-keys */
  33. Formatter.metadata = {
  34. formatterName: "json",
  35. description: "Formats errors as simple JSON.",
  36. sample: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n [\n {\n \"endPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n },\n \"failure\": \"Missing semicolon\",\n \"fix\": {\n \"innerStart\": 13,\n \"innerLength\": 0,\n \"innerText\": \";\"\n },\n \"name\": \"myFile.ts\",\n \"ruleName\": \"semicolon\",\n \"startPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n }\n }\n ]"], ["\n [\n {\n \"endPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n },\n \"failure\": \"Missing semicolon\",\n \"fix\": {\n \"innerStart\": 13,\n \"innerLength\": 0,\n \"innerText\": \";\"\n },\n \"name\": \"myFile.ts\",\n \"ruleName\": \"semicolon\",\n \"startPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n }\n }\n ]"]))),
  37. consumer: "machine",
  38. };
  39. return Formatter;
  40. }(abstractFormatter_1.AbstractFormatter));
  41. exports.Formatter = Formatter;
  42. var templateObject_1;