DEV Community


Posted on

Looking to remove duplicated code? Try codesim

Hi dev community.
I just released a new tool that can be helpful for you.
It's called "codesim" (on github:
It's a utility that can help you to find duplicated parts of code in your sources.

You can get it calling:

wget --no-cache -O /usr/local/bin/codesim ; chmod +x /usr/local/bin/codesim
Enter fullscreen mode Exit fullscreen mode

And use it with the following params:

usage: codesim [-h] [--exclude EXCLUDE] [--ratio RATIO]
               [--min-lines MIN_LINES]

positional arguments:
  dir                   Directory containing all the source files

optional arguments:
  -h, --help            show this help message and exit
  --exclude EXCLUDE     Exclude files matching the given pattern (ex:
  --ratio RATIO         Minimum percentage of common code (default: 0.9)
  --min-lines MIN_LINES
                        Minimum number of common lines (default: 10)
Enter fullscreen mode Exit fullscreen mode

It produces a table of all the duplicated parts of your code and can be really helpful, for instance, when doing web projects.

== Results ==

changes ratio   lines a lines b
6.00    0.92    37  37  ./projects/hook_logs/_index.html.haml -> ./admin/hook_logs/_index.html.haml
Enter fullscreen mode Exit fullscreen mode

If you like it, don't hesitate to leave me a star on Github :)


Top comments (0)