From b015e17560bc33310554af6631c3a875ed0a9da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Mon, 24 Aug 2020 16:47:08 +0200 Subject: [PATCH 1/3] By file linting for more details ... --- autohooks/plugins/pylint/pylint.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/autohooks/plugins/pylint/pylint.py b/autohooks/plugins/pylint/pylint.py index b79942d..56fa29b 100644 --- a/autohooks/plugins/pylint/pylint.py +++ b/autohooks/plugins/pylint/pylint.py @@ -27,9 +27,9 @@ def check_pylint_installed(): try: - import pylint # pylint: disable=import-outside-toplevel + import pylint # pylint: disable=import-outside-toplevel, disable=unused-import except ImportError: - raise Exception( + raise Exception from ImportError( 'Could not find pylint. Please add pylint to your python ' 'environment' ) @@ -83,16 +83,15 @@ def precommit(config=None, **kwargs): # pylint: disable=unused-argument arguments = get_pylint_arguments(config) with stash_unstaged_changes(files): - args = ['pylint'] - args.extend(arguments) - args.extend([str(f.absolute_path()) for f in files]) - - status = subprocess.call(args) - str_files = ', '.join([str(f.path) for f in files]) - - if status: - fail('Linting error(s) found in {}.'.format(str_files)) - else: - ok('Linting {} was successful.'.format(str_files)) + for f in files: + args = ['pylint'] + args.extend(arguments) + args.append(str(f.absolute_path())) + status = subprocess.call(args) + # str_files = ', '.join([str(f.path) for f in files]) + if status: + fail('Linting error(s) found in {}.'.format(str(f.path))) + else: + ok('Linting {} was successful.'.format(str(f.path))) return status From 1c2c550bb0bb0aa750dbaa053e03b16a5c66e5fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Mon, 24 Aug 2020 16:52:50 +0200 Subject: [PATCH 2/3] changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada1fdf..a6f9a0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed -Replaced pipenv with poetry for dependency management. poetry install works a bit different than pipenv install. It installs dev packages. [#16](https://github.com/greenbone/autohooks-plugin-pylint/pull/16) +* Replaced pipenv with poetry for dependency management. poetry install works a bit different than pipenv install. It installs dev packages. [#16](https://github.com/greenbone/autohooks-plugin-pylint/pull/16) +* Linting file by file [#19](https://github.com/greenbone/autohooks-plugin-pylint/pull/19) ### Fixed ### Removed From cfe935731205636029b9cd2deb494095b57f199c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Tue, 25 Aug 2020 12:43:53 +0200 Subject: [PATCH 3/3] Added suggested changes, also made an error out of fail ... --- autohooks/plugins/pylint/pylint.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/autohooks/plugins/pylint/pylint.py b/autohooks/plugins/pylint/pylint.py index 56fa29b..62bc09b 100644 --- a/autohooks/plugins/pylint/pylint.py +++ b/autohooks/plugins/pylint/pylint.py @@ -17,7 +17,7 @@ import subprocess -from autohooks.api import ok, fail +from autohooks.api import ok, error from autohooks.api.path import match from autohooks.api.git import get_staged_status, stash_unstaged_changes @@ -28,11 +28,11 @@ def check_pylint_installed(): try: import pylint # pylint: disable=import-outside-toplevel, disable=unused-import - except ImportError: - raise Exception from ImportError( + except ImportError as e: + raise Exception( 'Could not find pylint. Please add pylint to your python ' 'environment' - ) + ) from e def get_pylint_config(config): @@ -88,9 +88,8 @@ def precommit(config=None, **kwargs): # pylint: disable=unused-argument args.extend(arguments) args.append(str(f.absolute_path())) status = subprocess.call(args) - # str_files = ', '.join([str(f.path) for f in files]) if status: - fail('Linting error(s) found in {}.'.format(str(f.path))) + error('Linting error(s) found in {}.'.format(str(f.path))) else: ok('Linting {} was successful.'.format(str(f.path)))