summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-09-07 14:17:11 +0200
committerGitHub <noreply@github.com>2021-09-07 14:17:11 +0200
commitcf33d82635569da924d82538f806a5242481f06f (patch)
tree57f826acdeab8b975bee0cf03c59a84255e05d7f
parentfab2de272b3fc36dc4480d89840b8bfe0fbfbd0c (diff)
downloadpylint-git-cf33d82635569da924d82538f806a5242481f06f.tar.gz
Make ``min-similarity-lines == 0`` stop similarity check (#4970)
* 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>
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.11.rst4
-rw-r--r--pylint/checkers/similar.py2
-rw-r--r--tests/checkers/unittest_similar.py8
4 files changed, 18 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 97af302af..224728f39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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?
============================
diff --git a/doc/whatsnew/2.11.rst b/doc/whatsnew/2.11.rst
index 72dc75e71..6a9ed6686 100644
--- a/doc/whatsnew/2.11.rst
+++ b/doc/whatsnew/2.11.rst
@@ -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
diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py
index c65b1c893..88d7eac52 100644
--- a/pylint/checkers/similar.py
+++ b/pylint/checkers/similar.py
@@ -390,6 +390,8 @@ class Similar:
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]]]:
diff --git a/tests/checkers/unittest_similar.py b/tests/checkers/unittest_similar.py
index 4ddf2029a..c98ea15df 100644
--- a/tests/checkers/unittest_similar.py
+++ b/tests/checkers/unittest_similar.py
@@ -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() == ""