精华内容
下载资源
问答
  • CLOC
    2021-12-09 15:48:03

    ubuntu下使用cloc统计代码行数很好用。记录两个实际用到的扩展选项

    1. 排除项目路径下某些目录,比如python的虚拟环境或者node包:
    cloc . --exclude-dir=./venv,./webapp/node_models,./webapp/www,./webapp/src.assets
    

    2.有些语言或扩展名的文件cloc默认不统计,比如typeScript,需要手动指定以某种语言的统计方式统计某种扩展名的文件:

    --force-lang="JSP",ts
    

    注意,这样统计之后表格中的JSP统计结果中会包含.ts扩展名文件中的代码行数。

    最后贴一下备份自己统计代码行数的烂代码:

    import os
    
    cube_files = ['cubenet','cubenet_uaa','cubenet_gateway','cubenet_portal','cubenet_uapp1','cubenet_uapp2','cubenet_papp1','cubenet_serviceboot','cubenet_iboot',
        'cubeai','cubeai_umm','cubeai_pmodelhub','cubeai_umu','cubeai_umd','cubeai_popen','cubeai_ability','cubeai_ppersonal',
        'examples/cubeai_examples','examples/cubeai_examples_2','examples/cubeai_examples_3', 'cubeai_examples_3']
    
    print(len(cube_files))
    
    path = '/home/xu/cubeai_openi/'
    exclude = '--exclude-dir=./webapp/src/assets,./venv,./webapp/www,./webapp/node_models --force-lang="JSP",ts'
    
    
    fcount = open('fcount.txt', 'w+')
    
    count_py = 0
    count_ts = 0
    count_html = 0
    for folder in cube_files:
        print(folder)
        current_path = path + folder
        os.chdir(current_path)
        command = 'cloc ./ ' + exclude 
        redata = os.popen(command).read()
        fcount.write('#' + folder + '\n\n' + redata + '\n\n')
        for line in redata.split('\n'):
            if 'Python' in line:
                nums = line.split(' ')
                count_py = count_py + int(nums[-1])
            elif 'HTML' in line:
                nums = line.split(' ')
                count_html = count_html + int(nums[-1])
            elif ('Javascript' in line) or ('JSP' in line):
                nums = line.split(' ')
                count_ts = count_ts + int(nums[-1])
    
    print( count_py, count_ts, count_html )
    fcount.close()
    
    更多相关内容
  • Sloc Cloc和代码(scc) 与cloc,sloccount和tokei类似的工具。 用于计算许多编程语言中的物理代码行,空行,注释行和源代码的物理行。 目标是成为最快的代码计数器,但也要像位置计数一样执行COCOMO计算,并类似...
  • 可执行文件名称会有所不同,具体取决于您使用的是开发源版本( cloc ),发行版本的源( cloc-1.90.pl )还是Windows可执行文件( cloc-1.90.exe )。 在此页面上, cloc是用于指代其中任何一个的通用术语。 一份...
  • 可执行文件名称会有所不同,具体取决于您使用的是开发源版本( cloc ),发行版本的源( cloc-1.88.pl )还是Windows可执行文件( cloc-1.88.exe )。 在此页面上, cloc是用于指代其中任何一个的通用术语。 一份...
  • cloc2sloc 将cloc.xml文件转换为sloc文件。入门使用以下命令安装模块: npm install [-g] cloc2sloc 。 如下运行该工具: cloc --xml --by-line --report-file=cloc.xml /path/to/foldercloc2sloc --input=cloc.xml ...
  • CLOC代码工具工具(安装包+教程),CLOC代码工具工具(安装包+教程),良心出品,亲测可用!
  • cloc代码统计工具

    2020-12-05 19:02:39
    cloc代码统计工具,代码统计不犯愁,windos版本,包含使用教程,doc命令直接查 cloc代码统计工具,代码统计不犯愁,windos版本,包含使用教程,doc命令直接查
  • cloc - 编统计代码的行数。能够统计空行、注释行、多种编程语言源代码的物理行。
  • 代码统计行数工具cloc

    2017-07-20 17:08:30
    代码统计行数工具cloc, 里面有windows和linux版本的
  • cloc对代码行进行计数cloc对许多编程语言中源代码的空行,注释行和物理行进行计数。 最新版本:v1.84(2019年9月22日)在bein cloc计数行代码cloc对许多编程语言中的源代码的空行,注释行和物理行进行计数之后,cloc...
  • gocloc一个快速的cloc(计算行数),用Go编写。 受到tokei的启发。 安装$ go get -u github.com/hhatto/gocloc/cmd/gocloc用法基本用法$ gocloc。 $ gocloc。 ---- gocloc一个快速的cloc(计数行数),用Go编写。 受...
  • python库。 资源全名:cloc-0.0.1.tar.gz
  • cloc-1.64.zip

    2021-05-07 13:56:37
    cloc-1.64.zip
  • cloc-1.84.exe

    2020-07-05 22:14:34
    项目代码行数统计,区分注释、空行、有效代码行数,支持C/C++、JAVA、PYTHON、PHP等主流编程语言。通过命令行操作,命令参数为文件夹路径。
  • cloc-1.88.exe

    2021-02-05 14:56:38
    代码行数统计工具,识别c/c++、js、Java、.net等大量编程语言,无需安装,直接命令行操作。
  • cloc统计代码行数工具

    2021-01-15 00:32:11
    统计代码行数
  • 角色扮演:cloc 在基于Debian和基于EL的系统上安装(默认情况下) 或卸载(如果作为var传递)的角色。 根据存储库GitHub页面上的官方声明,它允许“ cloc计数许多编程语言中源代码的空行,注释行和物理行”。要求...
  • 好用的源码行数统计工具——cloc

    千次阅读 2022-03-31 11:19:03
    1. cloc简介2. 下载并安装cloc2.1. 通过包管理器安装2.2. 在Github下载稳定发布版本3. cloc的基本使用方法4. 附 1. cloc简介   cloc是一款用于统计源码信息行数的工具,可以针对许多编程语言中源代码的空白行、...

    1. cloc简介

      cloc是一款用于统计源码信息行数的工具,可以针对许多编程语言中源代码的空白行、注释行和物理行进行计数。给定两个版本的代码库,cloc 可以计算空白行、注释行和源代码行的差异。它完全用 Perl 编写,不依赖于 Perl v5.6 及更高版本的标准发行版(来自一些外部模块的代码嵌入在 cloc 中),因此非常可移植。众所周知,cloc 可在多种 Linux、FreeBSD、NetBSD、OpenBSD、macOS、AIX、HP-UX、Solaris、IRIX、z/OSWindows 上运行。(要在 Windows 上运行 clocPerl 源版本,需要 ActiveState Perl 5.6.1或更高版本、Strawberry Perl、适用于 LinuxWindows 子系统、 CygwinMobaXTerm安装 Perl 插件,或 mingw 环境和终端,例如 Git for Windows提供的。或者,可以使用PAR::Packer生成的 clocWindows 二进制文件在既没有 Perl 也没有 CygwinWindows 计算机上运行。)

      cloc包含来自 David WheelerSLOCCount、 Damian ConwayAbigailPerl 模块 Regexp::Common、 Sean M. BurkePerl 模块 Win32::AutoglobTye McQueenPerl模块Algorithm::Diff的代码。语言比例因子来自 Mayes Consulting, LLC 网站 http://softwareestimator.com/IndustryData2.htm

    2. 下载并安装cloc

    2.1. 通过包管理器安装

    根据您的操作系统,其中一种安装方法可能适合您(Windows的最后两个条目除外,都需要 Perl解释器):

    npm install -g cloc              # https://www.npmjs.com/package/cloc
    sudo apt install cloc            # Debian, Ubuntu
    sudo yum install cloc            # Red Hat, Fedora
    sudo dnf install cloc            # Fedora 22 or later
    sudo pacman -S cloc              # Arch
    sudo emerge -av dev-util/cloc    # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
    sudo apk add cloc                # Alpine Linux
    doas pkg_add cloc                # OpenBSD
    sudo pkg install cloc            # FreeBSD
    sudo port install cloc           # macOS with MacPorts
    brew install cloc                # macOS with Homebrew
    choco install cloc               # Windows with Chocolatey
    scoop install cloc               # Windows with Scoop
    

    [注]:如果您在使用上述软件包之一的 cloc 中遇到错误,请在提交问题报告之前尝试从 GitHub 上的最新稳定版本中提取的 cloc。

    2.2. 在Github下载稳定发布版本

      在包管理器安装失败或者安装后出现问题无法使用,可以直接在Github上下载源码编译或者直接下载编译好的稳定发布版本。
    Github链接: https://github.com/AlDanial/cloc/releases/latest

    3. cloc的基本使用方法

      本文只介绍cloc工具的最基本和常用的使用方法,即统计源码行数功能。
    测试环境为Windows11
    [注]:如果不是通过包管理器安装的cloc工具,则需要将exe文件拷贝到源码目录下使用

    PS E:\Code\stressapptest-master\src> .\cloc-1.64.exe ./
          31 text files.
          31 unique files.
           4 files ignored.
    
    http://cloc.sourceforge.net v 1.64  T=0.17 s (165.0 files/s, 72687.8 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    C++                             13           1253           1464           6380
    C/C++ Header                    13            546            922           1593
    C                                1             21             47             72
    make                             1              4              0             30
    -------------------------------------------------------------------------------
    SUM:                            28           1824           2433           8075
    -------------------------------------------------------------------------------
    

    测试环境为Ubuntu20.04

    imaginemiracle@: cloc perl-5.22.0.tar.gz
        5605 text files.
        5386 unique files.
        2176 files ignored.
    
    https://github.com/AlDanial/cloc v 1.65  T=25.49 s (134.7 files/s, 51980.3 lines/s)
    -----------------------------------------------------------------------------------
    Language                         files          blank        comment           code
    -----------------------------------------------------------------------------------
    Perl                              2892         136396         184362         536445
    C                                  130          24676          33684         155648
    C/C++ Header                       148           9766          16569         147858
    Bourne Shell                       112           4044           6796          42668
    Pascal                               8            458           1603           8592
    XML                                 33            142              0           2410
    YAML                                49             20             15           2078
    C++                                 10            313            277           2033
    make                                 4            426            488           1986
    Prolog                              12            438              2           1146
    JSON                                14              1              0           1037
    yacc                                 1             85             76            998
    Windows Message File                 1            102             11            489
    DOS Batch                           14             92             41            389
    Windows Resource File                3             10              0             85
    D                                    1              5              7              8
    Lisp                                 2              0              3              4
    -----------------------------------------------------------------------------------
    SUM:                              3434         176974         243934         903874
    -----------------------------------------------------------------------------------
    

    4. 附

      下面附上cloc工具的--help输出,仅供参考使用。

    imaginemiracle@: cloc --help
    
    Usage: cloc [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <report files>
    
     Count, or compute differences of, physical lines of source code in the
     given files (may be archives such as compressed tarballs or zip files,
     or git commit hashes or branch names) and/or recursively below the
     given directories.
    
     Input Options
       --extract-with=<cmd>      This option is only needed if cloc is unable
                                 to figure out how to extract the contents of
                                 the input file(s) by itself.
                                 Use <cmd> to extract binary archive files (e.g.:
                                 .tar.gz, .zip, .Z).  Use the literal '>FILE<' as
                                 a stand-in for the actual file(s) to be
                                 extracted.  For example, to count lines of code
                                 in the input files
                                    gcc-4.2.tar.gz  perl-5.8.8.tar.gz
                                 on Unix use
                                   --extract-with='gzip -dc >FILE< | tar xf -'
                                 or, if you have GNU tar,
                                   --extract-with='tar zxf >FILE<'
                                 and on Windows use, for example:
                                   --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ."
                                 (if WinZip is installed there).
       --list-file=<file>        Take the list of file and/or directory names to
                                 process from <file>, which has one file/directory
                                 name per line.  Only exact matches are counted;
                                 relative path names will be resolved starting from
                                 the directory where cloc is invoked.  Set <file>
                                 to - to read file names from a STDIN pipe.
                                 See also --exclude-list-file.
       --diff-list-file=<file>   Take the pairs of file names to be diff'ed from
                                 <file>, whose format matches the output of
                                 --diff-alignment.  (Run with that option to
                                 see a sample.)  The language identifier at the
                                 end of each line is ignored.  This enables --diff
                                 mode and bypasses file pair alignment logic.
       --vcs=<VCS>               Invoke a system call to <VCS> to obtain a list of
                                 files to work on.  If <VCS> is 'git', then will
                                 invoke 'git ls-files' to get a file list and
                                 'git submodule status' to get a list of submodules
                                 whose contents will be ignored.  See also --git
                                 which accepts git commit hashes and branch names.
                                 If <VCS> is 'svn' then will invoke 'svn list -R'.
                                 The primary benefit is that cloc will then skip
                                 files explicitly excluded by the versioning tool
                                 in question, ie, those in .gitignore or have the
                                 svn:ignore property.
                                 Alternatively <VCS> may be any system command
                                 that generates a list of files.
                                 Note:  cloc must be in a directory which can read
                                 the files as they are returned by <VCS>.  cloc will
                                 not download files from remote repositories.
                                 'svn list -R' may refer to a remote repository
                                 to obtain file names (and therefore may require
                                 authentication to the remote repository), but
                                 the files themselves must be local.
                                 Setting <VCS> to 'auto' selects between 'git'
                                 and 'svn' (or neither) depending on the presence
                                 of a .git or .svn subdirectory below the directory
                                 where cloc is invoked.
       --unicode                 Check binary files to see if they contain Unicode
                                 expanded ASCII text.  This causes performance to
                                 drop noticeably.
    
     Processing Options
       --autoconf                Count .in files (as processed by GNU autoconf) of
                                 recognized languages.  See also --no-autogen.
       --by-file                 Report results for every source file encountered.
       --by-file-by-lang         Report results for every source file encountered
                                 in addition to reporting by language.
       --config <file>           Read command line switches from <file> instead of
                                 the default location of /home/al/.config/cloc/options.txt.
                                 The file should contain one switch, along with
                                 arguments (if any), per line.  Blank lines and lines
                                 beginning with '#' are skipped.  Options given on
                                 the command line take priority over entries read from
                                 the file.
       --count-and-diff <set1> <set2>
                                 First perform direct code counts of source file(s)
                                 of <set1> and <set2> separately, then perform a diff
                                 of these.  Inputs may be pairs of files, directories,
                                 or archives.  If --out or --report-file is given,
                                 three output files will be created, one for each
                                 of the two counts and one for the diff.  See also
                                 --diff, --diff-alignment, --diff-timeout,
                                 --ignore-case, --ignore-whitespace.
       --diff <set1> <set2>      Compute differences in code and comments between
                                 source file(s) of <set1> and <set2>.  The inputs
                                 may be any mix of files, directories, archives,
                                 or git commit hashes.  Use --diff-alignment to
                                 generate a list showing which file pairs where
                                 compared.  When comparing git branches, only files
                                 which have changed in either commit are compared.
                                 See also --git, --count-and-diff, --diff-alignment,
                                 --diff-list-file, --diff-timeout, --ignore-case,
                                 --ignore-whitespace.
       --diff-timeout <N>        Ignore files which take more than <N> seconds
                                 to process.  Default is 10 seconds.  Setting <N>
                                 to 0 allows unlimited time.  (Large files with many
                                 repeated lines can cause Algorithm::Diff::sdiff()
                                 to take hours.) See also --timeout.
       --docstring-as-code       cloc considers docstrings to be comments, but this is
                                 not always correct as docstrings represent regular
                                 strings when they appear on the right hand side of an
                                 assignment or as function arguments.  This switch
                                 forces docstrings to be counted as code.
       --follow-links            [Unix only] Follow symbolic links to directories
                                 (sym links to files are always followed).
                                 See also --stat.
       --force-lang=<lang>[,<ext>]
                                 Process all files that have a <ext> extension
                                 with the counter for language <lang>.  For
                                 example, to count all .f files with the
                                 Fortran 90 counter (which expects files to
                                 end with .f90) instead of the default Fortran 77
                                 counter, use
                                   --force-lang="Fortran 90",f
                                 If <ext> is omitted, every file will be counted
                                 with the <lang> counter.  This option can be
                                 specified multiple times (but that is only
                                 useful when <ext> is given each time).
                                 See also --script-lang, --lang-no-ext.
       --force-lang-def=<file>   Load language processing filters from <file>,
                                 then use these filters instead of the built-in
                                 filters.  Note:  languages which map to the same
                                 file extension (for example:
                                 MATLAB/Mathematica/Objective-C/MUMPS/Mercury;
                                 Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
                                 will be ignored as these require additional
                                 processing that is not expressed in language
                                 definition files.  Use --read-lang-def to define
                                 new language filters without replacing built-in
                                 filters (see also --write-lang-def,
                                 --write-lang-def-incl-dup).
       --git                     Forces the inputs to be interpreted as git targets
                                 (commit hashes, branch names, et cetera) if these
                                 are not first identified as file or directory
                                 names.  This option overrides the --vcs=git logic
                                 if this is given; in other words, --git gets its
                                 list of files to work on directly from git using
                                 the hash or branch name rather than from
                                 'git ls-files'.  This option can be used with
                                 --diff to perform line count diffs between git
                                 commits, or between a git commit and a file,
                                 directory, or archive.  Use -v/--verbose to see
                                 the git system commands cloc issues.
       --git-diff-rel            Same as --git --diff, or just --diff if the inputs
                                 are recognized as git targets.  Only files which
                                 have changed in either commit are compared.
       --git-diff-all            Git diff strategy #2:  compare all files in the
                                 repository between the two commits.
       --ignore-whitespace       Ignore horizontal white space when comparing files
                                 with --diff.  See also --ignore-case.
       --ignore-case             Ignore changes in case within file contents;
                                 consider upper- and lowercase letters equivalent
                                 when comparing files with --diff.  See also
                                 --ignore-whitespace.
       --ignore-case-ext         Ignore case of file name extensions.  This will
                                 cause problems counting some languages
                                 (specifically, .c and .C are associated with C and
                                 C++; this switch would count .C files as C rather
                                 than C++ on *nix operating systems).  File name
                                 case insensitivity is always true on Windows.
       --lang-no-ext=<lang>      Count files without extensions using the <lang>
                                 counter.  This option overrides internal logic
                                 for files without extensions (where such files
                                 are checked against known scripting languages
                                 by examining the first line for #!).  See also
                                 --force-lang, --script-lang.
       --max-file-size=<MB>      Skip files larger than <MB> megabytes when
                                 traversing directories.  By default, <MB>=100.
                                 cloc's memory requirement is roughly twenty times
                                 larger than the largest file so running with
                                 files larger than 100 MB on a computer with less
                                 than 2 GB of memory will cause problems.
                                 Note:  this check does not apply to files
                                 explicitly passed as command line arguments.
       --no-autogen[=list]       Ignore files generated by code-production systems
                                 such as GNU autoconf.  To see a list of these files
                                 (then exit), run with --no-autogen list
                                 See also --autoconf.
       --original-dir            [Only effective in combination with
                                 --strip-comments]  Write the stripped files
                                 to the same directory as the original files.
       --read-binary-files       Process binary files in addition to text files.
                                 This is usually a bad idea and should only be
                                 attempted with text files that have embedded
                                 binary data.
       --read-lang-def=<file>    Load new language processing filters from <file>
                                 and merge them with those already known to cloc.
                                 If <file> defines a language cloc already knows
                                 about, cloc's definition will take precedence.
                                 Use --force-lang-def to over-ride cloc's
                                 definitions (see also --write-lang-def,
                                 --write-lang-def-incl-dup).
       --script-lang=<lang>,<s>  Process all files that invoke <s> as a #!
                                 scripting language with the counter for language
                                 <lang>.  For example, files that begin with
                                    #!/usr/local/bin/perl5.8.8
                                 will be counted with the Perl counter by using
                                    --script-lang=Perl,perl5.8.8
                                 The language name is case insensitive but the
                                 name of the script language executable, <s>,
                                 must have the right case.  This option can be
                                 specified multiple times.  See also --force-lang,
                                 --lang-no-ext.
       --sdir=<dir>              Use <dir> as the scratch directory instead of
                                 letting File::Temp chose the location.  Files
                                 written to this location are not removed at
                                 the end of the run (as they are with File::Temp).
       --skip-uniqueness         Skip the file uniqueness check.  This will give
                                 a performance boost at the expense of counting
                                 files with identical contents multiple times
                                 (if such duplicates exist).
       --stat                    Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
                                 do not have directory 'nlink' counts that match
                                 the number of its subdirectories.  Consequently
                                 cloc may undercount or completely skip the
                                 contents of such file systems.  This switch forces
                                 File::Find to stat directories to obtain the
                                 correct count.  File search speed will decrease.
                                 See also --follow-links.
       --stdin-name=<file>       Give a file name to use to determine the language
                                 for standard input.  (Use - as the input name to
                                 receive source code via STDIN.)
       --strip-comments=<ext>    For each file processed, write to the current
                                 directory a version of the file which has blank
                                 and commented lines removed (in-line comments
                                 persist).  The name of each stripped file is the
                                 original file name with .<ext> appended to it.
                                 It is written to the current directory unless
                                 --original-dir is on.
       --strip-str-comments      Replace comment markers embedded in strings with
                                 'xx'.  This attempts to work around a limitation
                                 in Regexp::Common::Comment where comment markers
                                 embedded in strings are seen as actual comment
                                 markers and not strings, often resulting in a
                                 'Complex regular subexpression recursion limit'
                                 warning and incorrect counts.  There are two
                                 disadvantages to using this switch:  1/code count
                                 performance drops, and 2/code generated with
                                 --strip-comments will contain different strings
                                 where ever embedded comments are found.
       --sum-reports             Input arguments are report files previously
                                 created with the --report-file option in plain
                                 format (eg. not JSON, YAML, XML, or SQL).
                                 Makes a cumulative set of results containing the
                                 sum of data from the individual report files.
       --timeout <N>             Ignore files which take more than <N> seconds
                                 to process at any of the language's filter stages.
                                 The default maximum number of seconds spent on a
                                 filter stage is the number of lines in the file
                                 divided by one thousand.  Setting <N> to 0 allows
                                 unlimited time.  See also --diff-timeout.
       --processes=NUM           [Available only on systems with a recent version
                                 of the Parallel::ForkManager module.  Not
                                 available on Windows.] Sets the maximum number of
                                 cores that cloc uses.  The default value of 0
                                 disables multiprocessing.
       --unix                    Override the operating system autodetection
                                 logic and run in UNIX mode.  See also
                                 --windows, --show-os.
       --use-sloccount           If SLOCCount is installed, use its compiled
                                 executables c_count, java_count, pascal_count,
                                 php_count, and xml_count instead of cloc's
                                 counters.  SLOCCount's compiled counters are
                                 substantially faster than cloc's and may give
                                 a performance improvement when counting projects
                                 with large files.  However, these cloc-specific
                                 features will not be available: --diff,
                                 --count-and-diff, --strip-comments, --unicode.
       --windows                 Override the operating system autodetection
                                 logic and run in Microsoft Windows mode.
                                 See also --unix, --show-os.
    
     Filter Options
       --exclude-content=<regex> Exclude files containing text that matches the given
                                 regular expression.
       --exclude-dir=<D1>[,D2,]  Exclude the given comma separated directories
                                 D1, D2, D3, et cetera, from being scanned.  For
                                 example  --exclude-dir=.cache,test  will skip
                                 all files and subdirectories that have /.cache/
                                 or /test/ as their parent directory.
                                 Directories named .bzr, .cvs, .hg, .git, .svn,
                                 and .snapshot are always excluded.
                                 This option only works with individual directory
                                 names so including file path separators is not
                                 allowed.  Use --fullpath and --not-match-d=<regex>
                                 to supply a regex matching multiple subdirectories.
       --exclude-ext=<ext1>[,<ext2>[...]]
                                 Do not count files having the given file name
                                 extensions.
       --exclude-lang=<L1>[,L2[...]]
                                 Exclude the given comma separated languages
                                 L1, L2, L3, et cetera, from being counted.
       --exclude-list-file=<file>  Ignore files and/or directories whose names
                                 appear in <file>.  <file> should have one file
                                 name per line.  Only exact matches are ignored;
                                 relative path names will be resolved starting from
                                 the directory where cloc is invoked.
                                 See also --list-file.
       --fullpath                Modifies the behavior of --match-f, --not-match-f,
                                 and --not-match-d to include the file's path
                                 in the regex, not just the file's basename.
                                 (This does not expand each file to include its
                                 absolute path, instead it uses as much of
                                 the path as is passed in to cloc.)
                                 Note:  --match-d always looks at the full
                                 path and therefore is unaffected by --fullpath.
       --include-ext=<ext1>[,ext2[...]]
                                 Count only languages having the given comma
                                 separated file extensions.  Use --show-ext to
                                 see the recognized extensions.
       --include-lang=<L1>[,L2[...]]
                                 Count only the given comma separated languages
                                 L1, L2, L3, et cetera.  Use --show-lang to see
                                 the list of recognized languages.
       --match-d=<regex>         Only count files in directories matching the Perl
                                 regex.  For example
                                   --match-d='/(src|include)/'
                                 only counts files in directories containing
                                 /src/ or /include/.  Unlike --not-match-d,
                                 --match-f, and --not-match-f, --match-d always
                                 compares the fully qualified path against the
                                 regex.
       --not-match-d=<regex>     Count all files except those in directories
                                 matching the Perl regex.  Only the trailing
                                 directory name is compared, for example, when
                                 counting in /usr/local/lib, only 'lib' is
                                 compared to the regex.
                                 Add --fullpath to compare parent directories to
                                 the regex.
                                 Do not include file path separators at the
                                 beginning or end of the regex.
       --match-f=<regex>         Only count files whose basenames match the Perl
                                 regex.  For example
                                   --match-f='^[Ww]idget'
                                 only counts files that start with Widget or widget.
                                 Add --fullpath to include parent directories
                                 in the regex instead of just the basename.
       --not-match-f=<regex>     Count all files except those whose basenames
                                 match the Perl regex.  Add --fullpath to include
                                 parent directories in the regex instead of just
                                 the basename.
       --skip-archive=<regex>    Ignore files that end with the given Perl regular
                                 expression.  For example, if given
                                   --skip-archive='(zip|tar(.(gz|Z|bz2|xz|7z))?)'
                                 the code will skip files that end with .zip,
                                 .tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
                                 .tar.7z.
       --skip-win-hidden         On Windows, ignore hidden files.
    
     Debug Options
       --categorized=<file>      Save names of categorized files to <file>.
       --counted=<file>          Save names of processed source files to <file>.
       --diff-alignment=<file>   Write to <file> a list of files and file pairs
                                 showing which files were added, removed, and/or
                                 compared during a run with --diff.  This switch
                                 forces the --diff mode on.
       --explain=<lang>          Print the filters used to remove comments for
                                 language <lang> and exit.  In some cases the
                                 filters refer to Perl subroutines rather than
                                 regular expressions.  An examination of the
                                 source code may be needed for further explanation.
       --help                    Print this usage information and exit.
       --found=<file>            Save names of every file found to <file>.
       --ignored=<file>          Save names of ignored files and the reason they
                                 were ignored to <file>.
       --print-filter-stages     Print processed source code before and after
                                 each filter is applied.
       --show-ext[=<ext>]        Print information about all known (or just the
                                 given) file extensions and exit.
       --show-lang[=<lang>]      Print information about all known (or just the
                                 given) languages and exit.
       --show-os                 Print the value of the operating system mode
                                 and exit.  See also --unix, --windows.
       -v[=<n>]                  Verbose switch (optional numeric value).
       -verbose[=<n>]            Long form of -v.
       --version                 Print the version of this program and exit.
       --write-lang-def=<file>   Writes to <file> the language processing filters
                                 then exits.  Useful as a first step to creating
                                 custom language definitions. Note: languages which
                                 map to the same file extension will be excluded.
                                 (See also --force-lang-def, --read-lang-def).
       --write-lang-def-incl-dup=<file>
                                 Same as --write-lang-def, but includes duplicated
                                 extensions.  This generates a problematic language
                                 definition file because cloc will refuse to use
                                 it until duplicates are removed.
    
     Output Options
       --3                       Print third-generation language output.
                                 (This option can cause report summation to fail
                                 if some reports were produced with this option
                                 while others were produced without it.)
       --by-percent  X           Instead of comment and blank line counts, show
                                 these values as percentages based on the value
                                 of X in the denominator:
                                    X = 'c'   -> # lines of code
                                    X = 'cm'  -> # lines of code + comments
                                    X = 'cb'  -> # lines of code + blanks
                                    X = 'cmb' -> # lines of code + comments + blanks
                                 For example, if using method 'c' and your code
                                 has twice as many lines of comments as lines
                                 of code, the value in the comment column will
                                 be 200%.  The code column remains a line count.
       --csv                     Write the results as comma separated values.
       --csv-delimiter=<C>       Use the character <C> as the delimiter for comma
                                 separated files instead of ,.  This switch forces --csv to be on.
       --file-encoding=<E>       Write output files using the <E> encoding instead of
                                 the default ASCII (<E> = 'UTF-7').  Examples: 'UTF-16',
                                 'euc-kr', 'iso-8859-16'.  Known encodings can be
                                 printed with
                                   perl -MEncode -e 'print join("\n", Encode->encodings(":all")), "\n"'
       --hide-rate               Do not show line and file processing rates in the
                                 output header. This makes output deterministic.
       --json                    Write the results as JavaScript Object Notation
                                 (JSON) formatted output.
       --md                      Write the results as Markdown-formatted text.
       --out=<file>              Synonym for --report-file=<file>.
       --progress-rate=<n>       Show progress update after every <n> files are
                                 processed (default <n>=100).  Set <n> to 0 to
                                 suppress progress output (useful when redirecting
                                 output to STDOUT).
       --quiet                   Suppress all information messages except for
                                 the final report.
       --report-file=<file>      Write the results to <file> instead of STDOUT.
       --sql=<file>              Write results as SQL create and insert statements
                                 which can be read by a database program such as
                                 SQLite.  If <file> is -, output is sent to STDOUT.
       --sql-append              Append SQL insert statements to the file specified
                                 by --sql and do not generate table creation
                                 statements.  Only valid with the --sql option.
       --sql-project=<name>      Use <name> as the project identifier for the
                                 current run.  Only valid with the --sql option.
       --sql-style=<style>       Write SQL statements in the given style instead
                                 of the default SQLite format.  Styles include
                                 'Oracle' and 'Named_Columns'.
       --sum-one                 For plain text reports, show the SUM: output line
                                 even if only one input file is processed.
       --xml                     Write the results in XML.
       --xsl=<file>              Reference <file> as an XSL stylesheet within
                                 the XML output.  If <file> is 1 (numeric one),
                                 writes a default stylesheet, cloc.xsl (or
                                 cloc-diff.xsl if --diff is also given).
                                 This switch forces --xml on.
       --yaml                    Write the results in YAML.
    
    展开全文
  • 一款使用Perl语言开发的开源代码统计工具,支持多平台使用、多语言识别,能够计算指定目标文件或文件夹中的文件数(files)、空白行数(blank)、注释行数(comment)和代码行数(code)
  • 解压到桌面之后,直接运行exe然后在打开命令行输入cmd操作即可。
  • Codacy Metrics Cloc 这是我们在Codacy使用的docker引擎,具有cloc支持。用法您可以通过执行以下操作来创建泊坞窗: sbt docker:publishLocal 使用以下命令运行docker: docker run -it -v $srcDir :/src < DOCKER> ...
  • 计数(发音为“tee-count”)通过标记、语法树节点的类型和语法树中的模式来计算您的代码。快速开始只需在项目根目录中运行tcount即可计算令牌和文件并打印按语言分组的结果。例如,tcount────────────...
  • macOS with MacPorts brew install cloc # macOS with Homebrew choco install cloc # Windows with Chocolatey scoop install cloc # Windows with Scoop cloc 优势? cloc 具有易于使用、可扩展和可移植的特性: ...

    上下文

    我们通常用代码量来评判一个程序员技术的高低或一个项目的大小,阅读新项目源码时,也需要了解其代码量,心里有个预期。

    那如何统计代码量呢?

    传统做法

    通过find+wc命令完成

    $ find . -name "*.go" | xargs wc -l
    
    60 ./etcd/tutorial/distributed_lock.go
    ...
    3491 total
    

    如上,统计命令显示了所有文件,一共有 3491 行代码。但是此处统计太过粗暴,wc 统计过程将注释、空白行等内容都被算作代码统计其中。

    我们应该尝试更有效的统计方式。

    有效统计 cloc

    cloc(Count Lines of Code[0]) 是一个 Perl 语言开发的开源代码统计工具。支持多平台、多语言、分类别的统计目标文件或文件夹中源代码的文件数、空白行数、注释行数和代码行数。

    安装

    支持多种安装方式,几乎包含常用的所有安装方式。

    npm install -g cloc              # https://www.npmjs.com/package/cloc
    sudo apt install cloc            # Debian, Ubuntu
    sudo yum install cloc            # Red Hat, Fedora
    sudo dnf install cloc            # Fedora 22 or later
    sudo pacman -S cloc              # Arch
    sudo emerge -av dev-util/cloc    # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
    sudo apk add cloc                # Alpine Linux
    doas pkg_add cloc                # OpenBSD
    sudo pkg install cloc            # FreeBSD
    sudo port install cloc           # macOS with MacPorts
    brew install cloc                # macOS with Homebrew
    choco install cloc               # Windows with Chocolatey
    scoop install cloc               # Windows with Scoop
    

    cloc 优势?

    cloc 具有易于使用、可扩展和可移植的特性:

    • 安装方便,只需下载文件包运行即可。
    • 支持分类别统计多种语言:Java、Go、Python、C 等。
    • 支持分类别统计多种格式的结果:纯文本、SQL、JSON、XML、YAML、逗号分隔值等。
    • 支持分类别统计文件数、空白行数、注释行数和代码行数。

    基本使用

    $ cloc ./					# 可统计目录
    $ cloc perl-5.22.0.tar.gz	# 也可直接统计压缩包
    

    对于前端同学,统计代码往往需要忽略最大的 node_modules 以及打包生成的 dist 文件,支持过滤逻辑,使用非常方便。

    $ cloc $(git ls-files) 
    # 或
    $ cloc --vcs git 			
    # 或过滤 svn 
    $ cloc --vcs svn
    

    高级用法

    使用方法也很简单,统计结果会按照语言分类统计源代码的空白行、注释行和物理行。具体如下:

    统计单个文件

    #$ cloc docker-compose-devcontainer.yml
    
           1 text file.
           1 unique file.
           0 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.01 s (140.6 files/s, 4919.9 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    YAML                             1              3              1             31
    -------------------------------------------------------------------------------
    

    统计文件夹

    $ cloc .
    
          54 text files.
          42 unique files.
          14 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.14 s (290.8 files/s, 22637.6 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    Go                              29            381            216           2468
    Markdown                         6             28              0             55
    ...
    -------------------------------------------------------------------------------
    SUM:                            42            431            220           2618
    -------------------------------------------------------------------------------
    

    也同时支持通过--exclude-dir参数过滤掉不计入统计的路径

    $ cloc . --exclude-dir=build
    
          52 text files.
          40 unique files.
          14 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.07 s (605.9 files/s, 48999.6 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    Go                              29            381            216           2468
    Markdown                         5             27              0             54
    ...
    -------------------------------------------------------------------------------
    SUM:                            40            423            217           2595
    -------------------------------------------------------------------------------
    

    也支持按--by-file参数进行统计结果的筛选。

    $ cloc . --by-file | head -n 10
    
          54 text files.
          42 unique files.
          14 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.03 s (1380.3 files/s, 107434.2 lines/s)
    -----------------------------------------------------------------------------------------
    File                                                  blank        comment           code
    -----------------------------------------------------------------------------------------
    ./etcd/tutorial/demo.go                                  53              0            291
    ./etcd/simple_raft/raft_log.go                           29             93            263
    

    统计文件夹下多个子目录

    $ for d in ./*/ ; do (cd "$d" && echo "$d" && cloc .); done
    ./go-bootcamp/
        1474 text files.
        1226 unique files.
         540 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=7.16 s (171.2 files/s, 118482.4 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    JavaScript                     421          10606          84539         584311
    ...
    -------------------------------------------------------------------------------
    SUM:                          1226          18182         100323         729998
    -------------------------------------------------------------------------------
    ./html-bootcamp/
          18 text files.
          15 unique files.
           5 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.02 s (635.5 files/s, 9744.9 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    HTML                             4             28              8             89
    ...
    -------------------------------------------------------------------------------
    SUM:                            15             51             15            164
    -------------------------------------------------------------------------------
    ./java-bootcamp/
           3 text files.
           1 unique file.
           3 files ignored.
    
    github.com/AlDanial/cloc v 1.92  T=0.01 s (104.8 files/s, 524.2 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    Markdown                         1              2              0              3
    -------------------------------------------------------------------------------
    

    更多命令

    $ cloc --help
    

    支持的语言

    $ cloc --show-lang
    

    通过 docker 运行

    $ docker run --rm -v $PWD:/tmp aldanial/cloc ./
    

    以上,就是今天的全部内容,包含了 cloc 安装和使用。当然,重要的内容往往篇幅较小,很推荐 docker 运行方式。

    ❤️❤️❤️读者每一份热爱都是笔者前进的动力!
    我是三十一[1],感谢各位朋友:求点赞、求评论、求转发,大家下期见!

    References

    • [0] Count Lines of Code: https://github.com/AlDanial/cloc
    • [1] 三十一: http://www.lee31.cn/assets/image/ThirtyOneLee.jpeg

    往期文章

    • 入门篇:从 etcd 名字的由来,到安装部署和使用姿势
    • 如何看待 Python(PyScript) 可以做浏览器前端开发语言?
    • 深度总结,带你玩转 NVIDIA GPU
    • 还活在上个时代,Etcd 3.0 实现分布式锁竟如此简单
    • 从 0 到 1,如何徒手撸一个 Python 插件系统?
    • 一站式机器学习开业平台 MLflow 怎么样?
    展开全文
  • cloc用perl编写,此程序包公开的二进制文件是cloc perl脚本。 您必须在计算机上安装perl才能使此二进制文件正常工作。 节点和npm 这是作为npm软件包分发的(有人说它代表“节点软件包管理器”)。 因此,您必须安装...
  • git cloc历史 用于为存储库生成代码历史记录行的CSV的命令行工具。 您必须在您的PATH上安装了 。 建造 要构建,请在SBT中运行项目 $ cd /path/to/git-cloc-history $ sbt > universal:packageBin 这应该生成target...
  • ClOC代码统计行数(安装包)ClOC代码统计行数(安装包),ClOC代码统计行数(安装包)亲测可用!
  • PHPCloc :rocket: 用PHP编写的Cloc和重复代码检查器 要求 ...安装 手动的 ...// or ...然后 $ sudo chmod a+x phpcloc $ sudo mv phpcloc /usr/local/bin/phpcloc ... $ composer global require... $ phpcloc cloc . 重复代码检
  • cloc用perl编写,此程序包公开的二进制文件是cloc perl脚本。 您必须在计算机上安装perl才能使此二进制文件正常工作。 用法 import { cloc } from 'cloc-lib' ; cloc ( 'filePath' , [ '--json' ] ) . then ( res =>...
  • 原标题:代码统计工具CLOC的使用方法在处理不同的项目时,有时您可能需要提供进度报告或统计信息,或者只是计算代码的价值。有一个简单但功能强大的工具叫做“ cloc - count lines of code”,它允许你计算所有代码...

    原标题:代码统计工具CLOC的使用方法

    在处理不同的项目时,有时您可能需要提供进度报告或统计信息,或者只是计算代码的价值。

    有一个简单但功能强大的工具叫做“ cloc - count lines of code”,它允许你计算所有代码的数量并同时排除注释和空行。

    它适用于所有主要Linux发行版,并支持多种编程语言和文件扩展名,并且没有任何特定要求可供使用。

    在本教程中,您将学习如何在Linux系统上安装和使用cloc。

    如何在Linux系统中安装和使用Cloc

    安装cloc既简单又简单。 您可以在下面看到如何使用相关的包管理器在不同的操作系统中安装cloc:

    $ sudo apt install cloc # Debian, Ubuntu

    $ sudo yum install cloc # Red Hat, Fedora

    $ sudo dnf install cloc # Fedora 22 or later

    $ sudo pacman -S cloc # Arch

    $ sudo emerge -av dev-util/cloc # Gentoo https://packages.gentoo.org/packages/dev-util/cloc

    $ sudo apk add cloc # Alpine Linux

    $ sudo pkg install cloc # FreeBSD

    $ sudo port install cloc # Mac OS X with MacPorts

    $ brew install cloc # Mac OS X with Homebrew

    $ npm install -g cloc # https://www.npmjs.com/package/cloc

    Cloc可用于计算特定文件中的行或目录中的多个文件中的行。 要使用cloc,只需键入cloc,然后键入要检查的文件或目录。

    这是bash中的文件示例。 有问题的文件在bash中包含以下代码:

    $ cat bash_.sh

    11156bf09fe94e8cc5c6bad37292bf3c.png

    Linux Bash脚本

    现在让我们运行cloc。

    $ cloc bash_.sh

    b5f399fcc9e5a77d5f85cd882d5c54c5.png

    计算文件中的行数

    正如您所看到的,它计算了文件数,空行,注释和代码行。

    cloc的另一个很酷的功能是甚至可以在压缩文件上使用。 例如,我已经下载了最新的WordPress存档并在其上运行cloc。

    $ cloc latest.tar.gz

    结果如下:

    6aab94b596477d7f9c3be6761d479614.png

    计算压缩文件的行数

    您可以看到它识别不同类型的代码并分离每种语言的统计信息。

    如果您需要获取目录中多个文件的报告,可以使用“--by-file”选项,这将计算每个文件中的行并为它们提供报告。 对于包含许多文件和数千行代码的项目,这可能需要一段时间。

    语法如下:

    $ cloc --by-file

    52252335b667cd57f56081d29225f1ba.png

    计算多个文件的行数

    虽然cloc的帮助很容易阅读和理解,但我将包含一些可以与cloc一起使用的额外选项,一些用户可能会觉得有用。

    --diff - 计算set1和set2的源文件之间的代码差异。 输入可以是文件和目录的混合。

    --git - 强制输入被识别为git目标,如果它们首先未被识别为文件或目录名称。

    --ignore-whitespace - 在使用--diff比较文件时忽略水平空格。

    --max-file-size= - 如果要跳过大于给定金额MB的文件。

    --exclude-dir=, - 排除给定的逗号分隔目录。

    --exclude-ext=, - 排除给定的文件扩展名。

    --csv - 将结果导出为CSV文件格式。

    --csv-delimiter= - 使用字符作为分隔符。

    --out= - 将结果保存到 。

    --quiet - 禁止所有信息消息并仅显示最终报告。

    --sql= - 将结果写为create和insert语句,这些语句可以由SQLite等数据库程序读取。

    结论

    Cloc是一个有用的实用工具,对你的武器库来说绝对是好事。 虽然它可能不会每天使用,但它可以在您必须生成某些报告时帮助您,或者您只是好奇您的项目是如何进行的。返回搜狐,查看更多

    责任编辑:

    展开全文
  • 使用Cloc衡量回购增长的速度 安装 npm i -g repo-growth 用法 重要说明请确保已拉出master且存储库处于干净状态。 repo-growth ┌─────────────────────┬─────────────┬──...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,875
精华内容 750
关键字:

CLOC