1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-18 09:48:38 +01:00

fix bugs and documentation for ArcanistPyLintLinter

Summary:
- The top documentation is more readable, and the details about the severity
mapping regexps is moved to the top from inline -- they're important.
- array_merge() is used when appending command line args from
##lint.pylint.options## instead of '+'. The latter merges by key instead of
appending the two lists as intended.
- rely on the exit code instead of magic text that may or may not be there
depending on how ##pylint## is invoked.

These bugs were introduced in d762311a9d.

Test Plan: ##arc lint --trace##'d a bunch of Python source files in a project,
with and without PyLint messages. Added some ##lint.pylint.options## to see
proper appending behavior.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley, cpiro

Differential Revision: 1045
This commit is contained in:
Chris Piro 2011-10-25 13:46:13 -07:00 committed by epriestley
parent a85e344425
commit 00e5ba7ddc

View file

@ -23,34 +23,41 @@
* *
* You should be able to install pylint with ##sudo easy_install pylint##. If * You should be able to install pylint with ##sudo easy_install pylint##. If
* your system is unusual, you can manually specify the location of pylint and * your system is unusual, you can manually specify the location of pylint and
* its dependencies by configuring these keys in your .arcrc: * its dependencies by configuring these keys in your .arcconfig:
* *
* lint.pylint.prefix * lint.pylint.prefix
* lint.pylint.logilab_astng.prefix * lint.pylint.logilab_astng.prefix
* lint.pylint.logilab_common.prefix * lint.pylint.logilab_common.prefix
* *
* You can specify additional command-line options to pass to PyLint by setting * You can specify additional command-line options to pass to PyLint by
* this key: * setting ##lint.pylint.options##.
* *
* lint.pylint.options * Specify which PyLint messages map to which Arcanist messages by defining
* * the following regular expressions:
* Now, configure which warnings and errors you want PyLint to raise by setting
* these keys:
* *
* lint.pylint.codes.error * lint.pylint.codes.error
* lint.pylint.codes.warning * lint.pylint.codes.warning
* lint.pylint.codes.advice * lint.pylint.codes.advice
* *
* Set these to regular expressions -- for instance, if you want to raise all * The regexps are run in that order; the first to match determines which
* PyLint errors as Arcanist errors, set this for ##lint.pylint.codes.error##: * Arcanist severity applies, if any. For example, to capture all PyLint
* "E...." errors as Arcanist errors, set ##lint.pylint.codes.error## to:
* *
* ^E.* * ^E.*
* *
* You can also match more granular errors: * You can also match more granularly:
* *
* ^E(0001|0002)$ * ^E(0001|0002)$
* *
* You can also provide a list of regular expressions. * According to ##man pylint##, there are 5 kind of messages:
*
* (C) convention, for programming standard violation
* (R) refactor, for bad code smell
* (W) warning, for python specific problems
* (E) error, for probable bugs in the code
* (F) fatal, if an error occurred which prevented pylint from
* doing further processing.
* *
* @group linter * @group linter
*/ */
@ -60,11 +67,6 @@ class ArcanistPyLintLinter extends ArcanistLinter {
$working_copy = $this->getEngine()->getWorkingCopy(); $working_copy = $this->getEngine()->getWorkingCopy();
// The config file defines how PyLint message codes translate to
// arcanist severities. The config options provide regex's to
// match against the message codes generated by PyLint. Severity's
// are matched in the order of errors, warnings, then advice.
// The first severity that matches, in that order, is returned.
$error_regexp = $working_copy->getConfig('lint.pylint.codes.error'); $error_regexp = $working_copy->getConfig('lint.pylint.codes.error');
$warning_regexp = $working_copy->getConfig('lint.pylint.codes.warning'); $warning_regexp = $working_copy->getConfig('lint.pylint.codes.warning');
$advice_regexp = $working_copy->getConfig('lint.pylint.codes.advice'); $advice_regexp = $working_copy->getConfig('lint.pylint.codes.advice');
@ -150,16 +152,15 @@ class ArcanistPyLintLinter extends ArcanistLinter {
} }
private function getPyLintOptions() { private function getPyLintOptions() {
// Options to pass the PyLint // '-rn': don't print lint report/summary at end
// - '-rn': don't print lint report/summary at end // '-iy': show message codes for lint warnings/errors
// - '-iy': show message codes for lint warnings/errors
$options = array('-rn', '-iy'); $options = array('-rn', '-iy');
// Add any options defined in the config file for PyLint // Add any options defined in the config file for PyLint
$working_copy = $this->getEngine()->getWorkingCopy(); $working_copy = $this->getEngine()->getWorkingCopy();
$config_options = $working_copy->getConfig('lint.pylint.options'); $config_options = $working_copy->getConfig('lint.pylint.options');
if ($config_options !== null) { if ($config_options !== null) {
$options += $config_options; $options = array_merge($options, $config_options);
} }
return implode(" ", $options); return implode(" ", $options);
@ -193,16 +194,16 @@ class ArcanistPyLintLinter extends ArcanistLinter {
"{$pylint_bin} {$options} {$path_on_disk}", "{$pylint_bin} {$options} {$path_on_disk}",
$python_path); $python_path);
} catch (CommandException $e) { } catch (CommandException $e) {
// PyLint will return a non-zero exit code if warnings/errors are found. if ($e->getError() == 32) {
// Therefore we detect command failure by checking that the stderr is // According to ##man pylint## the exit status of 32 means there was a
// some non-expected value. // usage error. That's bad, so actually exit abnormally.
if ($e->getStderr() !== "No config file found, ".
"using default configuration\n") {
throw $e; throw $e;
} } else {
// The other non-zero exit codes mean there were messages issued,
// which is expected, so don't exit.
$stdout = $e->getStdout(); $stdout = $e->getStdout();
} }
}
$lines = explode("\n", $stdout); $lines = explode("\n", $stdout);
$messages = array(); $messages = array();