Skip to content

Commit

Permalink
Make min-similarity-lines == 0 stop similarity check (#4970)
Browse files Browse the repository at this point in the history
* Make ``min-similarity-lines == 0`` stop similarity check
This makes it so that setting ``min-similarity-lines`` to zero exit the
similarity code checker with a successful exit.
This closes #4901

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  • Loading branch information
DanielNoord and cdce8p committed Sep 7, 2021
1 parent fab2de2 commit cf33d82
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 @@ -65,6 +65,10 @@ Release date: TBA

* Extended ``consider-using-in`` check to work for attribute access.

* 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 @@ -71,3 +71,7 @@ Other Changes
Closes #4907

* Extended ``consider-using-in`` check to work for attribute access.

* 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 @@ -390,6 +390,8 @@ def append_stream(self, streamid: str, stream: TextIO, encoding=None) -> None:

def run(self) -> None:
"""start looking for similarities and display results on stdout"""
if self.min_lines == 0:
return
self._display_sims(self._compute_sims())

def _compute_sims(self) -> List[Tuple[int, Set[LinesChunkLimits_T]]]:
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 cf33d82

Please sign in to comment.