最近公司在做双软认证,需要提供一下源码的行数,网上找了一番,发现一个非常不错的小工具,故分享下。
简介
cloc,即 Count Lines of Code 的缩写,支持统计众多编程语言源码的空行数、注释行数、物理行数。
安装非常简单。直接 npm install -g cloc 即可。其他安装方法见 Install via package manager。
用法:
统计单个文件的行数
sample.js
1 2 3 4 5 6 7 8 9 10
   | function hello() {        console.log('hello world')             }
  hello()
  | 
1 2 3 4 5 6 7 8 9 10 11 12 13 14
   |  cloc sample.js
 
         1 text file.        1 unique file.                                      0 files ignored.
  github.com/AlDanial/cloc v 1.78  T=0.01 s (76.2 files/s, 762.0 lines/s) ------------------------------------------------------------------------------- Language                     files          blank        comment           code ------------------------------------------------------------------------------- JavaScript                       1              5              1              4 -------------------------------------------------------------------------------
 
  | 
| 字段 | 含义 | 
|---|
| files | 文件数 | 
| blank | 空行数 | 
| comment | 注释行数 | 
| code | 代码行数 | 
统计目录下的源码行数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
   |  clol .
 
     17754 text files.    12969 unique files.                                           Complex regular subexpression recursion limit (32766) exceeded at /Users/user/.nvm/versions/node/v8.12.0/bin/cloc line 10685. Complex regular subexpression recursion limit (32766) exceeded at /Users/user/.nvm/versions/node/v8.12.0/bin/cloc line 10685.     5797 files ignored.
  github.com/AlDanial/cloc v 1.78  T=35.80 s (335.9 files/s, 77895.9 lines/s) --------------------------------------------------------------------------------------- Language                             files          blank        comment           code --------------------------------------------------------------------------------------- JavaScript                            8763         192138         281252        1465456 JSON                                  1403            756              0         327584 Markdown                              1093          52708              4         134228 TypeScript                              85          14720          34711         115732 HTML                                   231          47061            580          51339 CSS                                     90           3165           1207          26616 XML                                     56           3246           1300          13713 C/C++ Header                            21           1147            341           5913 YAML                                   120            105            128           2711 SQL                                     30            411            374           2249 CoffeeScript                            17            198            112           1111 Protocol Buffers                        51            245            739            719 make                                    23            213            188            676 DTD                                      1            179            177            514 Windows Module Definition                5             88              0            437 Python                                   1             81            175            355 C++                                      7             70             36            317 JSP                                      3             27             44            273 ActionScript                             1             38            102            132 JSON5                                    2              0              0            123 D                                        5              0              0             71 Bourne Shell                             5             25              7             53 Handlebars                               2             10              0             46 EJS                                      3              6              0             27 Vuejs Component                          4              0              4             21 Bourne Again Shell                       1              2              1             20 Lisp                                     1              0              0              6 DOS Batch                                1              0              0              2 --------------------------------------------------------------------------------------- SUM:                                 12025         316639         321482        2150444 ---------------------------------------------------------------------------------------
 
  |