jscpd
jscpd 查重时能够跳过标记为忽略的块和新行以及空符号和注释(不支持尖括号注释<!-- --!>
),重复率判定依据为一定长度标识符的MD5值是否相同。
- 安装
npm install -g jscpd
- 配置参数(查看更多)
Option | Type | Default | Description |
---|---|---|---|
-l, –min-lines | [NUMBER] | 5 | min size of duplication in code lines |
-t, –min-tokens | [NUMBER] | 70 | min size of duplication in code tokens |
-f, –files | [STRING] | * | glob pattern for find code |
-r, –reporter | [STRING] | xml | reporter name or path |
-x, –xsl-href | [STRING] | - | path to xsl file for include to xml report |
-e, –exclude | [STRING] | - | directory to ignore |
–languages-exts | [STRING] | - | list of languages with file extensions (e.g. language:ext1,ext2;language:ext3) |
-g, –languages | [STRING] | All supported | list of languages which scan for duplicates, separated with coma |
-o, –output | [PATH] | - | path to report file |
-c, –config | [PATH] | - | path to config yml file (e.g. .cpd.yml) |
–verbose | - | show full info about copies | |
–skip-comments | false | - | skip comments in code when |
-b, –blame | false | - | blame authors of duplications (get information about authors from git) |
-p, –path | [PATH] | Current dir | path to code |
–limit | [NUMBER] | 50 | limit of allowed duplications, if real duplications percent more then limit jscpd exit with error |
-d, –debug | - | show debug information (options list and selected files) | |
-v, –version | - | Display the current version | |
-h, –help | - | Display help and usage details |
- 配置文件
配置文件以.json结尾,在项目根目录新建一个.jscpd.json文件
{
minLines: 10000,
minTokens: 10000,
"maxTokens": 10000000,
"maxSize": 10000000,
ignoreCase: true,
silent: true,
threshold: 10,
"formatsExts": "markup:vue",
reporters: [
"console",
"json",
"html",
],
languages: [
"js",
"html",
"css",
"markup",
"scss"
],
mode: "strict",
blame: true,
absolute: true,
gitignore: true,
failOnError: true,
output: "./report",
verbose: true,
}
- 执行检测
jscpd ./ -f "javascript,css,vue,markup" -t 5 -r "console,html" -i"node_modules" -m weak -l 5 -o "./report"