CLOC忽略/排除列表文件(.clocignore)

 xuyang200788 发布于 2022-12-18 17:59

(编辑:请参阅底部的正确用法部分.)

主要问题

你如何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.

1 个回答
  • 我发现最好的解决方法是.clocignore直接提供内容--exclude-dir.例如,如果您正在使用bash并且tr可用:

    cloc --exclude-dir=$(tr '\n' ',' < .clocignore) .
    

    2022-12-18 18:01 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有