golang轻量级的代码复制粘贴查看器 cpd

我的项目地址: https://github.com/dengjiawen...

疾速开始

clone

git clone https://github.com/dengjiawen8955/copy-paste-detector.gitcd copy-paste-detector

配置文件 vim cpd.toml

minRepeatLine = 4  # 最小反复行parseFolder   = "out"   # 解析的文件夹门路Ignore        = [] # 过滤的正则表达式Contain       = [] # 匹配的正则表达式文件, 优先级高于 Ignore

编译

go build copy-paste-detector .

可选: 指定配置文件

$ ./copy-paste-detector -hUsage of ./copy-paste-detector:      --config string   config file (default "cpd.toml")pflag: help requested

run

$ ./copy-paste-detector +------+------+--------------+| 片段 | 序号 | 文件名:行数  |+------+------+--------------+|    1 |    1 | out1.txt:2-5 ||    1 |    2 | out2.txt:6-9 |+------+------+--------------+bcd3

实现思路

  • Parser 次要返回 map[string][]IDLine 反复的 IDLine 能够通过 IDLine 查问到确定的文件和确定的行
  • Detector 次要返回 BlockMatrix [][]*Block{Start, End} 反复代码块, 遍历链表, 通过反复 map 的 IDLine 获取反复代码块

优化思路

反复代码检测专利: https://patents.google.com/pa...

参考 jscpd: https://github.com/kucherenko...

本文由mdnice多平台公布