Giter Club home page Giter Club logo

aldanial / cloc Goto Github PK

View Code? Open in Web Editor NEW
18.5K 215.0 986.0 5.74 MB

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

License: GNU General Public License v2.0

Perl 86.95% Makefile 0.77% Assembly 0.58% C# 0.26% C++ 4.97% C 1.11% COBOL 0.08% ColdFusion 0.01% Fortran 0.17% Haskell 0.13% Java 0.43% MATLAB 0.63% Batchfile 0.01% Mathematica 0.18% Pascal 0.05% HTML 0.06% Tcl 0.01% TypeScript 1.07% XSLT 0.06% R 2.47%
cloc count-lines programming-language

cloc's People

Contributors

achary avatar aldanial avatar asadcr avatar asrmchq avatar breadcrumbistaken avatar cbek avatar cdahlheimer avatar darvil82 avatar dfm avatar drkameleon avatar dulrich avatar erkmos avatar feilongfl avatar gnustavo avatar hrbrmstr avatar jolkdarr avatar jwilk avatar larsbrinkhoff avatar ljdursi avatar logandark avatar luxaritas avatar michaeldimmitt avatar quidity avatar ryanmcc avatar strager avatar stsnel avatar szepeviktor avatar talyian avatar tgamblin avatar wonderbird avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloc's Issues

Bad detection of a Smarty file

I have a directory full of ".smarty" files and PHP files.
Calling cloc on this directory do not report smarty file, only php files. Only lines of code , comments ect of the PHP files are reported. Smarty files are ignored.

To reproduce :

  • create a .PHP file with only PHP marker inside
  • create a dummy SMARTY file containing somethig like :
{if $cta.style eq 'STYLE_DROPDOWNLIST'}
    <div class="list{if isset($cta.dimension)} grid-col span_{$cta.dimension}_of_12{/if}">
    </div>
{elseif $cta.style eq 'STYLE_SIMPLELINK'}
   <h1>HELLO WORLD</h1>
{else}
      <h1>HELLO WORLD 2</h1>
{/if}
  • start cloc
    It says
    2 text files.
    2 unique files.
    1 file ignored.
    And report only PHP stats.

Nemerle language support.

