1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-10 06:41:04 +01:00
phorge-arcanist/src/lint/linter/ArcanistPyFlakesLinter.php
epriestley 7870e7f2e4 Warn when accessing deprecated lint config
Summary:
Ref T2039. Addresses two issues:

  - Issues a warning for use of config which is deprecated by `.arclint`.
  - We no longer require an engine to be present for these linters, so `arc linters` doesn't fatal if they aren't configured.

Test Plan:
  - Ran `arc linters` in a repo with no JSHint.
  - Ran `arc linters` in a repo with junk in .arcconfig and got a warning when it was read. Verified it still took effect.

Reviewers: chad, btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T2039

Differential Revision: https://secure.phabricator.com/D9058
2014-05-11 18:39:28 -07:00

102 lines
2.4 KiB
PHP

<?php
/**
* Uses "PyFlakes" to detect various errors in Python code.
*/
final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
public function getInfoURI() {
return 'https://pypi.python.org/pypi/pyflakes';
}
public function getInfoName() {
return pht('PyFlakes');
}
public function getInfoDescription() {
return pht(
'PyFlakes is a simple program which checks Python source files for '.
'errors.');
}
public function getLinterName() {
return 'PYFLAKES';
}
public function getLinterConfigurationName() {
return 'pyflakes';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.pyflakes.prefix');
$bin = $this->getDeprecatedConfiguration('lint.pyflakes.bin', 'pyflakes');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install pyflakes with `pip install pyflakes`.');
}
public function shouldExpectCommandErrors() {
return true;
}
public function supportsReadDataFromStdin() {
return true;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match('/^(.*?):(\d+): (.*)$/', $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$severity = ArcanistLintSeverity::SEVERITY_WARNING;
$description = $matches[3];
$error_regexp = '/(^undefined|^duplicate|before assignment$)/';
if (preg_match($error_regexp, $description)) {
$severity = ArcanistLintSeverity::SEVERITY_ERROR;
}
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[2]);
$message->setCode($this->getLinterName());
$message->setDescription($description);
$message->setSeverity($severity);
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
}