【问题标题】:Get lines of code in src folder skipping comments and empty lines获取 src 文件夹中跳过注释和空行的代码行
【发布时间】:2018-11-16 13:32:01
【问题描述】:

嗨,我已经有一些东西可以获取代码行,但它仍然输出了空行和 cmets 计数。

git ls-files | grep "\.java$" | xargs wc -l

你能修改这个以跳过 cmets 和空行吗?

提前致谢

【问题讨论】:

  • 这是干什么用的?计算代码行数不仅仅是忽略 cmets。根据样式,同一语句可以分成多个文本行

标签: java git lines-of-code


【解决方案1】:

试试CLOC,它可以很详细地列出数字。 您需要先使用语法brew install cloc安装CLOC

cloc $(git ls-files)

示例输出供参考:

20 text files.
      20 unique files.                              
       6 files ignored.

    http://cloc.sourceforge.net v 1.62  T=0.22 s (62.5 files/s, 2771.2 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    Javascript                       2             13            111            309
    JSON                             3              0              0             58
    HTML                             2              7             12             50
    Handlebars                       2              0              0             37
    CoffeeScript                     4              1              4             12
    SASS                             1              1              1              5
    -------------------------------------------------------------------------------
    SUM:                            14             22            128            471
    -------------------------------------------------------------------------------

【讨论】:

    【解决方案2】:

    大多数测试覆盖率工具也会计算 LOC。例如,Jacoco 把这个吐给 Jenkins。

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2012-06-01
      • 2015-03-07
      相关资源
      最近更新 更多