]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix an issue with PHPCS output formatting
authorepriestley <git@epriestley.com>
Tue, 10 Sep 2013 22:10:34 +0000 (15:10 -0700)
committerepriestley <git@epriestley.com>
Tue, 10 Sep 2013 22:10:34 +0000 (15:10 -0700)
Summary:
See <https://github.com/facebook/arcanist/issues/102>. PHPCS changed its output format sometime between 1.4.6 (stable) and 1.5.0RC3.

Add a "no errors" test and make the linter work on both versions.

Test Plan: Ran `arc unit` on PHPCS 1.5.0RC3.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran
Differential Revision: https://secure.phabricator.com/D6926

src/lint/linter/ArcanistPhpcsLinter.php
src/lint/linter/__tests__/phpcs/no-errors.lint-test [new file with mode: 0644]

index ace53f074a55f104649ad896a89008d6c1e78128..ff34a185e8decbf1c72542f7463554c214b31c53 100644 (file)
@@ -62,6 +62,13 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
   }
 
   protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+    // NOTE: Some version of PHPCS after 1.4.6 stopped printing a valid, empty
+    // XML document to stdout in the case of no errors. If PHPCS exits with
+    // error 0, just ignore output.
+    if (!$err) {
+      return array();
+    }
+
     $report_dom = new DOMDocument();
     $ok = @$report_dom->loadXML($stdout);
     if (!$ok) {
diff --git a/src/lint/linter/__tests__/phpcs/no-errors.lint-test b/src/lint/linter/__tests__/phpcs/no-errors.lint-test
new file mode 100644 (file)
index 0000000..784acd6
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * This tests for a PHPCS lint run against a file without any errors. PHPCS
+ * literally requires all of this with this exact spacing and formatting.
+ *
+ * PHP version 5
+ *
+ * @category Function
+ * @package  None
+ * @author   Abraham Lincoln <alincoln@logcab.in>
+ * @license  Imaginary License http://www.example.com/LICENSE
+ * @version  GIT: HEAD
+ * @link     http://www.derp.com/
+ */
+
+/**
+ * A function.
+ *
+ * @return void
+ */
+function f()
+{
+
+}
+~~~~~~~~~~