diff --git a/doc/whatsnew/fragments/8715.performance b/doc/whatsnew/fragments/8715.performance new file mode 100644 index 0000000000..319af164d7 --- /dev/null +++ b/doc/whatsnew/fragments/8715.performance @@ -0,0 +1,3 @@ +Exit immediately if all messages are disabled. + +Closes #8715 diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 776803f2e4..e7a0fde8e6 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -175,9 +175,11 @@ def __init__( sys.exit(code) return - # Display help messages if there are no files to lint - if not args: - print(linter.help()) + # 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.") sys.exit(32) if linter.config.jobs < 0: diff --git a/tests/test_self.py b/tests/test_self.py index fd3bb5ff02..3970f22641 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -212,6 +212,11 @@ def test_nonexistent_config_file(self) -> None: def test_error_missing_arguments(self) -> None: self._runtest([], code=32) + 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() + def test_no_out_encoding(self) -> None: """Test redirection of stdout with non ascii characters.""" # This test reproduces bug #48066 ; it happens when stdout is redirected