Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistScalastyleLinter.php
- This file was added.
<?php | |||||
final class ArcanistScalastyleLinter extends ArcanistExternalLinter { | |||||
private $jarPath = null; | |||||
private $configPath = null; | |||||
public function getInfoURI() { | |||||
return 'http://www.scalastyle.org/'; | |||||
} | |||||
public function getInfoDescription() { | |||||
return 'Scalastyle linter for Scala code'; | |||||
joshuaspence: This should be wrapped in a call to the `pht()` function so that it is translatable. | |||||
} | |||||
public function getLinterName() { | |||||
return 'scalastyle'; | |||||
} | |||||
public function getLinterConfigurationName() { | |||||
return 'scalastyle'; | |||||
} | |||||
public function getDefaultBinary() { | |||||
return 'java'; | |||||
} | |||||
public function getInstallInstructions() { | |||||
return 'See http://www.scalastyle.org/command-line.html'; | |||||
} | |||||
public function shouldExpectCommandErrors() { | |||||
return true; | |||||
} | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsThis is the default behaviour, so you don't need to override this method explicitly. joshuaspence: This is the default behaviour, so you don't need to override this method explicitly. | |||||
protected function getMandatoryFlags() { | |||||
if ($this->jarPath === null) { | |||||
throw new ArcanistUsageException( | |||||
pht('Scalastyle JAR path must be configured.')); | |||||
} | |||||
if ($this->configPath === null) { | |||||
throw new ArcanistUsageException( | |||||
pht('Scalastyle config XML path must be configured.')); | |||||
} | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsYou should be able to remove the optional type specifier from getLinterConfigurationOptions() instead. joshuaspence: You should be able to remove the `optional` type specifier from `getLinterConfigurationOptions… | |||||
return array( | |||||
'-jar', $this->jarPath, | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsPrefer '-jar='.$this->jarPath joshuaspence: Prefer `'-jar='.$this->jarPath` | |||||
'--config', $this->configPath, | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsAs above. joshuaspence: As above. | |||||
'--quiet', 'true'); | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsPrefer --quiet (without true). joshuaspence: Prefer `--quiet` (without `true`). | |||||
} | |||||
protected function getDefaultFlags() { | |||||
return array(); | |||||
} | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsJust remove this. joshuaspence: Just remove this. | |||||
protected function parseLinterOutput($path, $err, $stdout, $stderr) { | |||||
$messages = array(); | |||||
$output = trim($stdout); | |||||
if (strlen($output) === 0) { | |||||
return $messages; | |||||
} | |||||
$lines = explode(PHP_EOL, $output); | |||||
foreach ($lines as $line) { | |||||
$lintMessage = id(new ArcanistLintMessage()) | |||||
->setPath($path) | |||||
->setCode($this->getLinterName()); | |||||
$matches = array(); | |||||
if (preg_match('/^([a-z]+)/', $line, $matches)) { | |||||
switch ($matches[1]) { | |||||
case 'warning': | |||||
$lintMessage->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); | |||||
break; | |||||
case 'error': | |||||
$lintMessage->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); | |||||
break; | |||||
} | |||||
} | |||||
$matches = array(); | |||||
if (preg_match('/message=([^=]+ )/', $line, $matches)) { | |||||
$lintMessage->setDescription(trim($matches[1])); | |||||
} else if (preg_match('/message=([^=]+$)/', $line, $matches)) { | |||||
$lintMessage->setDescription(trim($matches[1])); | |||||
} | |||||
$matches = array(); | |||||
if (preg_match('/line=([^=]+ )/', $line, $matches)) { | |||||
$lintMessage->setLine(trim($matches[1])); | |||||
} else if (preg_match('/line=([^=]+$)/', $line, $matches)) { | |||||
$lintMessage->setLine(trim($matches[1])); | |||||
} | |||||
$matches = array(); | |||||
if (preg_match('/column=([^=]+ )/', $line, $matches)) { | |||||
$lintMessage->setChar(trim($matches[1])); | |||||
} else if (preg_match('/column=([^=]+$)/', $line, $matches)) { | |||||
$lintMessage->setChar(trim($matches[1])); | |||||
} | |||||
$messages[] = $lintMessage; | |||||
} | |||||
return $messages; | |||||
} | |||||
public function getLinterConfigurationOptions() { | |||||
$options = array( | |||||
'jar' => array( | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsShould be namespaced as scalastyle.jar joshuaspence: Should be namespaced as `scalastyle.jar` | |||||
'type' => 'optional string | list<string>', | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsWhy a list of strings? joshuaspence: Why a list of strings? | |||||
'help' => pht( | |||||
'Specify a string (or list of strings) identifying the Scalastyle '. | |||||
'JAR file.') | |||||
), | |||||
'config' => array( | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsAs above. joshuaspence: As above. | |||||
'type' => 'optional string | list<string>', | |||||
joshuaspenceUnsubmitted Not Done Inline ActionsWhy a list of strings? joshuaspence: Why a list of strings? | |||||
'help' => pht( | |||||
'Specify a string (or list of strings) identifying the Scalastyle '. | |||||
'config XML file.') | |||||
), | |||||
); | |||||
return $options + parent::getLinterConfigurationOptions(); | |||||
} | |||||
public function setLinterConfigurationValue($key, $value) { | |||||
switch ($key) { | |||||
case 'jar': | |||||
$working_copy = $this->getEngine()->getWorkingCopy(); | |||||
$root = $working_copy->getProjectRoot(); | |||||
foreach ((array)$value as $path) { | |||||
if (Filesystem::pathExists($path)) { | |||||
$this->jarPath = $path; | |||||
return; | |||||
} | |||||
$path = Filesystem::resolvePath($path, $root); | |||||
if (Filesystem::pathExists($path)) { | |||||
$this->jarPath = $path; | |||||
return; | |||||
} | |||||
} | |||||
throw new ArcanistUsageException( | |||||
pht('None of the configured Scalastyle JARs can be located.')); | |||||
case 'config': | |||||
$working_copy = $this->getEngine()->getWorkingCopy(); | |||||
$root = $working_copy->getProjectRoot(); | |||||
foreach ((array)$value as $path) { | |||||
if (Filesystem::pathExists($path)) { | |||||
$this->configPath = $path; | |||||
return; | |||||
} | |||||
$path = Filesystem::resolvePath($path, $root); | |||||
if (Filesystem::pathExists($path)) { | |||||
$this->configPath = $path; | |||||
return; | |||||
} | |||||
} | |||||
throw new ArcanistUsageException( | |||||
pht('None of the configured Scalastyle configs can be located.')); | |||||
} | |||||
return parent::setLinterConfigurationValue($key, $value); | |||||
} | |||||
} |
This should be wrapped in a call to the pht() function so that it is translatable.