Skip to content

Commit

Permalink
Make min-similarity-lines == 0 stop similarity check
Browse files Browse the repository at this point in the history
This makes it so that setting ``min-similarity-lines`` to zero exit the
similarity code checker with a successful exit.
This closes pylint-dev#4901
  • Loading branch information
DanielNoord committed Sep 5, 2021
1 parent 005b7d2 commit c81eecf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -63,6 +63,10 @@ Release date: TBA

Closes #4907

* Setting ``min-similarity-lines`` to 0 now makes the similarty checker stop checking for duplicate code

Closes #4901


What's New in Pylint 2.10.3?
============================
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.11.rst
Expand Up @@ -69,3 +69,7 @@ Other Changes
* Fix false positive ``superfluous-parens`` for tuples created with inner tuples

Closes #4907

* Setting ``min-similarity-lines`` to 0 now makes the similarty checker stop checking for duplicate code

Closes #4901
2 changes: 2 additions & 0 deletions pylint/checkers/similar.py
Expand Up @@ -919,6 +919,8 @@ def Run(argv=None):
ignore_signatures = True
if not args:
usage(1)
if min_lines == 0:
sys.exit(0)
sim = Similar(
min_lines, ignore_comments, ignore_docstrings, ignore_imports, ignore_signatures
)
Expand Down
8 changes: 8 additions & 0 deletions tests/checkers/unittest_similar.py
Expand Up @@ -502,3 +502,11 @@ def test_get_map_data() -> None:
# There doesn't seem to be a faster way of doing this, yet.
lines = (linespec.text for linespec in lineset_obj.stripped_lines)
assert tuple(expected_lines) == tuple(lines)


def test_set_duplicate_lines_to_zero() -> None:
output = StringIO()
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
similar.Run(["--duplicates=0", SIMILAR1, SIMILAR2])
assert ex.value.code == 0
assert output.getvalue() == ""

0 comments on commit c81eecf

Please sign in to comment.