From f0efe0a7262d18807f5ed13a33e5dd9cc8727586 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Tue, 16 Feb 2021 11:17:44 -0800 Subject: [PATCH] Handle missing "offense" values (#63) We've encountered a number of cases where the eslint result doesn't include values for all of these expected keys. Harden the code for these cases using idx(). The internal Arcanist interface allows these values to be `null`, which is idx()'s default value. --- src/ESLintLinter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ESLintLinter.php b/src/ESLintLinter.php index 485f84a..6ba6831 100644 --- a/src/ESLintLinter.php +++ b/src/ESLintLinter.php @@ -131,11 +131,11 @@ protected function parseLinterOutput($path, $err, $stdout, $stderr) { $message = new ArcanistLintMessage(); $message->setPath($file['filePath']); - $message->setSeverity($this->mapSeverity($offense['severity'])); + $message->setSeverity($this->mapSeverity(idx($offense, 'severity', '0'))); $message->setName(nonempty(idx($offense, 'ruleId'), 'unknown')); - $message->setDescription($offense['message']); - $message->setLine($offense['line']); - $message->setChar($offense['column']); + $message->setDescription(idx($offense, 'message')); + $message->setLine(idx($offense, 'line')); + $message->setChar(idx($offense, 'column')); $message->setCode($this->getLinterName()); $messages[] = $message; }