DEV Community

aclarembeau
aclarembeau

Posted on

2 2

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: https://github.com/aclarembeau/codesim).
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 https://raw.githubusercontent.com/aclarembeau/codesim/master/main.py -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]
               dir


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:
                        node_modules)
  --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 :)

Best,

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay