• Stars
    star
    935
  • Rank 46,987 (Top 1.0 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

simple tool to count SLOC (source lines of code)

sloc

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

Build Status Dependency Status NPM version Bower version Mega-Linter License Minified 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.

Link sloc.js in your HTML file:

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

sloc is also available via bower:

bower install sloc

Note: You need to compile the coffee-script files yourself. If you want to use a pre-compiled bower package, you can run

bower install sloc-bower

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 :  245

Number of files read :  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

var fs    = require('fs');
var sloc  = require('sloc');

fs.readFile("mySourceFile.coffee", "utf8", function(err, code){

  if(err){ console.error(err); }
  else{
    var stats = sloc(code,"coffee");
    for(i in sloc.keys){
      var k = sloc.keys[i];
      console.log(k + " : " + stats[k]);
    }
  }
});

Browser usage

var sourceCode = "foo();\n /* bar */\n baz();";

var stats = window.sloc(sourceCode,"javascript");

Contribute an new formatter

  1. Fork this repo

  2. add the new formatter into src/formatters/ that exports a method with three arguments:

    1. results (object)
    2. global options (object)
    3. formatter specific options (array)
  3. add the formatter in src/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
  • 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
  • Python
  • R
  • Racket
  • Ren'Py
  • Ruby
  • Rust
  • Scala
  • Squirrel
  • SVG
  • Swift
  • Typescript
  • Visual Basic
  • XML
  • Yaml

Run tests

npm test

Build

npm run prepublish

Changelog

see CHANGELOG.md

License

sloc is licensed under the MIT license

More Repositories

1

rust-web-framework-comparison

A comparison of some web frameworks and libs written in Rust
Rust
4,385
star
2

rust-os-comparison

A comparison of operating systems written in Rust
593
star
3

scaleApp

scaleApp is a JavaScript framework for scalable and maintainable One-Page-Applications
CoffeeScript
352
star
4

json-file-store

A simple JSON store for Node.js
JavaScript
193
star
5

clean-architecture-with-rust

Full-Stack Clean Architecture implementation example written in Rust
Rust
65
star
6

rust-json-file-store

A simple JSON file store written in Rust.
Rust
62
star
7

text-editors-written-in-rust

62
star
8

listOfToDoManagers

Collection of known web based ToDo/Task/Project/GTD-Managers
58
star
9

rust-sun

A Rust library for calculating sun positions
Rust
44
star
10

node-plc

Node.js module to connect to PLCs
C
26
star
11

linuxconsole

http://sourceforge.net/projects/linuxconsole/
C
25
star
12

FAST

Free All Scrambled Thoughs
JavaScript
24
star
13

node-xmpp-serviceadmin

Service Administration (XEP-0133) library for node-xmpp
CoffeeScript
18
star
14

go-modbus

DONT USE IT: A free modbus library for go
Go
12
star
15

r2d2-cypher

Cypher support for the r2d2 connection pool
Rust
10
star
16

node-xmpp-joap

Jabber Object Access Protocol (XEP-0075) library for node-xmpp
CoffeeScript
8
star
17

oven

simple cookie middleware for Iron
Rust
7
star
18

semanticExperiments

Experiments with semantic web technologies
JavaScript
5
star
19

npm-source-sans-pro

CSS
5
star
20

node-ezmlm

Node.js wrapper for ezmlm
CoffeeScript
5
star
21

inversePendulumExperiments

Arduino
5
star
22

bits

Easy bit manipulation
CoffeeScript
4
star
23

als-aid

Advanced Life Support - Mobile App
CSS
4
star
24

xmpp

Clone of the XMPP Standards Foundation XEP repository.
Python
3
star
25

react-vm-flower

React.js component to render a VM flower with SVG
CoffeeScript
3
star
26

smackScalaHelpers

A collection of little helpers written in Scala for the XMPP Smack library
Scala
2
star
27

r2d2-jfs

Rust
2
star
28

multi-vlc

Control multiple VLC instances with only one web interface
CoffeeScript
2
star
29

node-xmpp-logger

Logging over XMPP
CoffeeScript
2
star
30

hello-xmpp

A collection of "Hello world!" examples written with several XMPP-libraries
C
2
star
31

wasm-browser-extension-test

JavaScript
2
star
32

nickel-sqlite

A SQLite middleware for nickel.rs
Rust
2
star
33

node-jid

Parse and handle XMPP/Jabber Identifiers
JavaScript
2
star
34

egui-font-rendering-bug

Rust
1
star
35

npm-strophe-plugins

JavaScript
1
star