Skip to content

[IMP] duplicate-code: Add feature to disable a duplicate-code from pylint: disable comment #891

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

Closed
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
12 changes: 11 additions & 1 deletion pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ def process_module(self, node):
stream,
node.file_encoding)

def _is_disabled_comment(self, lines):
for line in lines:
# TODO: Better way of get a disabled comment from a string
if ('R0801' in line or 'duplicate-code' in line) and ('pylint' in line and 'disable' in line):
return True
return False

def close(self):
"""compute and display similarities on closing (i.e. end of parsing)"""
total = sum(len(lineset) for lineset in self.linesets)
Expand All @@ -311,7 +318,10 @@ def close(self):
for num, couples in self._compute_sims():
msg = []
for lineset, idx in couples:
msg.append("==%s:%s" % (lineset.name, idx))
if not self._is_disabled_comment(lineset._real_lines):
msg.append("==%s:%s" % (lineset.name, idx))
if len(msg) < 2:
continue
msg.sort()
# pylint: disable=W0631
for line in lineset._real_lines[idx:idx+num]:
Expand Down