diff --git a/shopify_python/git_utils.py b/shopify_python/git_utils.py index ce4b122..39cea28 100644 --- a/shopify_python/git_utils.py +++ b/shopify_python/git_utils.py @@ -122,6 +122,11 @@ def handle_message(self, msg): def pylint_files(files, **kwargs): # type: (typing.List[str], **str) -> typing.Iterable[utils.Message] + # File paths must not be interpreted as Pylint options. + for path in files: + if path.startswith('-'): + raise ValueError("refusing to lint path that looks like a pylint option: {}".format(path)) + kwargs['reports'] = 'n' pylint_args = ["--{}={}".format(key, value) for key, value in kwargs.items()] diff --git a/tests/shopify_python/test_git_utils.py b/tests/shopify_python/test_git_utils.py index 3dab39f..dcd2f7d 100644 --- a/tests/shopify_python/test_git_utils.py +++ b/tests/shopify_python/test_git_utils.py @@ -1,4 +1,5 @@ import os +import mock import py # pylint: disable=unused-import import pytest import git # pylint: disable=unused-import @@ -327,3 +328,12 @@ def test_passing_linter(tmpdir): lint_results = [x for x in git_utils.pylint_files([str(tmpdir)], reports='n')] assert lint_results == [] + + +def test_linter_rejects_paths_that_look_like_options(): + # type: () -> None + with mock.patch.object(git_utils.lint, 'Run') as pylint_run: + with pytest.raises(ValueError): + list(git_utils.pylint_files(['--example.py'])) + + pylint_run.assert_not_called()