使用clonedigger来检查python中的重复代码

安装Clonedigger

$ sudo pip install clonedigger
$ clonedigger -help
Usage: To run Clone Digger type:
python clonedigger.py [OPTION]... [SOURCE FILE OR DIRECTORY]...

The typical usage is:
python clonedigger.py source_file_1 source_file_2 ...
  or
python clonedigger.py path_to_source_tree
Don't forget to remove automatically generated sources, tests and third party libraries from the source tree.

Notice:
The semantics of threshold options is discussed in the paper "Duplicate code detection using anti-unification", which can be downloaded from the site http://clonedigger.sourceforge.net . All arguments are optional. Supported options are:


Options:
  -h, --help            show this help message and exit
  -l LANGUAGE, --language=LANGUAGE
                        the programming language
  --no-recursion        do not traverse directions recursively
  -o OUTPUT, --output=OUTPUT
                        the name of the output file ("output.html" by default)
  --clustering-threshold=CLUSTERING_THRESHOLD
                        read the paper for semantics
  --distance-threshold=DISTANCE_THRESHOLD
                        the maximum amount of differences between pair of
                        sequences in clone pair (5 by default). Larger value
                        leads to larger amount of false positives
  --hashing-depth=HASHING_DEPTH
                        default value if 1, read the paper for semantics.
                        Computation can be speeded up by increasing this value
                        (but some clones can be missed)
  --size-threshold=SIZE_THRESHOLD
                        the minimum clone size. The clone size for its turn is
                        equal to the count of lines of code in its the largest
                        fragment
  --clusterize-using-dcup
                        mark each statement with its D-cup value instead of
                        the most similar pattern. This option together with
                        --hashing-depth=0 make it possible to catch all
                        considered clones (but it is slow and applicable only
                        to small programs)
  --dont-print-time     do not print time
  -f, --force
  --force-diff          force highlighting of differences based on the diff
                        algorithm
  --fast                find only clones, which differ in variable and
                        function names and constants
  --ignore-dir=IGNORE_DIRS
                        exclude directories from parsing
  --eclipse-output=ECLIPSE_OUTPUT
                        for internal usage only
  --cpd-output          output as PMDs CPDs XML format. If output file not
                        defined, output.xml is generated
  --report-unifiers
  --func-prefixes=F_PREFIXES
                        skip functions/methods with these prefixes (provide a
                        CSV string as argument)
  --file-list=FILE_LIST
                        a file that contains a list of file names that must be
                        processed by Clone Digger
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

使用Clonedigger

clonedigger -l python --ignore-dir=/path_to/exclude_file -o ./output.html -f --size-threshold=10 /path_to/src/
  • 1

集成到Jenkins,使用violations插件生成trend图

$ clonedigger  --cpd-output -o ./cpdout.xml  /path_to/src/
  • 1

这里写图片描述 
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值