pmdFormatter.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 output = "<pmd version=\"tslint\">";
  30. for (var _i = 0, failures_1 = failures; _i < failures_1.length; _i++) {
  31. var failure = failures_1[_i];
  32. var failureString = failure.getFailure()
  33. .replace(/&/g, "&amp;")
  34. .replace(/</g, "&lt;")
  35. .replace(/>/g, "&gt;")
  36. .replace(/'/g, "&#39;")
  37. .replace(/"/g, "&quot;");
  38. var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
  39. var priority = failure.getRuleSeverity() === "warning" ? 4 : 3;
  40. output += "<file name=\"" + failure.getFileName();
  41. output += "\"><violation begincolumn=\"" + (lineAndCharacter.character + 1);
  42. output += "\" beginline=\"" + (lineAndCharacter.line + 1);
  43. output += "\" priority=\"" + priority + "\"";
  44. output += " rule=\"" + failureString + "\"></violation></file>";
  45. }
  46. output += "</pmd>";
  47. return output;
  48. };
  49. /* tslint:disable:object-literal-sort-keys */
  50. Formatter.metadata = {
  51. formatterName: "pmd",
  52. description: "Formats errors as through they were PMD output.",
  53. descriptionDetails: "Imitates the XML output from PMD. All errors have a priority of 1.",
  54. sample: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n <pmd version=\"tslint\">\n <file name=\"myFile.ts\">\n <violation begincolumn=\"14\" beginline=\"1\" priority=\"3\" rule=\"Missing semicolon\"></violation>\n </file>\n </pmd>"], ["\n <pmd version=\"tslint\">\n <file name=\"myFile.ts\">\n <violation begincolumn=\"14\" beginline=\"1\" priority=\"3\" rule=\"Missing semicolon\"></violation>\n </file>\n </pmd>"]))),
  55. consumer: "machine",
  56. };
  57. return Formatter;
  58. }(abstractFormatter_1.AbstractFormatter));
  59. exports.Formatter = Formatter;
  60. var templateObject_1;