Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make min-similarity-lines == 0 stop similarity check #4970

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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() == ""