Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/CheckDocLinter.php
<?php | <?php | ||||
/** | /** | ||||
* Uses the check-doc.py script to enfore command line arguments documentation | * Uses the check-doc.py script to enfore command line arguments documentation | ||||
*/ | */ | ||||
final class CheckDocLinter extends ArcanistExternalLinter { | final class CheckDocLinter extends ArcanistExternalLinter | ||||
{ | |||||
public function getInfoName() { | public function getInfoName() | ||||
{ | |||||
return 'check-doc'; | return 'check-doc'; | ||||
} | } | ||||
public function getInfoURI() { | public function getInfoURI() | ||||
{ | |||||
return ''; | return ''; | ||||
} | } | ||||
public function getInfoDescription() { | public function getInfoDescription() | ||||
{ | |||||
return pht('Check that all the command line arguments are documented.'); | return pht('Check that all the command line arguments are documented.'); | ||||
} | } | ||||
public function getLinterName() { | public function getLinterName() | ||||
{ | |||||
return 'check-doc'; | return 'check-doc'; | ||||
} | } | ||||
public function getLinterConfigurationName() { | public function getLinterConfigurationName() | ||||
{ | |||||
return 'check-doc'; | return 'check-doc'; | ||||
} | } | ||||
public function getLinterConfigurationOptions() { | public function getLinterConfigurationOptions() | ||||
$options = array( | { | ||||
); | $options = array(); | ||||
return $options + parent::getLinterConfigurationOptions(); | return $options + parent::getLinterConfigurationOptions(); | ||||
} | } | ||||
public function getDefaultBinary() { | public function getDefaultBinary() | ||||
{ | |||||
return Filesystem::resolvePath( | return Filesystem::resolvePath( | ||||
'test/lint/check-doc.py', | 'test/lint/check-doc.py', | ||||
$this->getProjectRoot()); | $this->getProjectRoot() | ||||
); | |||||
} | } | ||||
public function shouldUseInterpreter() { | public function shouldUseInterpreter() | ||||
{ | |||||
return true; | return true; | ||||
} | } | ||||
public function getDefaultInterpreter() { | public function getDefaultInterpreter() | ||||
{ | |||||
return "python3"; | return "python3"; | ||||
} | } | ||||
public function getInstallInstructions() { | public function getInstallInstructions() | ||||
return pht('The test/lint/check-doc.py script is part of the bitcoin-abc project'); | { | ||||
return pht('The test/lint/check-doc.py script is part of the '. | |||||
'bitcoin-abc project'); | |||||
} | } | ||||
public function shouldExpectCommandErrors() { | public function shouldExpectCommandErrors() | ||||
{ | |||||
return false; | return false; | ||||
} | } | ||||
protected function getMandatoryFlags() { | protected function getMandatoryFlags() | ||||
return array( | { | ||||
); | return array(); | ||||
} | } | ||||
protected function parseLinterOutput($path, $err, $stdout, $stderr) { | protected function parseLinterOutput($path, $err, $stdout, $stderr) | ||||
{ | |||||
/* Split stdout: | /* Split stdout: | ||||
* 0 => Empty (before first 'Args' occurence) | * 0 => Empty (before first 'Args' occurence) | ||||
* 1 => Args used: count | * 1 => Args used: count | ||||
* 2 => Args documented: count | * 2 => Args documented: count | ||||
* 3 => Args undocumented: count and list | * 3 => Args undocumented: count and list | ||||
* 4 => Args unknown: count and list | * 4 => Args unknown: count and list | ||||
*/ | */ | ||||
$stdoutExploded = preg_split('/Args/', $stdout); | $stdoutExploded = preg_split('/Args/', $stdout); | ||||
$undocumented = $stdoutExploded[3]; | $undocumented = $stdoutExploded[3]; | ||||
$unknown = $stdoutExploded[4]; | $unknown = $stdoutExploded[4]; | ||||
$messages = array(); | $messages = array(); | ||||
// Undocumented arguments | // Undocumented arguments | ||||
$match = preg_match_all('/-[\w|-]+/', $undocumented, $args); | $match = preg_match_all('/-[\w|-]+/', $undocumented, $args); | ||||
foreach($args[0] as $arg) { | foreach ($args[0] as $arg) { | ||||
$messages[] = id(new ArcanistLintMessage()) | $messages[] = id(new ArcanistLintMessage()) | ||||
->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) | ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) | ||||
->setCode('ARGDOC') | ->setCode('ARGDOC') | ||||
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ||||
->setName('Undocumented argument') | ->setName('Undocumented argument') | ||||
->setDescription("'$arg' is undocumented."); | ->setDescription("'$arg' is undocumented."); | ||||
} | } | ||||
// Unknown arguments | // Unknown arguments | ||||
$match = preg_match_all('/-[\w|-]+/', $unknown, $args); | $match = preg_match_all('/-[\w|-]+/', $unknown, $args); | ||||
foreach($args[0] as $arg) { | foreach ($args[0] as $arg) { | ||||
$messages[] = id(new ArcanistLintMessage()) | $messages[] = id(new ArcanistLintMessage()) | ||||
->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) | ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) | ||||
->setCode('ARGDOC') | ->setCode('ARGDOC') | ||||
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) | ||||
->setName('Unknown argument') | ->setName('Unknown argument') | ||||
->setDescription("'$arg' is documented but not used."); | ->setDescription("'$arg' is documented but not used."); | ||||
} | } | ||||
return $messages; | return $messages; | ||||
} | } | ||||
} | } | ||||
?> |