From b2b0571492b105c1572c759880522cfd36f1b192 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 25 Sep 2023 22:49:42 +0200 Subject: [PATCH] Make 'pylint' equivalent to 'pylint .' Closes #5701 --- doc/whatsnew/fragments/5701.breaking | 4 ++++ pylint/lint/pylinter.py | 16 ++++++++++++---- pylint/lint/run.py | 6 ++---- tests/test_self.py | 7 ++++--- 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 doc/whatsnew/fragments/5701.breaking diff --git a/doc/whatsnew/fragments/5701.breaking b/doc/whatsnew/fragments/5701.breaking new file mode 100644 index 0000000000..bac7145976 --- /dev/null +++ b/doc/whatsnew/fragments/5701.breaking @@ -0,0 +1,4 @@ +``pylint`` is now equivalent to ``pylint .`` and won't show the help by default anymore. +The help is still available with ``pylint --help`` or ``pylint --long-help``. + +Closes #5701 diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index cecf4f195c..8d506a915b 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -658,13 +658,14 @@ def check(self, files_or_modules: Sequence[str]) -> None: files_or_modules is either a string or list of strings presenting modules to check. """ self.initialize() + if not files_or_modules and not self.config.from_stdin: + files_or_modules = (str(Path(".").resolve()),) if self.config.recursive: files_or_modules = tuple(self._discover_files(files_or_modules)) if self.config.from_stdin: if len(files_or_modules) != 1: - raise exceptions.InvalidArgsError( - "Missing filename required for --from-stdin" - ) + print("Missing filename required for --from-stdin") + sys.exit(32) extra_packages_paths = list( { @@ -989,7 +990,14 @@ def get_ast( confidence=HIGH, ) except astroid.AstroidBuildingError as ex: - self.add_message("parse-error", args=ex) + msg = str(ex) + if "Unable to load file" in msg and "__init__.py" in msg: + msg = ( + "No '__init__.py' in the given directory, give a python module, " + "or use '--recursive=y' with the proper ignore option (in order" + " to not lint your virtualenv)" + ) + self.add_message("parse-error", args=msg) except Exception as ex: traceback.print_exc() # We raise BuildingError here as this is essentially an astroid issue diff --git a/pylint/lint/run.py b/pylint/lint/run.py index e7a0fde8e6..7f1b66e783 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -176,10 +176,8 @@ def __init__( return # Display help if there are no files to lint or no checks enabled - if not args or len(linter.config.disable) == len( - linter.msgs_store._messages_definitions - ): - print("No files to lint: exiting.") + if len(linter.config.disable) == len(linter.msgs_store._messages_definitions): + print("No messages to check: exiting.") sys.exit(32) if linter.config.jobs < 0: diff --git a/tests/test_self.py b/tests/test_self.py index 09a1ccfc3e..42558a8412 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -211,12 +211,12 @@ def test_nonexistent_config_file(self) -> None: self._runtest(["--rcfile=/tmp/this_file_does_not_exist"], code=32) def test_error_missing_arguments(self) -> None: - self._runtest([], code=32) + self._runtest([], code=1) def test_disable_all(self) -> None: out = StringIO() self._runtest([UNNECESSARY_LAMBDA, "--disable=all"], out=out, code=32) - assert "No files to lint: exiting." in out.getvalue().strip() + assert "No messages to check: exiting." in out.getvalue().strip() def test_no_out_encoding(self) -> None: """Test redirection of stdout with non ascii characters.""" @@ -491,8 +491,9 @@ def test_pylintrc_comments_in_values(self) -> None: ) def test_no_crash_with_formatting_regex_defaults(self) -> None: + path = join(HERE, "regrtest_data", "empty.py") self._runtest( - ["--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=32 + [path, "--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=0 ) def test_getdefaultencoding_crashes_with_lc_ctype_utf8(self) -> None: