Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistHLintLinter.php
| Show All 24 Lines | public function getLinterConfigurationName() { | ||||
| return 'hlint'; | return 'hlint'; | ||||
| } | } | ||||
| public function getDefaultBinary() { | public function getDefaultBinary() { | ||||
| return 'hlint'; | return 'hlint'; | ||||
| } | } | ||||
| public function getInstallInstructions() { | public function getInstallInstructions() { | ||||
| return pht('Install hlint with `cabal install hlint`.'); | return pht('Install hlint with `%s`.', 'cabal install hlint'); | ||||
| } | } | ||||
| protected function getMandatoryFlags() { | protected function getMandatoryFlags() { | ||||
| return array('--json'); | return array('--json'); | ||||
| } | } | ||||
| public function getVersion() { | public function getVersion() { | ||||
| list($stdout, $stderr) = execx( | list($stdout, $stderr) = execx( | ||||
| '%C --version', $this->getExecutableCommand()); | '%C --version', $this->getExecutableCommand()); | ||||
| $matches = null; | $matches = null; | ||||
| if (preg_match('@HLint v(.*),@', $stdout, $matches)) { | if (preg_match('@HLint v(.*),@', $stdout, $matches)) { | ||||
| return $matches[1]; | return $matches[1]; | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| protected function parseLinterOutput($path, $err, $stdout, $stderr) { | protected function parseLinterOutput($path, $err, $stdout, $stderr) { | ||||
| $json = phutil_json_decode($stdout); | $json = phutil_json_decode($stdout); | ||||
| $messages = array(); | $messages = array(); | ||||
| foreach ($json as $fix) { | foreach ($json as $fix) { | ||||
| if ($fix === null) { | if ($fix === null) { | ||||
| return; | return; | ||||
| } | } | ||||
| $message = new ArcanistLintMessage(); | $message = new ArcanistLintMessage(); | ||||
| $message->setCode($this->getLinterName()); | $message->setCode($this->getLinterName()); | ||||
| $message->setPath($path); | $message->setPath($path); | ||||
| $message->setLine($fix['startLine']); | $message->setLine($fix['startLine']); | ||||
| $message->setChar($fix['startColumn']); | $message->setChar($fix['startColumn']); | ||||
| $message->setName($fix['hint']); | $message->setName($fix['hint']); | ||||
| $message->setOriginalText($fix['from']); | $message->setOriginalText($fix['from']); | ||||
| $message->setReplacementText($fix['to']); | $message->setReplacementText($fix['to']); | ||||
| /* Some improvements may slightly change semantics, so attach | /* Some improvements may slightly change semantics, so attach | ||||
| all necessary notes too. */ | all necessary notes too. */ | ||||
| $notes = ''; | $notes = ''; | ||||
| foreach ($fix['note'] as $note) { | foreach ($fix['note'] as $note) { | ||||
| $notes .= ' **NOTE**: '.trim($note, '"').'.'; | $notes .= phutil_console_format( | ||||
| ' **%s**: %s.', | |||||
| pht('NOTE'), | |||||
| trim($note, '"')); | |||||
| } | } | ||||
| $message->setDescription( | $message->setDescription( | ||||
| pht( | pht( | ||||
| 'In module `%s`, declaration `%s`.%s', | 'In module `%s`, declaration `%s`.', | ||||
| $fix['module'], $fix['decl'], $notes)); | $fix['module'], | ||||
| $fix['decl']).$notes); | |||||
| switch ($fix['severity']) { | switch ($fix['severity']) { | ||||
| case 'Error': | case 'Error': | ||||
| $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); | $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); | ||||
| break; | break; | ||||
| case 'Warning': | case 'Warning': | ||||
| $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); | $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); | ||||
| break; | break; | ||||
| Show All 11 Lines | |||||