From 9a13c87ac4a944273aba112a06f710ce73703cd1 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 5 May 2014 21:18:43 -0700 Subject: [PATCH] Parse JSON as an associate array. Summary: It seems that in some situations, JSHint does not set the `evidence` property. In such cases, PHP fails with `Undefined property: stdClass::$evidence`. It would be safer to access the error object as an associative array rather than as `stdClass`. Test Plan: N/A Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D8993 --- src/lint/linter/ArcanistJSHintLinter.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lint/linter/ArcanistJSHintLinter.php b/src/lint/linter/ArcanistJSHintLinter.php index 0463547a..3c241517 100644 --- a/src/lint/linter/ArcanistJSHintLinter.php +++ b/src/lint/linter/ArcanistJSHintLinter.php @@ -84,7 +84,7 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter { } protected function parseLinterOutput($path, $err, $stdout, $stderr) { - $errors = json_decode($stdout); + $errors = json_decode($stdout, true); if (!is_array($errors)) { // Something went wrong and we can't decode the output. Exit abnormally. @@ -98,13 +98,13 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter { foreach ($errors as $err) { $message = new ArcanistLintMessage(); $message->setPath($path); - $message->setLine($err->line); - $message->setChar($err->col); - $message->setCode($err->code); - $message->setName('JSHint'.$err->code); - $message->setDescription($err->reason); - $message->setSeverity($this->getLintMessageSeverity($err->code)); - $message->setOriginalText($err->evidence); + $message->setLine(idx($err, 'line')); + $message->setChar(idx($err, 'col')); + $message->setCode(idx($err, 'code')); + $message->setName('JSHint'.idx($err, 'code')); + $message->setDescription(idx($err, 'reason')); + $message->setSeverity($this->getLintMessageSeverity(idx($err, 'code'))); + $message->setOriginalText(idx($err, 'evidence')); $messages[] = $message; }