2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Uses "pep8.py" to enforce PEP8 rules for Python.
|
|
|
|
*/
|
2013-08-23 20:52:44 +02:00
|
|
|
final class ArcanistPEP8Linter extends ArcanistExternalLinter {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2014-05-11 22:42:56 +02:00
|
|
|
public function getInfoName() {
|
2015-09-14 20:45:15 +02:00
|
|
|
return 'Python PEP 8';
|
2014-05-11 22:42:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoURI() {
|
|
|
|
return 'https://pypi.python.org/pypi/pep8';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoDescription() {
|
|
|
|
return pht(
|
|
|
|
'pep8 is a tool to check your Python code against some of the '.
|
|
|
|
'style conventions in PEP 8.');
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function getLinterName() {
|
|
|
|
return 'PEP8';
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:58:07 +02:00
|
|
|
public function getLinterConfigurationName() {
|
|
|
|
return 'pep8';
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getDefaultBinary() {
|
2015-05-20 22:57:23 +02:00
|
|
|
return 'pep8';
|
2013-08-23 20:52:44 +02:00
|
|
|
}
|
2013-02-15 01:16:08 +01:00
|
|
|
|
Add a `getVersion` function to `ArcanistExternalLinter`.
Summary:
This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work).
Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used.
Fixes T4954.
Test Plan: I'm not sure how to test this.
Reviewers: chad, epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin
Maniphest Tasks: T4954
Differential Revision: https://secure.phabricator.com/D8971
2014-05-06 00:10:20 +02:00
|
|
|
public function getVersion() {
|
|
|
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
|
|
|
|
|
|
|
$matches = array();
|
2015-02-10 15:17:25 +01:00
|
|
|
if (preg_match('/^(?P<version>\d+\.\d+(?:\.\d+)?)\b/', $stdout, $matches)) {
|
Add a `getVersion` function to `ArcanistExternalLinter`.
Summary:
This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work).
Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used.
Fixes T4954.
Test Plan: I'm not sure how to test this.
Reviewers: chad, epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin
Maniphest Tasks: T4954
Differential Revision: https://secure.phabricator.com/D8971
2014-05-06 00:10:20 +02:00
|
|
|
return $matches['version'];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getInstallInstructions() {
|
2016-04-29 17:45:11 +02:00
|
|
|
return pht('Install PEP8 using `%s`.', 'pip install pep8');
|
2013-08-23 20:52:44 +02:00
|
|
|
}
|
2013-02-15 01:16:08 +01:00
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
|
2014-06-20 10:26:44 +02:00
|
|
|
$lines = phutil_split_lines($stdout, false);
|
2013-08-23 20:52:44 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$messages = array();
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
$matches = null;
|
|
|
|
if (!preg_match('/^(.*?):(\d+):(\d+): (\S+) (.*)$/', $line, $matches)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($matches as $key => $match) {
|
|
|
|
$matches[$key] = trim($match);
|
|
|
|
}
|
|
|
|
$message = new ArcanistLintMessage();
|
|
|
|
$message->setPath($path);
|
|
|
|
$message->setLine($matches[2]);
|
|
|
|
$message->setChar($matches[3]);
|
|
|
|
$message->setCode($matches[4]);
|
|
|
|
$message->setName('PEP8 '.$matches[4]);
|
|
|
|
$message->setDescription($matches[5]);
|
2013-08-23 20:58:07 +02:00
|
|
|
$message->setSeverity($this->getLintMessageSeverity($matches[4]));
|
2013-08-23 20:52:44 +02:00
|
|
|
|
|
|
|
$messages[] = $message;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
2013-08-23 20:52:44 +02:00
|
|
|
|
|
|
|
return $messages;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:58:07 +02:00
|
|
|
protected function getDefaultMessageSeverity($code) {
|
|
|
|
if (preg_match('/^W/', $code)) {
|
|
|
|
return ArcanistLintSeverity::SEVERITY_WARNING;
|
|
|
|
} else {
|
2014-06-15 20:50:59 +02:00
|
|
|
return ArcanistLintSeverity::SEVERITY_ERROR;
|
2013-08-23 20:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getLintCodeFromLinterConfigurationKey($code) {
|
|
|
|
if (!preg_match('/^(E|W)\d+$/', $code)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Unrecognized lint message code "%s". Expected a valid PEP8 '.
|
|
|
|
'lint code like "%s" or "%s".',
|
|
|
|
$code,
|
2014-05-23 22:53:05 +02:00
|
|
|
'E101',
|
|
|
|
'W291'));
|
2013-08-23 20:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|