Skip to content

Commit b2b0571

Browse files
Make 'pylint' equivalent to 'pylint .'
Closes #5701
1 parent 07b01dd commit b2b0571

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Diff for: doc/whatsnew/fragments/5701.breaking

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``pylint`` is now equivalent to ``pylint .`` and won't show the help by default anymore.
2+
The help is still available with ``pylint --help`` or ``pylint --long-help``.
3+
4+
Closes #5701

Diff for: pylint/lint/pylinter.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,14 @@ def check(self, files_or_modules: Sequence[str]) -> None:
658658
files_or_modules is either a string or list of strings presenting modules to check.
659659
"""
660660
self.initialize()
661+
if not files_or_modules and not self.config.from_stdin:
662+
files_or_modules = (str(Path(".").resolve()),)
661663
if self.config.recursive:
662664
files_or_modules = tuple(self._discover_files(files_or_modules))
663665
if self.config.from_stdin:
664666
if len(files_or_modules) != 1:
665-
raise exceptions.InvalidArgsError(
666-
"Missing filename required for --from-stdin"
667-
)
667+
print("Missing filename required for --from-stdin")
668+
sys.exit(32)
668669

669670
extra_packages_paths = list(
670671
{
@@ -989,7 +990,14 @@ def get_ast(
989990
confidence=HIGH,
990991
)
991992
except astroid.AstroidBuildingError as ex:
992-
self.add_message("parse-error", args=ex)
993+
msg = str(ex)
994+
if "Unable to load file" in msg and "__init__.py" in msg:
995+
msg = (
996+
"No '__init__.py' in the given directory, give a python module, "
997+
"or use '--recursive=y' with the proper ignore option (in order"
998+
" to not lint your virtualenv)"
999+
)
1000+
self.add_message("parse-error", args=msg)
9931001
except Exception as ex:
9941002
traceback.print_exc()
9951003
# We raise BuildingError here as this is essentially an astroid issue

Diff for: pylint/lint/run.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ def __init__(
176176
return
177177

178178
# Display help if there are no files to lint or no checks enabled
179-
if not args or len(linter.config.disable) == len(
180-
linter.msgs_store._messages_definitions
181-
):
182-
print("No files to lint: exiting.")
179+
if len(linter.config.disable) == len(linter.msgs_store._messages_definitions):
180+
print("No messages to check: exiting.")
183181
sys.exit(32)
184182

185183
if linter.config.jobs < 0:

Diff for: tests/test_self.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ def test_nonexistent_config_file(self) -> None:
211211
self._runtest(["--rcfile=/tmp/this_file_does_not_exist"], code=32)
212212

213213
def test_error_missing_arguments(self) -> None:
214-
self._runtest([], code=32)
214+
self._runtest([], code=1)
215215

216216
def test_disable_all(self) -> None:
217217
out = StringIO()
218218
self._runtest([UNNECESSARY_LAMBDA, "--disable=all"], out=out, code=32)
219-
assert "No files to lint: exiting." in out.getvalue().strip()
219+
assert "No messages to check: exiting." in out.getvalue().strip()
220220

221221
def test_no_out_encoding(self) -> None:
222222
"""Test redirection of stdout with non ascii characters."""
@@ -491,8 +491,9 @@ def test_pylintrc_comments_in_values(self) -> None:
491491
)
492492

493493
def test_no_crash_with_formatting_regex_defaults(self) -> None:
494+
path = join(HERE, "regrtest_data", "empty.py")
494495
self._runtest(
495-
["--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=32
496+
[path, "--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=0
496497
)
497498

498499
def test_getdefaultencoding_crashes_with_lc_ctype_utf8(self) -> None:

0 commit comments

Comments
 (0)