Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to count source lines of code (SLOC) in a CoffeeScript project? [closed]

Tags:

coffeescript

Is there a common way of counting source lines of code (SLOC) in a CoffeeScript project?

I'm hoping for something that will traverse all of the directories in my project during the count. I found a few projects online but they seemed kind of overkill for the task. I would love a simple utility or even just some command-line-fu.

like image 453
Mitch Avatar asked Apr 02 '12 01:04

Mitch


2 Answers

If you're on UNIX, I would go with the wc tool. I usually use wc -l *.coffee */*.coffee etc. because it is easy to remember. However, a recursive version would be

wc -l `find <proj-dir> -type f | grep \.coffee$`

which runs the find command, which recursively lists files of type f, or normal files, fed into the grep, which filters down to just Coffeescript files, and the output of that is used as the command line arguments to wc (-l signals a line count).

Edit: Now we don't want to count blank or comment lines (we're only catching single-line comments here). We lose the per-file counts, but here goes:

cat `find <proj-dir> -type f | grep \.coffee$` | sed '/^\s*#/d;/^\s*$/d' | wc -l

We find the Coffeescript files, and then cat them. Then, sed strips out lines that consist of only whitespace or have whitespace followed by a #. Finally, our friend wc counts the remaining lines.

like image 180
Aaron Dufour Avatar answered Sep 19 '22 15:09

Aaron Dufour


This will do what you want: https://github.com/blackducksw/ohcount

It correctly excludes comments and blank lines and also supports many other languages.

like image 30
Craig Barnes Avatar answered Sep 19 '22 15:09

Craig Barnes