Nemerle language (http://nemerle.org/About) defines comment blocks like many languages already supported (C++, C# or Scala...). Therefore, that language may be supported easily by processing source files with .n extension.

Bundled Regexp::Common licensing issue

Hey! Thanks for cloc, it's awesome!

I maintain the cloc package in Fedora and just got notified that Cloc bundles a version of Regexp::Common that both Fedora and GNU consider non-free. Newer versions of Regexp::Common use other licenses in addition, which are considered free.

Would it be possible to either bump the bundled Regexp::Common to something with a free license or (perhaps preferably) stop bundling it and just depend on it and use its API? Would this break anything? (I'm not sure what the original reason for bundling was.)

Unknown option: by_percent

Maybe I am missing something, but I can't get the by-percent option to work at all, I just get the same message every time, "Unknown option: by_percent".

Use of implicit split to @_ is deprecated

Hi!
Downloaded and tested cloc-1.66 today and got this warning:
Use of implicit split to @_ is deprecated at ../scripts/cloc-1.66.pl line 3027.
It's easily fixed by chaning line 3027 to:
from:
my $n_cols = scalar(split(' ', $data_line));
to:
my @Items = split(' ', $data_line);
my $n_cols = @Items;

Update the homebrew recipe

The homebrew recipe still points to the sourceforge site. It probably also should refer to a more modern version instead of 1.64.

Mentioning the whole URL causes issues in small terminals

Although I suppose everyone has monitors for 200+ characters per line today, I am certain that I am not the only one using small windows for quick tasks. These windows usually have the very sensible width of 80 columns, as you seem to know very well by the code.

However, see

[mg@localhost cloc]$ ./cloc .
      14 text files.
       9 unique files.                              
      11 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=0.16 s (24.4 files/s, 124011.8 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code

I know you want credit, but do you need the whole URL? It will wrap very often.

I would change it to AlDanial/cloc (5 top results in google for this string is you anyway).

If you really need a URL, consider using a shortener.

Thanks, and note that I am just trying to improve everyone's experience when using your software.

Plugin for Grunt task runner

It would be nice if cloc could be automatically launched from Grunt with relevant options.

Note. if you think I'm using Grunt, you're right ;)
Grunt plugins are available for Sloc, Sloccount and file-sloc.

Diff error (quoted comments?)

Diff error (quoted comments?) happens when I execute cloc --diff for diff-fail.c below.

{/* begin */
{
     }
}/* end */
  perl modcloc-1.64.pl --v=1 --skip-uniqueness --diff diff-fail.c diff-fail.c >& diff-fail.log

where modcloc-1.64.pl is only for additional loggings:

diff cloc-1.64.pl modcloc-1.64.pl
8951a8952,8955
>
>       print "  ## $flag L=$n_L: [$line_L]\n";
>       print "  ## $flag R=$n_R: [$line_R]\n";
>
9033a9038
>                 die "diff failed !\n";

This error may happen when the source file has a "code" + "comment" line followed by a "code" line, where these two "code" parts are exactly same.

Wrong hypen-lines width with --sum-reports option

When creating summary report with --sum-reports option the hypens are to short:


-------------------------------------------------------------------------------------
File                                          files          blank        comment           code
-------------------------------------------------------------------------------------
directory/test1234                              696          13535          23433          86058
directory/test123                               458          11511          11403          66143
directory/test123456789                         343           4167           7979          37972

directory_1/test_123445678901234                 13             81            264            497
directory_1/test_12344567890123456                4             38            176            179
-------------------------------------------------------------------------------------
SUM:                                           2208          41016          61090         256197
-------------------------------------------------------------------------------------

Match path

Hi there,

I'm trying to --not-match-d a dir/subdir (which I do with --not-match-d="(dir\/subdir)" but it doesn't seem to work. Also there are cases where I'd like to match a directory and file name together like dir/file.* and for which I need to resort to --exclude-list-file.

I wonder whether you could implement a --match and --not-match which would match on the complete relative (or absolute) path (directory + basename)?

Thanks for the great tool!

Jun

Support for Elm

Hi, thanks for this wonderful tool.

It would be great to have support for Elm, the syntax of Elm is very heavily inspired by Haskell so hopefully we can reuse the Haskell code.
http://elm-lang.org/

Comments are exactly the same as they are in Haskell, here's the reference for comments in elm:
http://elm-lang.org/docs/syntax#comments

All Elm files end in '.elm'

Some sample code can be found here:
http://elm-lang.org/examples

for a non trivial sized sample see:
http://elm-lang.org/examples/pong

Please let me know anything else you might need, and anything I can do to help

Thanks for writing cloc

I just stop by to say thank you for this nice utility!
You can see my favorite use-case here: https://jorin.me/git-cloc/

Keep up the good work!

(Feel free to close the issue. Just couldn't see another way to contact you.)

Long paths under windows dont work

I am facing https://sourceforge.net/p/cloc/bugs/101/ under Windows 7 SP1, 64bit with the bundled EXE version 1.62 and also 1.66 on NTFS filesystem.

Windows has a limit on the length of filenames. Perls Find::Find inherently has to deal with the limitation and therefor also cloc.

I am running cloc on a huge codebase, unfortunately, i cant create a minimal example presenting the problem or disclose the project structure. Running cloc on just the directory structure which poses the problem works fine, so i assume it has something todo when recursing through lots of folders.

Cloc is invoked with

--by-file --ignored ignored.log --found found.log --xml --out src.xml <relative path>

The error i get is:
Can't cd to ../../../.. from <relative path with length of 222>: No such file or directory at C:/StrawberryPerl/perl/lib/File/Find.pm line 469.

Note, i am running the .pl against Strawberry Perl 5.22.1.2-32bit instead of the .exe for debugging reasons .

The relative path is prepended by a path of length 35, resulting in a total length of 256 for the directory. The error results in not output file, therefor missing results.

One temporary fix is to subst the first part of the path to a new drive letter and hence save 33 chars.

Mixed comments in single line badly processed

When block comments and line comment are used in a single line, clocgets confused and miscounts comments and LS for the processed file. Observed with C/C++ files.
Example:

/* data 1 */ // KO, processed as LS
int i;

/* data 2 */ /* OK, processed as comment */
int j;

Result:

Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                1              1              1              3

Expected:

C                                1              1              2              2

Support for Puppet's configuration language

Hi,

I'd like to add support for Puppet's configuration language. Currently, CLOC treats it as PASCAL, and the LOC is very incorrect (I tested using the sample code below which has 19 LOC).

cloc sample.pp
...
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Pascal                           1              3             15              6
-------------------------------------------------------------------------------

Could you point me how to write the plugin? Thanks!

1. File extensions associated with the language.
.pp

2. A description of how comments are defined
It supports two styles of comments:
https://docs.puppetlabs.com/puppet/latest/reference/lang_comments.html

(1) Shell-stype (begin with #)

# This is a comment

(2) C-style (delimited by slashes with inner asterisks.)

/*
  this is a comment
*/

3. Sample code

#sample.pp

case $operatingsystem {
  centos, redhat: { $service_name = 'ntpd' }
  debian, ubuntu: { $service_name = 'ntp' }
}

package { 'ntp':
  ensure => installed,
}

service { 'ntp':
  name      => $service_name,
  ensure    => running,
  enable    => true,
  subscribe => File['ntp.conf'],
}

file { 'ntp.conf':
  path    => '/etc/ntp.conf',
  ensure  => file,
  require => Package['ntp'],
  source  => "puppet:///modules/ntp/ntp.conf",
  # This source file would be located on the Puppet master at
  # /etc/puppetlabs/code/modules/ntp/files/ntp.conf
}

Here is a brief intro of the language:
https://docs.puppetlabs.com/puppet/4.2/reference/lang_summary.html

Missing perl module

I just wanted to test "CLOC" so I typed these two lines in bash, but it didn't work.

xapple@local ~ $ brew install cloc
==> Downloading https://homebrew.bintray.com/bottles/cloc-1.66.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cloc-1.66.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/cloc/1.66: 5 files, 526K
xapple@local ~ $
xapple@local ~ $
xapple@local ~ $ cloc /repos/cool_project/
Can't locate Algorithm/Diff.pm in @INC (@INC contains: /Users/xapple/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level /Users/xapple/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0 /Users/xapple/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level /Users/xapple/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0 .) at /usr/local/bin/cloc line 71.
BEGIN failed--compilation aborted at /usr/local/bin/cloc line 71.
xapple@local ~ $

Respect .gitignore

I'm not sure if this was ever filed, but it'd be nice to have .gitignore respected. is that possible?

read-lang-def is broken

--read-lang-def seems to be doing nothing
Happens under MacOSX both on brew-installed 1.64 and downloaded 1.66 release from this repo.

> cloc --write-lang-def=def.txt
> cloc --read-lang-def=def.txt

Usage: cloc [options] <file(s)/dir(s)> | <set 1> <set 2> | <report files>
[the rest of help here]

> echo $?
255

Support for Coq

Files for the Coq proof assistant are currently classified as Verilog as they both use a .v extension. Comments are all of the form (* foo bar *) , which is one way to distinguish the files from Verilog. Also the words "Inductive, Fixpoint, Definition, Theorem, Lemma, Proof, Qed, forall" appear with high frequency in Coq source and (I'm guessing) not so much in Verilog. Some sample code can be found here or here.
It would be awesome if you get the chance to add support, otherwise I might investigate doing so myself. Thanks.

support for tsx files

Hi,

I can't get a count of my tsx files (Typescript + JSX) with cloc.

Would it be possible to add this feature?

Incorrect handling of block-comment delimiter inside string

Hi! I've run into an issue where cloc is reporting incorrect lines counts in certain cases involving block comment delimiters inside a string in PHP code. I've attached a test script that demonstrates the issue. I have not yet tried it with any other languages.

The test file contains three functions. The first has a /* inside a string literal and the third has a block comment above it. (In this example, the block comment is a PHPDoc docblock, but the issue happens with a plain block comment too). The correct counts for this file are 4 comment lines and 16 code lines. However, the actual output from cloc is 11 comment and 9 code.

Base on my testing, it looks like cloc is incorrectly flagging the /* and */ as valid comment delimiters in the following cases:

  1. They occur inside a string literal in code.
  2. They occur inside a trailing line comment (# or // in PHP) on a line that starts with some code. Note that the delimiters are correctly ignored if they occur in a line comment that doesn't have any code before it, i.e. the line is just whitespace and comment.

Note that if no closing */ is found in a string literal, a real block comment, or a comment as described above, the initial /* is correctly ignored. (Actually, the only reason I even noticed this is because I ran cloc on a file that had a /* in a string literal at line 60 and didn't have a single */ until about 500 lines later.)

cloc-test.php.txt

XHTML files aren't all JavaServer Faces files

Many of us use XHTML outside of JavaServer faces ;-).

Right now, we're forced to use the additional flag:

--force-lang="HTML",xhtml

And then it counts them as "HTML" files, which isn't accurate.

Suggestion: gif file replacement

Many Unicode characters are arrows.
Maybe one of them could be used for the readme.md file allowing to get rid of the up.gif file.

For example, the following line:

# [Basic Use![^](up.gif)](#___top "click to go to top of document")

would be replaced with:

# [Basic Use &#9650;](#___top "click to go to top of document")

and rendered:

Basic Use ▲

Modern browsers handle Unicode charsets (UTF-8...) with no difficulty.
A nice table provides arrows available at http://unicode-table.com/en/sets/arrows-symbols/ .

assertion failed: open my_perl

I use this tool as part of my build process within a Jenkins server. I run 4 build variations every night when there are code changes.. Over the last 10 times the 4 variations have run, there have been 2 failures (out of 40 executions of cloc). On the most recent instance, the 1st of the 4 variations failed and the remaining 3 were successful.

EDIT: The "assertion failed" always happens on the Jenkins server but never happens when we run on the command line directly but does not cause the build to fail. Added additional line showing the Unknown exception that the build fails on. Don't know if the error is at the end of the first command line or the beginning of the second command line.

I get the following error message when this occurs.
23:51:26 assertion failed: open my_perl
23:51:26 assertion failed: MZ magic bytes
23:51:26 assertion failed: PE header
23:51:26 assertion failed: IMAGE_NT_OPTIONAL_HDR_MAGIC
23:51:26 amk E457: ["makefile" 158/0] uncaught 'Unknown' exception (ffffffff) while executing 'PR11940_GEN7_2_PostBuild'

We run the command twice to get both the detailed and summary data:
cloc-1.62 --by-file --progress-rate=0 --quiet --report-file=PR11940_cloc_report.xml --list-file=PR11940_cloc.txt
cloc-1.62 --progress-rate=0 --quiet --report-file=PR11940_GEN7_2_cloc_report.txt --list-file=PR11940_GEN7_2_cloc.txt

In the process of upgrading to v1.64 to see if problem repeats but also would like to be able to capture some additional debug information if that would be helpful to finding the root cause of the issue

cloc cannot read its own written language definition file

> ./cloc-1.64.exe --write-lang-def=my_cloc_language_definitions.txt
> ./cloc-1.64.exe --read-lang-def=my_cloc_language_definitions.txt .
Missing computer language name, line 1 of my_cloc_language_definitions.txt

Removing this first section in the file helps:

(unknown)
    3rd_gen_scale 0.00

Appear to be getting invalid counts for .htm file

I'm evaluating this for use in our CI Build/Metrics workflow. I ran it against a .Net Solution that has one .htm file (attached). CLOC returned:
files language blank comment code
1 HTML 4 0 57

The file is mostly JavaScript and mostly commented out. It appears to be counting the commented Javascript as code.
10-5-2015 12-28-10 pm

inefficient,--diff,cloc just uses one cpu core to run

system envirenment:LINUX
CLOC version:1.56
CPU core: 8

QUESTION:
when i use the cloc.pl tool to get difference between tows source codes,
cloc tool just use one cpu core to run .
As follows:
1ff57782-91e5-4144-b81a-78a00010876e

since inefficiency of using one cpu core,cloc tool takes me too much time to wait the result.

what should i do to increase the efficiency of cloc tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.