Event Timeline
Comment Actions
It appears that the ArcanistLintMessage has correctly determined the diff, but the diff that is proposed to be applied is wrong.
wrong stuff:
- remove line 70
- add line 78
- line 106-108 came from nowhere (a newline was removed for some reason)
- line 115 is added
Comment Actions
how I ended up doing it:
protected function parseLinterOutput($path, $err, $stdout, $stderr) { $messages = array(); $matches = split("\n", $stdout, 2); $description = $matches[0]; $diff = $matches[1]; $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($diff); foreach ($changes as $change) { foreach ($change->getHunks() as $hunk) { $oldText = array(); $newText = array(); $replacementText = ""; $originalText = ""; $lines = phutil_split_lines($hunk->getCorpus(), false); foreach ($lines as $line) { $char = strlen($line) ? $line[0] : '~'; $rest = "\n" . strlen($line) == 1 ? '' : substr($line, 1); switch ($char) { case '-': $originalText .= $rest; break; case '+': $replacementText .= $rest; break; case '~': break; case ' ': $originalText .= $rest; $replacementText .= $rest; break; } } $message = new ArcanistLintMessage(); $message->setPath($path); $message->setLine($hunk->getOldOffset()); $message->setChar(0); $message->setCode('Improper imports'); $message->setName('ISORT'); // $message->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX); $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); $message->setReplacementText($replacementText); $message->setOriginalText($originalText); $messages[] = $message; } } if ($err && !$messages) { return false; } return $messages; }