代码重复率检查工具jsinspect

检查重复代码,去掉冗余代码。

安装:

npm install -g jsinspect

用法:jsinspect [options] <paths ...>

检测复制粘贴和结构类似的JavaScript代码

示例:jsinspect -I -L -t 20 --ignore "test" ./path/to/src 

意思是检查 ./path/to/src 路径下文件 -I不匹配标识符 -L不匹配文字 -t 20匹配大于20个字节的代码 忽略test文件

Options:

  -h, --help                         output usage information 输出使用信息
  -V, --version                      output the version number 输出版本号
  -t, --threshold <number>           number of nodes (default: 30) 检查字节阀值(默认是30个字节)
  -m, --min-instances <number>       min instances for a match (default: 2) 匹配的最小实例(默认2个字节)
  -c, --config [config]              path to config file (default: .jsinspectrc) 配置文件路径
  -r, --reporter [default|json|pmd]  specify the reporter to use 指定类型使用
  -I, --no-identifiers               do not match identifiers 不匹配标识符
  -L, --no-literals                  do not match literals 不匹配文字
  -C, --no-color                     disable colors 禁用颜色
  --ignore <pattern>                 ignore paths matching a regex 忽略与正则表达式匹配的路径
  --truncate <number>                length to truncate lines (default: 100, off: 0) 截线长度
  --debug                            print debug information 打印调试信息

如果.jsinspectrc文件位于项目目录中,则将使用其值代替上面列出的默认值。例如:

{
  "threshold":     30,
  "identifiers":   true,
  "literals":      true,
  "color":         true,
  "minInstances":  2,
  "ignore":        "test|spec|mock",
  "reporter":      "json",
  "truncate":      100,
}

首次使用项目时,您可能希望使用以下选项运行该工具,同时在lib/src目录上显式运行,而不是test/spec目录。

jsinspect -t 50 --ignore "test" ./path/to/src

 

posted @ 2018-07-26 18:10  觉信  阅读(6291)  评论(0编辑  收藏  举报