How to count the total number of line of code for JS, CSS, LESS, HTML files in a project?

19,599

Solution 1

Perhaps you are using source control? In case that source control is Git, you can count the amount of code in the repo like this – no extra tools required.

For a more detailed breakdown, cloc may be helpful – have a look at this answer then. cloc doesn't depend on Git, or any other type of source control.

Solution 2

In windows OS there is also a gui tool http://www.locmetrics.com/ which you can use to count lines of code (LOC), blank lines of code (BLOC), comment lines of code (CLOC).

Share:
19,599
GibboK
Author by

GibboK

A professional and enthusiastic Senior Front End Developer. Listed as top 2 users by reputation in Czech Republic on Stack Overflow. Latest open source projects Animatelo - Porting to JavaScript Web Animations API of Animate.css (430+ stars on GitHub) Industrial UI - Simple, modular UI Components for Shop Floor Applications Frontend Boilerplate - An opinionated boilerplate which helps you build fast, robust, and adaptable single-page application in React Keyframes Tool - Command line tool which convert CSS Animations to JavaScript objects gibbok.coding📧gmail.com

Updated on July 16, 2022

Comments

  • GibboK
    GibboK almost 2 years

    I am looking for a way to count the total number of line of code for my front-end project.

    At the moment I am using the gulp-sloc

    gulp.task('sloc', function () {
        gulp.src(folders)
          .pipe(sloc());
    });
    

    But the CSS code is not included in the count.

    • Do I miss some special configuration?
    • Do you know any other similar plugin?
  • GibboK
    GibboK over 8 years
    I am using SVN, do you know if there is any similar command on SVN?
  • hashchange
    hashchange over 8 years
    I don't, unfortunately. But cloc doesn't depend on Git, so that might work for you (didn't make that clear enough in my answer, I have edited it now).
  • GibboK
    GibboK over 8 years
    Thanks for your answer, but rather prefer a solution based on gulp
  • GibboK
    GibboK over 8 years
    Also looking at locmetrics's site, I cannot see reference to JS and CSS, I see mainly support for C#, C++, Java, and SQL
  • hashchange
    hashchange over 8 years
    @GibboK I think your last comment was meant for the other answer ;) cloc does support CSS and JS: github.com/AlDanial/cloc#Languages
  • learner
    learner over 5 years
    This tool can only be used for Programming languages like, C#, C++, Java, and SQL.