Привет DEV сообщество. Я только что выпустил новый инструмент, который может быть полезен для вас. Это называется «Codesim» (на Github: https://github.com/aclarembeau/codesim ). Это утилита, которая может помочь вам найти дублированные части кода в ваших источниках.
Вы можете получить это звонить:
wget --no-cache https://raw.githubusercontent.com/aclarembeau/codesim/master/main.py -O /usr/local/bin/codesim ; chmod +x /usr/local/bin/codesim
И используйте его со следующими словами:
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)
Это производит таблицу всех дублированных частей вашего кода и может быть действительно полезным, например, при выполнении веб-проектов.
== 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
Если вам это нравится, не стесняйтесь оставлять мне звезду на Github:)
Лучший,
Оригинал: “https://dev.to/aclarembeau/looking-to-remove-duplicated-code-try-codesim-44ib”