pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False negative ``duplicate-code`` when similarities are in the same file

Open onilton opened this issue 8 years ago • 9 comments

Steps to reproduce

  1. Create a file with repeated code: code.py
  2. pylint --disable=all --enable=similarities code.py

Current behavior

Do not show code repeated in the same file,

Expected behavior

Show code repeated in the same file.

pylint --version output

onilton avatar Apr 27 '17 21:04 onilton

I do not understand this issue.

I used similarities today for the first time, and it worked.

Could you please provide an example where pylint fails to find the duplicates?

guettli avatar Mar 05 '18 12:03 guettli

similarities compares code lines among multiple files. if you have one file with duplicated code it will not be found. Attached is a modification of pylint checkers similar.py to also compare a file with itself (if only one file is given to pylint) maybe this helps you to use that feature or to add it in the future, after making it to clean code again similar.zip

Amegon avatar Mar 13 '18 13:03 Amegon

this would be nice to have. I enabled similarities expecting checking in the same file was the actual behaviour. I was a bit surprised it only works on multiple files.

wdpypere avatar Oct 18 '18 09:10 wdpypere

Up!

iacopy avatar Mar 09 '20 11:03 iacopy

Maybe this could be also a command line flag --scan-self and yet provide a list of file names, meaning that similarity scanning will also occur within each provided file

https://github.com/PyCQA/pylint/issues/7439#issuecomment-1241510155 @dgutson

Pierre-Sassoulas avatar Sep 09 '22 07:09 Pierre-Sassoulas

CC @qequ

dgutson avatar Sep 09 '22 13:09 dgutson

@Pierre-Sassoulas is this about symilar? Does --enable=similarities end up calling symilar?

dgutson avatar Sep 09 '22 13:09 dgutson

Yes, symilar is embeded in pylint and raises duplicate-code messages.

Pierre-Sassoulas avatar Sep 09 '22 13:09 Pierre-Sassoulas