Page MenuHomePhabricator

D9083.id21586.diff
No OneTemporary

D9083.id21586.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -91,6 +91,7 @@
'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 @@
'ArcanistLesscLinter' => 'ArcanistExternalLinter',
'ArcanistLesscLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistLiberateWorkflow' => 'ArcanistBaseWorkflow',
+ 'ArcanistLintCheckstyleXMLRenderer' => 'ArcanistLintRenderer',
'ArcanistLintConsoleRenderer' => 'ArcanistLintRenderer',
'ArcanistLintJSONRenderer' => 'ArcanistLintRenderer',
'ArcanistLintLikeCompilerRenderer' => 'ArcanistLintRenderer',
diff --git a/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php b/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * Shows lint messages to the user.
+ *
+ * @group lint
+ */
+final class ArcanistLintCheckstyleXMLRenderer extends ArcanistLintRenderer {
+
+ public function renderPreamble() {
+ return '<?xml version="1.0" encoding="utf-8"?>'.
+ '<checkstyle version="4.3">';
+ }
+
+ public function renderLintResult(ArcanistLintResult $result) {
+ $file = new SimpleXMLElement('<file/>', LIBXML_NOXMLDECL);
+ $file->addAttribute('name', $result->getPath());
+
+ foreach ($result->getMessages() as $message) {
+ $error = $file->addChild('error');
+ $error->addAttribute('line', $message->getLine());
+ $error->addAttribute('column', $message->getChar());
+ $error->addAttribute(
+ 'severity',
+ ArcanistLintSeverity::getStringForSeverity($message->getSeverity()));
+ $error->addAttribute('message', $message->getDescription());
+ $error->addAttribute('source', $message->getCode());
+ }
+
+ return preg_replace('/^.+\n/', '', $file->asXML());
+ }
+
+ public function renderOkayResult() {
+ return '';
+ }
+
+ public function renderPostamble() {
+ return '</checkstyle>';
+ }
+}
diff --git a/src/lint/renderer/ArcanistLintRenderer.php b/src/lint/renderer/ArcanistLintRenderer.php
--- a/src/lint/renderer/ArcanistLintRenderer.php
+++ b/src/lint/renderer/ArcanistLintRenderer.php
@@ -7,7 +7,15 @@
*/
abstract class ArcanistLintRenderer {
+ public function renderPreamble() {
+ return '';
+ }
+
abstract public function renderLintResult(ArcanistLintResult $result);
abstract public function renderOkayResult();
+ public function renderPostamble() {
+ return '';
+ }
+
}
diff --git a/src/workflow/ArcanistLintWorkflow.php b/src/workflow/ArcanistLintWorkflow.php
--- a/src/workflow/ArcanistLintWorkflow.php
+++ b/src/workflow/ArcanistLintWorkflow.php
@@ -96,7 +96,8 @@
"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 @@
$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);
@@ -463,6 +467,7 @@
}
$all_autofix = true;
+ $console->writeOut('%s', $renderer->renderPreamble());
foreach ($results as $result) {
$result_all_autofix = $result->isAllAutofix();
@@ -514,6 +519,8 @@
}
}
+ $console->writeOut('%s', $renderer->renderPostamble());
+
if ($wrote_to_disk && $this->shouldAmendChanges) {
if ($this->shouldAmendWithoutPrompt ||
($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {

File Metadata

Mime Type
text/plain
Expires
Sat, May 10, 9:14 AM (4 h, 2 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7735094
Default Alt Text
D9083.id21586.diff (4 KB)

Event Timeline