Summary: Fixes T4948. Add a lint renderer which supports outputting the lint results in the Checkstyle XML format.
Test Plan: Ran `arc lint --xml` and inspected the output.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley, Korvin
Maniphest Tasks: T4948
Differential Revision: https://secure.phabricator.com/D9083
'ArcanistLesscLinter' => 'lint/linter/ArcanistLesscLinter.php',
'ArcanistLesscLinterTestCase' => 'lint/linter/__tests__/ArcanistLesscLinterTestCase.php',
'ArcanistLiberateWorkflow' => 'workflow/ArcanistLiberateWorkflow.php',
+ 'ArcanistLintCheckstyleXMLRenderer' => 'lint/renderer/ArcanistLintCheckstyleXMLRenderer.php',
'ArcanistLintConsoleRenderer' => 'lint/renderer/ArcanistLintConsoleRenderer.php',
'ArcanistLintEngine' => 'lint/engine/ArcanistLintEngine.php',
'ArcanistLintJSONRenderer' => 'lint/renderer/ArcanistLintJSONRenderer.php',
'ArcanistLesscLinter' => 'ArcanistExternalLinter',
'ArcanistLesscLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistLiberateWorkflow' => 'ArcanistBaseWorkflow',
+ 'ArcanistLintCheckstyleXMLRenderer' => 'ArcanistLintRenderer',
'ArcanistLintConsoleRenderer' => 'ArcanistLintRenderer',
'ArcanistLintJSONRenderer' => 'ArcanistLintRenderer',
'ArcanistLintLikeCompilerRenderer' => 'ArcanistLintRenderer',
--- /dev/null
+<?php
+
+/**
+ * Shows lint messages to the user.
+ *
+ * @group lint
+ */
+final class ArcanistLintCheckstyleXMLRenderer extends ArcanistLintRenderer {
+
+ private $writer;
+
+ public function __construct() {
+ $this->writer = new XMLWriter();
+ $this->writer->openMemory();
+ $this->writer->setIndent(true);
+ $this->writer->setIndentString(' ');
+
+ $this->writer->startDocument('1.0', 'UTF-8');
+ $this->writer->startElement('checkstyle');
+ $this->writer->writeAttribute('version', '4.3');
+ }
+
+ public function renderLintResult(ArcanistLintResult $result) {
+ $this->writer->startElement('file');
+ $this->writer->writeAttribute('name', $result->getPath());
+
+ foreach ($result->getMessages() as $message) {
+ $this->writer->startElement('error');
+
+ $this->writer->writeAttribute('line', $message->getLine());
+ $this->writer->writeAttribute('column', $message->getChar());
+ $this->writer->writeAttribute('severity',
+ ArcanistLintSeverity::getStringForSeverity($message->getSeverity()));
+ $this->writer->writeAttribute('message', $message->getDescription());
+ $this->writer->writeAttribute('source', $message->getCode());
+
+ $this->writer->endElement();
+ }
+
+ $this->writer->endElement();
+ return $this->writer->flush();
+ }
+
+ public function renderOkayResult() {
+ return '';
+ }
+
+ public function renderPostamble() {
+ $this->writer->endElement();
+ $this->writer->endDocument();
+ return $this->writer->flush();
+ }
+}
abstract public function renderLintResult(ArcanistLintResult $result);
abstract public function renderOkayResult();
+ public function renderPostamble() {
+ return '';
+ }
+
}
"With 'summary', show lint warnings in a more compact format. ".
"With 'json', show lint warnings in machine-readable JSON format. ".
"With 'none', show no lint warnings. ".
- "With 'compiler', show lint warnings in suitable for your editor."
+ "With 'compiler', show lint warnings in suitable for your editor. ".
+ "With 'xml', show lint warnings in the Checkstyle XML format."
),
'only-new' => array(
'param' => 'bool',
$prompt_patches = false;
$apply_patches = $this->getArgument('apply-patches');
break;
+ case 'xml':
+ $renderer = new ArcanistLintCheckstyleXMLRenderer();
+ break;
default:
$renderer = new ArcanistLintConsoleRenderer();
$renderer->setShowAutofixPatches($prompt_autofix_patches);
}
}
+ $console->writeOut('%s', $renderer->renderPostamble());
+
if ($wrote_to_disk && $this->shouldAmendChanges) {
if ($this->shouldAmendWithoutPrompt ||
($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {