关于后端:golang轻量级的代码复制粘贴检查器-cpd

2次阅读

共计 831 个字符,预计需要花费 3 分钟才能阅读完成。

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

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

疾速开始

clone

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

配置文件 vim cpd.toml

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

编译

go build copy-paste-detector .

可选: 指定配置文件

$ ./copy-paste-detector -h
Usage 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 |
+------+------+--------------+
b
c
d
3

实现思路

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

优化思路

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

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

本文由 mdnice 多平台公布

正文完
 0