(编辑:请参阅底部的正确用法部分.)
主要问题
你如何cloc使用它的--exclude-list-file=<file>选择?基本上,我正在尝试将其提供给.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.
Run Code Online (Sandbox Code Playgroud)
尝试
以下命令按预期工作:
cloc --exclude-dir=node_modules .
Run Code Online (Sandbox Code Playgroud)
但是这个命令不排除任何东西:
cloc --exclude-list-file=myignorefile .
Run Code Online (Sandbox Code Playgroud)
这是以下内容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/**
Run Code Online (Sandbox Code Playgroud)
cloc如果不存在则不会出错myignorefile,所以我对它正在做的事情没有任何反馈. …
cloc 使每个类型的每种语言(空白,注释或代码)能够计算存储在目录中的代码行数.
git blame 使人能够看到文件的哪个部分属于谁.
我正在寻找一种结合两者的方法,以便获得一个(三维)矩阵,列出每个用户每种语言的每种类型的代码行.
是否有优雅内置的方式来做到这一点还是应该一个"报废"的"怪"的部分(运行grep后git blame)每个用户的,并运行cloc它们来计算表中的每个用户?
编辑:
天真的方法(基于@Jubobs的评论):
grep "^[^(]*([^)]*)"捕捉到所有用户的列表,并与检索唯一身份sort和uniq.grep "^[^(]*($user)"使得仅保留该用户的行.这或多或少是如何生成所需的输出.但是正如人们所看到的,这种方法进行了大量的复制(或至少存储在内存中),并且实际上可以通过在文件上运行一次而不是多次来计算每个用户的行数.
期望的输出:
就像是:
+--------+--------------------------------+--------------------------------+
|User | C# | XML |
+--------+-------+-------+---------+------+-------+-------+---------+------+
| | files | blank | comment | code | files | blank | comment | code |
+--------+-------+-------+---------+------+-------+-------+---------+------+
| Foo | 12 | 75 | 148 | 2711 | 2 | 42 | 0 | …Run Code Online (Sandbox Code Playgroud) 这应该是一项微不足道的任务,但既没有阅读文档和手册页也没有谷歌搜索提出了我想要实现的目标的解决方案:
cloc 正在扫描我们的源代码树,我们希望它忽略所有*.html和*.css文件.
有没有办法给出cloc一个文件扩展名列表来忽略..?
我正在开发一个工具来分析并提供有关其他人的源代码的一些统计信息,该工具将能够识别代码中的许多内容!现在我被困在计算代码的评论数量,我目前的代码是:
public static void main(String[] args) {
String line = "";
int count = 0;
try {
BufferedReader br = new BufferedReader(new FileReader("comments.txt"));
while ((line = br.readLine()) != null) {
if (line.startsWith("//")) {
count++;
} else if (line.startsWith("/*")) {
count++;
while (!(line = br.readLine()).endsWith("'*\'")) {
count++;
break;
}
}
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("count=" + count);
}
Run Code Online (Sandbox Code Playgroud)
要检查代码,我使用的是测试文件.但是代码在两个文件中都给出了错误的结果,例如; 我在以下文件中得到三个
Yes
//comment
yes
yes
/*
if
random
test
test
*/ …Run Code Online (Sandbox Code Playgroud) 我已使用 --exclude-lang = "xml" 和 --exclude-lang = "designer.cs" 从两个不同文件夹中的行数更改中排除设计器和 xml 文件,但它不起作用。
我尝试使用 git 存储库中的 diff 以及上次提交和 HEAD 检查代码行,但出现错误,
$ cloc -- diff 182712379cae1b953c5976854e735134530e8241 头
错误:
0 个文本文件。
0 个文本文件。
0 个文件被忽略。
2个错误:无法读取:182712379cae1b953c5976854e735134530e8241
无法读取:HEAD
没什么可算的。