Search code examples
pythoncode-analysisstatic-analysispylintcode-duplication

How to detect code duplication among multiple python source files?


I have placed all python project sources in a single folder. Running the following pylint only seems to be looking and analyzing for duplicates within each source file and not across all which is what I intended:

pylint --disable=all --enable=duplicate-code /some/source/folder/

Is there a way to find code duplicates across many source files?


Solution

    • On Unix-based systems, collect and pass all .py files to Pylint. This approach should work with all Pylint versions

      pylint --disable=all --enable=duplicate-code $(find . -name "*.py")
      
    • If you are using version 2.13 and above, you can use --recursive=y

      pylint --disable=all --enable=duplicate-code --recursive=y ./