Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

simple tool to count SLOC (source lines of code)

License

NotificationsYou must be signed in to change notification settings

flosse/sloc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create stats of your source code:

  • physical lines
  • lines of code (source)
  • lines with comments
  • lines with single-line comments
  • lines with block comments
  • lines mixed up with source and comments
  • empty lines within block comments
  • empty lines
  • lines with TODO's

NPM versionLicenseMinified size

Supported outputs

In addition to the default terminal output (see examples below), sloc provides an alternative set of output formatters:

  • CSV
  • JSON
  • Command line table

Install

To use sloc as an application install it globally:

sudo npm install -g sloc

If you're going to use it as a Node.js module within your project:

npm install --save sloc

Browser

You can also use sloc within your browser application.

Linksloc.js in your HTML file:

<scriptsrc="lib/sloc.js"></script>

Usage

CLI

sloc [option]<file>|<directory>

Options:

-h, --help                  output usage information-V, --version               output the version number-e, --exclude<regex>       regular expression to exclude files and folders-i, --include<regex>       regular expression to include files and folders-f, --format<format>       format output: json, csv, cli-table    --format-option [value] add formatter option-k, --keys<keys>           report only numbers of the given keys-d, --details               report stats of each analyzed file-a, --alias<custom ext>=<standard ext>alias custom ext to act like standard ext (eg. php5=php,less=css)

e.g.:

$ sloc src/---------- Result ------------            Physical:  1202              Source:  751             Comment:  322 Single-line comment:  299       Block comment:  23               Mixed:  116               Empty:  245Number of filesread:  10------------------------------

or

$ sloc --details \       --format cli-table \       --keys total,source,comment \       --exclude i18n*.\.coffee \       --format-option no-head src/┌─────────────────────────────────┬──────────┬────────┬─────────┐│ src/cli.coffee                  │ 98       │ 74     │ 7       │├─────────────────────────────────┼──────────┼────────┼─────────┤│ src/helpers.coffee              │ 26       │ 20     │ 0       │├─────────────────────────────────┼──────────┼────────┼─────────┤│ src/sloc.coffee                 │ 196      │ 142    │ 20      │├─────────────────────────────────┼──────────┼────────┼─────────┤│ src/formatters/simple.coffee    │ 44       │ 28     │ 7       │├─────────────────────────────────┼──────────┼────────┼─────────┤│ src/formatters/csv.coffee       │ 25       │ 14     │ 5       │├─────────────────────────────────┼──────────┼────────┼─────────┤│ src/formatters/cli-table.coffee │ 22       │ 13     │ 0       │└─────────────────────────────────┴──────────┴────────┴─────────┘

Node.js

Or use it in your own node module

varfs=require('fs');varsloc=require('sloc');fs.readFile("mySourceFile.coffee","utf8",function(err,code){if(err){console.error(err);}else{varstats=sloc(code,"coffee");for(iinsloc.keys){vark=sloc.keys[i];console.log(k+" : "+stats[k]);}}});

Browser usage

varsourceCode="foo();\n /* bar */\n baz();";varstats=window.sloc(sourceCode,"javascript");

Contribute an new formatter

  1. Fork this repo

  2. add the new formatter intosrc/formatters/ that exports amethod with three arguments:

    1. results (object)
    2. global options (object)
    3. formatter specific options (array)
  3. add the formatter insrc/cli.coffee

  4. open a pull request

sloc adapters

Supported languages

  • Assembly
  • Agda
  • Brightscript
  • C / C++
  • C#
  • Clojure / ClojureScript
  • CoffeeScript / IcedCoffeeScript
  • Crystal
  • CSS / SCSS / SASS / LESS / Stylus
  • Dart
  • Elixir
  • Erlang
  • F#
  • Fortran
  • Go
  • Groovy
  • Handlebars
  • Haskell
  • Haxe
  • Hilbert
  • HTML
  • hy
  • Jade
  • Java
  • JavaScript
  • JSX
  • Julia
  • Kotlin
  • LaTeX
  • LilyPond
  • LiveScript
  • Lua
  • MJS
  • Mochi
  • Monkey
  • Mustache
  • Nim
  • Nix
  • Objective-C / Objective-C++
  • OCaml
  • Perl 5
  • PHP
  • PRQL
  • Pug
  • Python
  • R
  • Racket
  • Ren'Py
  • Ruby
  • Rust
  • Scala
  • Squirrel
  • SVG
  • Swift
  • Typescript
  • Visual Basic
  • XML
  • Yaml
  • Zig

Run tests

npmtest

Build

npm run prepublish

Changelog

seeCHANGELOG.md

License

sloc is licensed under the MIT license


[8]ページ先頭

©2009-2025 Movatter.jp