(编辑:请参阅底部的正确用法部分.)
主要问题
你如何cloc
使用它的--exclude-list-file=
选择?基本上,我正在尝试将其提供给.clocignore
文件.
预期的行为
cloc
文档说明如下:
--exclude-list-file=Ignore files and/or directories whose names appear in . should have one entry per line. Relative path names will be resolved starting from the directory where cloc is invoked. See also --list-file.
尝试
以下命令按预期工作:
cloc --exclude-dir=node_modules .
但是这个命令不排除任何东西:
cloc --exclude-list-file=myignorefile .
这是以下内容myignorefile
:
node_modules node_modules/ node_modules/* node_modules/** ./node_modules ./node_modules/ ./node_modules/* ./node_modules/** /full/path/to/current/directory/node_modules /full/path/to/current/directory/node_modules/ /full/path/to/current/directory/node_modules/* /full/path/to/current/directory/node_modules/**
cloc
如果不存在则不会出错myignorefile
,所以我对它正在做的事情没有任何反馈.
(我正在运行OS X并cloc
通过Homebrew 安装了v1.60.)
tl; dr - @ Raman的答案中指定的方法都需要较少的指定.clocignore
并且运行速度要快得多.
通过@拉曼的回答带动下,我调查的源代码:cloc
确实事实上方面--exclude-list-file
,但不是过程不同的看法--exclude-dir
在两个重要方面.
首先,while --exclude-dir
将忽略其路径包含指定字符串的任何文件,但--exclude-list-file
只会排除指定的确切文件或目录.clocignore
.
如果您有这样的目录结构:
.clocignore node_modules/foo/first.js app/node_modules/bar/second.js
而内容.clocignore
就是
node_modules
然后cloc --exclude-list-file=.clocignore .
将成功忽略first.js
但计数second.js
.而cloc --exclude-dir=node_modules .
将忽略两者.
要解决这个问题,.clocignore
需要包含这个:
node_modules app/node_modules
其次,源代码cloc
似乎将指定的目录添加--exlude-dir
到列表中,该列表在计算文件之前会被查阅.而在计算文件后--exclude-list-file
查阅发现的目录列表.
意思--exclude-list-file
是,在忽略最终报告中的结果之前,仍会处理文件,这些文件可能很慢.这是通过实验证实了:在一个示例中的代码库,它采取半秒钟运行cloc
与--exclude-dir
,11秒到具有等效运行--exclude-list-file
.
我发现最好的解决方法是.clocignore
直接提供内容--exclude-dir
.例如,如果您正在使用bash
并且tr
可用:
cloc --exclude-dir=$(tr '\n' ',' < .clocignore) .