mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 10:12:41 +01:00
Convert more linters to modern formats with .arclint
support
Summary: Ref T3186. Ref T2039. - Convert JSHint to modern format; improve granularity of errors. - Convert PyFlakes to modern format; - Remove ApacheLicenseLinter and LicenseLinter (these have been deprecated for a very long time). This is somewhat disruptive and will break some users by no longer respecting various path/config options. I'll sequence documentation and deprecation warnings in front of these. Test Plan: Ran unit tests. Reviewers: btrahan, #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin, joshuaspence, aran Maniphest Tasks: T3186, T2039 Differential Revision: https://secure.phabricator.com/D6810
This commit is contained in:
parent
f2b341ae03
commit
c013124690
5 changed files with 76 additions and 52 deletions
|
@ -124,6 +124,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPhutilXHPASTLinter' => 'lint/linter/ArcanistPhutilXHPASTLinter.php',
|
'ArcanistPhutilXHPASTLinter' => 'lint/linter/ArcanistPhutilXHPASTLinter.php',
|
||||||
'ArcanistPhutilXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php',
|
'ArcanistPhutilXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php',
|
||||||
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
|
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
|
||||||
|
'ArcanistPyFlakesLinterTestCase' => 'lint/linter/__tests__/ArcanistPyFlakesLinterTestCase.php',
|
||||||
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
|
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
|
||||||
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
|
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
|
||||||
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
|
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
|
||||||
|
@ -274,7 +275,8 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPhutilTestTerminatedException' => 'Exception',
|
'ArcanistPhutilTestTerminatedException' => 'Exception',
|
||||||
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
|
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
|
||||||
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
|
'ArcanistPyFlakesLinter' => 'ArcanistExternalLinter',
|
||||||
|
'ArcanistPyFlakesLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistPyLintLinter' => 'ArcanistLinter',
|
'ArcanistPyLintLinter' => 'ArcanistLinter',
|
||||||
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
|
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
|
||||||
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
|
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
|
||||||
|
|
|
@ -5,69 +5,54 @@
|
||||||
*
|
*
|
||||||
* @group linter
|
* @group linter
|
||||||
*/
|
*/
|
||||||
final class ArcanistPyFlakesLinter extends ArcanistLinter {
|
final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
|
||||||
|
|
||||||
public function getLinterName() {
|
public function getLinterName() {
|
||||||
return 'PyFlakes';
|
return 'PYFLAKES';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPyFlakesOptions() {
|
public function getLinterConfigurationName() {
|
||||||
return null;
|
return 'pyflakes';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lintPath($path) {
|
public function getDefaultBinary() {
|
||||||
$config = $this->getEngine()->getConfigurationManager();
|
$config = $this->getEngine()->getConfigurationManager();
|
||||||
$pyflakes_path = $config->getConfigFromAnySource('lint.pyflakes.path');
|
$prefix = $config->getConfigFromAnySource('lint.pyflakes.prefix');
|
||||||
$pyflakes_prefix = $config->getConfigFromAnySource('lint.pyflakes.prefix');
|
$bin = $config->getConfigFromAnySource('lint.pyflakes.bin', 'pyflakes');
|
||||||
|
|
||||||
// Default to just finding pyflakes in the users path
|
if ($prefix) {
|
||||||
$pyflakes_bin = 'pyflakes';
|
return $prefix.'/'.$bin;
|
||||||
$python_path = array();
|
} else {
|
||||||
|
return $bin;
|
||||||
// If a pyflakes path was specified, then just use that as the
|
|
||||||
// pyflakes binary and assume that the libraries will be imported
|
|
||||||
// correctly.
|
|
||||||
//
|
|
||||||
// If no pyflakes path was specified and a pyflakes prefix was
|
|
||||||
// specified, then use the binary from this prefix and add it to
|
|
||||||
// the PYTHONPATH environment variable so that the libs are imported
|
|
||||||
// correctly. This is useful when pyflakes is installed into a
|
|
||||||
// non-default location.
|
|
||||||
if ($pyflakes_path !== null) {
|
|
||||||
$pyflakes_bin = $pyflakes_path;
|
|
||||||
} else if ($pyflakes_prefix !== null) {
|
|
||||||
$pyflakes_bin = $pyflakes_prefix.'/bin/pyflakes';
|
|
||||||
$python_path[] = $pyflakes_prefix.'/lib/python2.7/site-packages';
|
|
||||||
$python_path[] = $pyflakes_prefix.'/lib/python2.7/dist-packages';
|
|
||||||
$python_path[] = $pyflakes_prefix.'/lib/python2.6/site-packages';
|
|
||||||
$python_path[] = $pyflakes_prefix.'/lib/python2.6/dist-packages';
|
|
||||||
}
|
}
|
||||||
$python_path[] = '';
|
}
|
||||||
$python_path = implode(':', $python_path);
|
|
||||||
$options = $this->getPyFlakesOptions();
|
|
||||||
|
|
||||||
$f = new ExecFuture(
|
public function getVersion() {
|
||||||
'/usr/bin/env PYTHONPATH=%s$PYTHONPATH %s %C',
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
$python_path,
|
|
||||||
$pyflakes_bin,
|
|
||||||
$options);
|
|
||||||
$f->write($this->getData($path));
|
|
||||||
|
|
||||||
try {
|
$matches = array();
|
||||||
list($stdout, $_) = $f->resolvex();
|
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
|
||||||
} catch (CommandException $e) {
|
return $matches['version'];
|
||||||
// PyFlakes will return an exit code of 1 if warnings/errors
|
} else {
|
||||||
// are found but print nothing to stderr in this case. Therefore,
|
return false;
|
||||||
// if we see any output on stderr or a return code other than 1 or 0,
|
|
||||||
// pyflakes failed.
|
|
||||||
if ($e->getError() !== 1 || $e->getStderr() !== '') {
|
|
||||||
throw $e;
|
|
||||||
} else {
|
|
||||||
$stdout = $e->getStdout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
$lines = explode("\n", $stdout);
|
|
||||||
$messages = array();
|
$messages = array();
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$matches = null;
|
$matches = null;
|
||||||
|
@ -92,8 +77,15 @@ final class ArcanistPyFlakesLinter extends ArcanistLinter {
|
||||||
$message->setCode($this->getLinterName());
|
$message->setCode($this->getLinterName());
|
||||||
$message->setDescription($description);
|
$message->setDescription($description);
|
||||||
$message->setSeverity($severity);
|
$message->setSeverity($severity);
|
||||||
$this->addLintMessage($message);
|
|
||||||
|
$messages[] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($err && !$messages) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
12
src/lint/linter/__tests__/ArcanistPyFlakesLinterTestCase.php
Normal file
12
src/lint/linter/__tests__/ArcanistPyFlakesLinterTestCase.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistPyFlakesLinterTestCase
|
||||||
|
extends ArcanistArcanistLinterTestCase {
|
||||||
|
|
||||||
|
public function testPyflakesLinter() {
|
||||||
|
return $this->executeTestsInDirectory(
|
||||||
|
dirname(__FILE__).'/pyflakes/',
|
||||||
|
new ArcanistPyFlakesLinter());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
src/lint/linter/__tests__/jshint/jshint.lint-test
Normal file
11
src/lint/linter/__tests__/jshint/jshint.lint-test
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
function f() {
|
||||||
|
for (ii = 0; ii < 3; ii++) {
|
||||||
|
g()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
~~~~~~~~~~
|
||||||
|
warning:3:8
|
||||||
|
error:7:1
|
7
src/lint/linter/__tests__/pyflakes/pyflakes.lint-test
Normal file
7
src/lint/linter/__tests__/pyflakes/pyflakes.lint-test
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import sys, os
|
||||||
|
|
||||||
|
x += 1
|
||||||
|
~~~~~~~~~~
|
||||||
|
warning:1:
|
||||||
|
warning:1:
|
||||||
|
error:3:
|
Loading…
Reference in a new issue