From b780ef0868e24f4c9fdd550507fb0ba49a2570e1 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 12 Jan 2015 07:22:42 +1100 Subject: [PATCH] Use the `raw` formatter for `coffeelint` Summary: Using `--reporter=raw` exposes raw JSON output rather than a limited XML output. This allows us to pull more context from the `coffeelint` output. Test Plan: `arc unit` Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11320 --- src/lint/linter/ArcanistCoffeeLintLinter.php | 33 ++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/lint/linter/ArcanistCoffeeLintLinter.php b/src/lint/linter/ArcanistCoffeeLintLinter.php index 9161fd14..66319037 100644 --- a/src/lint/linter/ArcanistCoffeeLintLinter.php +++ b/src/lint/linter/ArcanistCoffeeLintLinter.php @@ -57,7 +57,7 @@ final class ArcanistCoffeeLintLinter extends ArcanistExternalLinter { protected function getMandatoryFlags() { $options = array( - '--reporter=checkstyle', + '--reporter=raw', ); if ($this->config) { @@ -89,32 +89,29 @@ final class ArcanistCoffeeLintLinter extends ArcanistExternalLinter { } protected function parseLinterOutput($path, $err, $stdout, $stderr) { - $report_dom = new DOMDocument(); - $ok = @$report_dom->loadXML($stdout); + $messages = array(); + $output = phutil_json_decode($stdout); - if (!$ok) { + // We are only linting a single file. + if (count($output) != 1) { return false; } - $files = $report_dom->getElementsByTagName('file'); - $messages = array(); - - foreach ($files as $file) { - foreach ($file->getElementsByTagName('error') as $error) { + foreach ($output as $reports) { + foreach ($reports as $report) { // Column number is not provided in the output. // See https://github.com/clutchski/coffeelint/issues/87 $message = id(new ArcanistLintMessage()) ->setPath($path) - ->setLine($error->getAttribute('line')) + ->setLine($report['lineNumber']) ->setCode($this->getLinterName()) - ->setDescription(preg_replace( - '/; context: .*$/', - '.', - $error->getAttribute('message'))); + ->setName(ucwords(str_replace('_', ' ', $report['name']))) + ->setDescription($report['message']) + ->setOriginalText(idx($report, 'line')); - switch ($error->getAttribute('severity')) { - case 'warning': + switch ($report['level']) { + case 'warn': $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); break; @@ -131,6 +128,10 @@ final class ArcanistCoffeeLintLinter extends ArcanistExternalLinter { } } + if ($err && !$messages) { + return false; + } + return $messages; }