简单的源代码统计工具:sloc

jopen 9年前

它可以实现以几种类型的源代码统计:

  • 源代码行数
  • 有注释的行数
  • 有注释块的行数
  • 单行注释的行数
  • 混合源码和注释的行数
  • 空行数
  • 物理行数

sloc能够输出以下格式:

  • CSV
  • JSON
  • Commandline table
示例:
$ sloc src/    ---------- Result ------------                Physical :  1202                Source :  751               Comment :  322   Single-line comment :  299         Block comment :  23                 Mixed :  116                 Empty :  245    Number of files read :  10

或者:
$ sloc --details \         --format cli-table \         --keys total,source,comment \         --exclude i18n*.\.coffee \         --format-option no-head src/    ┌─────────────────────────────────┬──────────┬────────┬─────────┐  │ src/cli.coffee                  │ 98       │ 74     │ 7       │  ├─────────────────────────────────┼──────────┼────────┼─────────┤  │ src/helpers.coffee              │ 26       │ 20     │ 0       │  ├─────────────────────────────────┼──────────┼────────┼─────────┤  │ src/sloc.coffee                 │ 196      │ 142    │ 20      │  ├─────────────────────────────────┼──────────┼────────┼─────────┤  │ src/formatters/simple.coffee    │ 44       │ 28     │ 7       │  ├─────────────────────────────────┼──────────┼────────┼─────────┤  │ src/formatters/csv.coffee       │ 25       │ 14     │ 5       │  ├─────────────────────────────────┼──────────┼────────┼─────────┤  │ src/formatters/cli-table.coffee │ 22       │ 13     │ 0       │  └─────────────────────────────────┴──────────┴────────┴─────────┘

支持的语言:
  • CoffeeScript
  • C / C++
  • C#
  • Clojure / ClojureScript
  • CSS / SCSS / LESS / Stylus
  • Erlang
  • Go
  • Groovy
  • HTML
  • Handlebars
  • Haskell
  • Haxe
  • Hilbert
  • hy
  • Java
  • JavaScript
  • Julia
  • Lua
  • LiveScript
  • Nix
  • Mochi
  • Monkey
  • Mustache
  • Perl 5
  • Python
  • PHP
  • R
  • Racket
  • Ruby
  • Rust
  • Scala
  • SVG
  • Swift
  • Typescript
  • Visual Basic
  • Yaml
  • XML

项目主页:http://www.open-open.com/lib/view/home/1420786737812