Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By file linting for more details ... #19

Merged
merged 3 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions autohooks/plugins/pylint/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,12 +27,12 @@

def check_pylint_installed():
try:
import pylint # pylint: disable=import-outside-toplevel
except ImportError:
import pylint # pylint: disable=import-outside-toplevel, disable=unused-import
except ImportError as e:
raise Exception(
'Could not find pylint. Please add pylint to your python '
'environment'
)
) from e


def get_pylint_config(config):
Expand Down Expand Up @@ -83,16 +83,14 @@ 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)
if status:
error('Linting error(s) found in {}.'.format(str(f.path)))
else:
ok('Linting {} was successful.'.format(str(f.path)))

return status