Skip to content

Commit

Permalink
Make 'pylint' equivalent to 'pylint .'
Browse files Browse the repository at this point in the history
Closes #5701
  • Loading branch information
Pierre-Sassoulas committed Sep 30, 2023
1 parent 07b01dd commit b2b0571
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions 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
16 changes: 12 additions & 4 deletions pylint/lint/pylinter.py
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions pylint/lint/run.py
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_self.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b2b0571

Please sign in to comment.