Count all lines of an IT project
I needed to find a really fast way of evaluating LOC (Lines of Code) that my project has. For all files types, including .php, .js, .md, .html, .sql etc. etc.
Since I don’t know any web service that can do this and don’t have any designates special software for this, I used ol’ good Notepad++.
The method
I have used the Edit → Find in Files tool to replace all line-ending separator to the very same ones:
Why replaces? Because, I had a worse day! :) Seriously, you can use Find All as well.
Since we’re talking about an IT project, that is:
- which sources most likely comes from a GitHub
- where files are edited by people under all three systems: Windows, Linux and Mac
Then I had to repeat the above search three times (or actually four):
Each time changing replacement pattern:
\r\n
→\r\n
(Windows)\n
→\n
(Linux)\r
→\r
(Mac)\n\r
→\n\r
And sum the total count of replacement that Notepad++ has reported after each pass:
The fourth line-ending separator is no standard at all and isn’t officially used by any operating system known to me. But, to my extreme surprise it turned out that some 150 files had this separator as well.
The results
I was a little bit surprised to learn that a typical framework-based project in PHP has over two hundred thousand lines of code, counting only its own files. Because, if we would like to include all the Composer-extracted external libraries then the whole thing rises to even three million lines of code.
Each project is naturally different, so these numbers are very rough. But, still gives some estimate.