diff options
author | Jason Owen <jason.a.owen@gmail.com> | 2018-05-17 12:58:01 -0400 |
---|---|---|
committer | Ashley Whetter <asw@dneg.com> | 2018-07-23 11:35:50 -0700 |
commit | 32fd3b9fb937141f38370fdb5160eb1ce27da135 (patch) | |
tree | 72c939621feeb74af41a755689b3ad2b15b701d1 | |
parent | 0d913675ec682401b2814bb2a8ae06a66f22ebbd (diff) | |
download | pylint-git-32fd3b9fb937141f38370fdb5160eb1ce27da135.tar.gz |
Add `--exit-zero` option (#2099)
Add a new command-line option for the use of continuous integration
scripts which abort if a command returns a non-zero status code. If the
option is specified, and Pylint runs successfully, it will exit with 0
regardless of the number of lint issues detected.
Configuration errors, parse errors, and calling Pylint with invalid
command-line options all still return a non-zero error code, even if
`--exit-zero` is specified.
Thanks for hosting a sprint at PyCon 2018!
Close #2042
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | pylint/lint.py | 11 | ||||
-rw-r--r-- | pylint/test/test_self.py | 6 |
4 files changed, 23 insertions, 1 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a720347ea..40f0deb42 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -161,3 +161,4 @@ Order doesn't matter (not that much, at least ;) * Tobias Hernstig: contributor +* Jason Owen: contributor @@ -17,6 +17,12 @@ Release date: |TBA| Close #2186 + * Add `--exit-zero` option for continuous integration scripts to more + easily call Pylint in environments that abort when a program returns a + non-zero (error) status code. + + Close #2042 + What's New in Pylint 1.9.2? =========================== diff --git a/pylint/lint.py b/pylint/lint.py index be7fdaa97..1c424ea1b 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -417,6 +417,12 @@ class PyLinter(config.OptionsManagerMixIn, 'help': ('When enabled, pylint would attempt to guess common ' 'misconfiguration and emit user-friendly hints instead ' 'of false-positive error messages')}), + + ('exit-zero', + {'action': 'store_true', + 'help': ('Always return a 0 (non-error) status code, even if ' + 'lint errors are found. This is primarily useful in ' + 'continuous integration scripts.')}), ) option_groups = ( @@ -1347,7 +1353,10 @@ group are mutually exclusive.'), linter.check(args) linter.generate_reports() if exit: - sys.exit(self.linter.msg_status) + if linter.config.exit_zero: + sys.exit(0) + else: + sys.exit(self.linter.msg_status) def cb_set_rcfile(self, name, value): """callback for option preprocessing (i.e. before option parsing)""" diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py index b77988105..481d76108 100644 --- a/pylint/test/test_self.py +++ b/pylint/test/test_self.py @@ -145,6 +145,12 @@ class TestRunTC(object): def test_w0704_ignored(self): self._runtest([join(HERE, 'input', 'ignore_except_pass_by_default.py')], code=0) + def test_exit_zero(self): + self._runtest([ + '--exit-zero', + join(HERE, 'regrtest_data', 'syntax_error.py') + ], code=0) + def test_generate_config_option(self): self._runtest(['--generate-rcfile'], code=0) |