1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-20 00:49:11 +02:00

Support Checkstyle as an output format for lint results.

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
This commit is contained in:
Joshua Spence 2014-05-13 13:20:29 -07:00 committed by epriestley
parent 85b6c581e1
commit ec3de41684
4 changed files with 66 additions and 1 deletions

View file

@ -91,6 +91,7 @@ phutil_register_library_map(array(
'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',
@ -262,6 +263,7 @@ phutil_register_library_map(array(
'ArcanistLesscLinter' => 'ArcanistExternalLinter',
'ArcanistLesscLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistLiberateWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistLintCheckstyleXMLRenderer' => 'ArcanistLintRenderer',
'ArcanistLintConsoleRenderer' => 'ArcanistLintRenderer',
'ArcanistLintJSONRenderer' => 'ArcanistLintRenderer',
'ArcanistLintLikeCompilerRenderer' => 'ArcanistLintRenderer',

View file

@ -0,0 +1,53 @@
<?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();
}
}

View file

@ -10,4 +10,8 @@ abstract class ArcanistLintRenderer {
abstract public function renderLintResult(ArcanistLintResult $result);
abstract public function renderOkayResult();
public function renderPostamble() {
return '';
}
}

View file

@ -96,7 +96,8 @@ EOTEXT
"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',
@ -456,6 +457,9 @@ EOTEXT
$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);
@ -514,6 +518,8 @@ EOTEXT
}
}
$console->writeOut('%s', $renderer->renderPostamble());
if ($wrote_to_disk && $this->shouldAmendChanges) {
if ($this->shouldAmendWithoutPrompt ||
($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {