shell – CLOC ignore / exlude列表文件(.clocignore)
(编辑:请参阅底部正确使用部分.)
主要问题 如何使 预期行为 cloc文件说如下: --exclude-list-file=<file> Ignore files and/or directories whose names appear in <file>. <file> 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/** 如果myignorefile不存在,cloc不会出错,所以我没有反馈它在做什么. (我正在运行OS X并通过Homebrew安装cloc v1.60.) 正确使用 tl; dr – 在@ Raman的答案中指定的方法要求在.clocignore中指定的更少,运行速度更快. 在@ Raman的答案的推动下,我调查了源代码:cloc实际上是尊重–exclude-list-file,但是以两种重要的方式处理它们不同于-exclude-dir. 精确的文件名与“路径的一部分” 首先,-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仍然处理文件,这可能很慢,之后忽略最终报告中的结果.这是通过实验证实的:在一个示例代码库中,使用–exclude-dir运行cloc需要半秒钟,使用等效的–exclude-list-file运行11秒.
我找到的最好的解决方法是将.clocignore的内容直接提供给–exclude-dir.例如,如果您正在使用bash并具有tr可用性:
cloc --exclude-dir=$(tr 'n' ',' < .clocignore) . (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |