Count source lines by
- source lines
- comment lines
- multiline comment lines
- single comment lines
- empty lines
- physical lines
- CoffeeScript
- C / C++
- JavaScript
- Python
- Java
- PHP
sudo npm install -g sloc
sloc [option] <file>|<directory>
Options:
-h, --help output usage information
-V, --version output the version number
-j, --json return JSON object
-s, --sloc print only number of source lines
-v, --verbose print or add analzed files
-e, --exclude <regex> regular expression to exclude files and folders
e.g.:
$ sloc src/
---------- result ------------
physical lines : 301
lines of source code : 236
total comment : 17
singleline : 9
multiline : 8
empty : 48
number of files read : 2
------------------------------
Or use it in your own node module
var fs = require('fs');
var sloc = require('sloc');
fs.readFile("mySourceFile.coffee", "utf8", function(err, code){
if(err){ console.error(err); }
else{
stats = sloc(code,"coffeescript");
console.log("total lines: " + stats.loc);
console.log("source lines: " + stats.sloc);
console.log("comment lines: " + stats.cloc);
}
});
npm test
sloc is licensed under the GPLv3 licence