martianyi / github-sloc

Chrome extension to display SLOC (source lines of code) on GitHub
https://goo.gl/tb7GW2
MIT License
13 stars 5 forks source link

Use tokei.rs to get lines of code #2

Open miraclx opened 3 years ago

miraclx commented 3 years ago

Currently (a3f7db1), this repo calculates the total lines of code by using GitHub code frequency data.

It doesn't actually reflect the actual lines of code for a repo at a given time.

A good alternative to this would be to use tokei and it's equivalent web server tokei_rs

tokei_rs supports querying and responds, appropriately in JSON format.

Example

curl -H 'Accept: application/json' 'https://tokei.rs/b1/github/miraclx/freyr-js?category=lines' | jq

Response

{
  "blanks": 310,
  "code": 4660,
  "comments": 363,
  "lines": 5333,
  "stats": [
    {
      "blanks": 75,
      "code": 1633,
      "comments": 58,
      "lines": 1765,
      "name": "cli.js"
    },
    {
      "blanks": 3,
      "code": 9,
      "comments": 11,
      "lines": 22,
      "name": "banner.js"
    },
    {
      "blanks": 2,
      "code": 18,
      "comments": 1,
      "lines": 21,
      "name": "src/walkr.js"
    },
    {
      "blanks": 0,
      "code": 4,
      "comments": 0,
      "lines": 3,
      "name": "src/symbols.js"
    },
    {
      "blanks": 3,
      "code": 60,
      "comments": 22,
      "lines": 85,
      "name": "src/stream_utils.js"
    },
    {
      "blanks": 17,
      "code": 113,
      "comments": 88,
      "lines": 218,
      "name": "src/stack_logger.js"
    },
    {
      "blanks": 7,
      "code": 69,
      "comments": 25,
      "lines": 99,
      "name": "src/parse_range.js"
    },
    {
      "blanks": 1,
      "code": 9,
      "comments": 0,
      "lines": 10,
      "name": "src/p_flatten.js"
    },
    {
      "blanks": 3,
      "code": 13,
      "comments": 1,
      "lines": 16,
      "name": "src/most_polyfill.js"
    },
    {
      "blanks": 13,
      "code": 44,
      "comments": 1,
      "lines": 58,
      "name": "src/freyr.js"
    },
    {
      "blanks": 5,
      "code": 27,
      "comments": 0,
      "lines": 31,
      "name": "src/filter_parser.js"
    },
    {
      "blanks": 8,
      "code": 73,
      "comments": 0,
      "lines": 81,
      "name": "src/file_mgr.js"
    },
    {
      "blanks": 10,
      "code": 92,
      "comments": 0,
      "lines": 102,
      "name": "src/cli_server.js"
    },
    {
      "blanks": 16,
      "code": 83,
      "comments": 92,
      "lines": 191,
      "name": "src/async_queue.js"
    },
    {
      "blanks": 35,
      "code": 375,
      "comments": 56,
      "lines": 466,
      "name": "src/services/youtube.js"
    },
    {
      "blanks": 35,
      "code": 297,
      "comments": 2,
      "lines": 334,
      "name": "src/services/spotify.js"
    },
    {
      "blanks": 47,
      "code": 270,
      "comments": 2,
      "lines": 319,
      "name": "src/services/deezer.js"
    },
    {
      "blanks": 30,
      "code": 263,
      "comments": 4,
      "lines": 297,
      "name": "src/services/apple_music.js"
    },
    {
      "blanks": 0,
      "code": 91,
      "comments": 0,
      "lines": 91,
      "name": "package.json"
    },
    {
      "blanks": 0,
      "code": 56,
      "comments": 0,
      "lines": 56,
      "name": "conf.json"
    },
    {
      "blanks": 0,
      "code": 1061,
      "comments": 0,
      "lines": 1061,
      "name": "README.md"
    }
  ],
  "inaccurate": false
}
martianyi commented 3 years ago

Excellent, I will add tokei support recently

miraclx commented 3 years ago

In the meantime, I've put together a user script to do precisely that

View on GitHub Install on Greasy Fork

Screenshot_20210208_055932

EDIT: just so it's clear, the badges are clickable

miraclx commented 3 years ago

Here's what these two look like side by side, as you can see, github-sloc is really off

Screenshot_20210208_065646

martianyi commented 3 years ago

Excellent work, I was too busy, can you make a PR, I'll merge it and publish to chrome webstore

miraclx commented 3 years ago

Yeah, I thought about opening a PR before making the user script but that pretty much did the job and I don't really have a lot of time on my hands so I just settled for that. Feel free to close this issue though unresolved or perhaps label it as a good first issue for potential contributors.