flosse / sloc

simple tool to count SLOC (source lines of code)
MIT License
943 stars 84 forks source link

SLOC: make it work on directories #143

Closed domengasperlin closed 6 months ago

domengasperlin commented 6 months ago

Updated readdirp compatibility

Problem

The current version of readdirp in the codebase is 3.3.0. However, due to a series of breaking changes readdirp introduced during the transition from version 2.x to 3.x, current implementation does not function as expected when running on directories. However it still works when running on single files. In this PR i aim to restored the functionality.

Example:

sloc cli.js ../lib
/Users/domen/.nvm/versions/node/v20.10.0/lib/node_modules/sloc/node_modules/readdirp/index.js:264
    throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
    ^

TypeError: readdirp: root argument must be a string. Usage: readdirp(root, options)
    at readdirp (/Users/domen/.nvm/versions/node/v20.10.0/lib/node_modules/sloc/node_modules/readdirp/index.js:264:11)
    at readDir (/Users/domen/.nvm/versions/node/v20.10.0/lib/node_modules/sloc/lib/cli.js:176:12)
    at /Users/domen/.nvm/versions/node/v20.10.0/lib/node_modules/sloc/lib/cli.js:194:16
    at FSReqCallback.oncomplete (node:fs:200:5)

Solution

In response to this issue, the code has been adapted to ensure compatibility with readdirp version 3.x. The changes align with the specifications outlined in the readdirp changelog.

✅ tests 80 passing (55ms)

✅ linter

image

✅ built and ran the generated cli to verify it now works as expected in comparison to not working before.

image image image
flosse commented 6 months ago

Thank you!!

chenrui333 commented 6 months ago

still saying the same issue in https://github.com/Homebrew/homebrew-core/pull/158728

==> /opt/homebrew/Cellar/sloc/0.3.1/bin/sloc --format=csv .
/opt/homebrew/Library/Homebrew/ignorable.rb:29:in `block in raise'
Minitest::Assertion: --- expected
+++ actual
@@ -1,3 +1,18 @@
-"Path,Physical,Source,Comment,Single-line comment,Block comment,Mixed,Empty block comment,Empty,To Do
-Total,4,4,0,0,0,0,0,0,0
+"
+---------- Result ------------
+
+            Physical :  4
+              Source :  4
+             Comment :  0
+ Single-line comment :  0
+       Block comment :  0
+               Mixed :  0
+ Empty block comment :  0
+               Empty :  0
+               To Do :  0
+
+Number of files read :  1
+
+----------------------------
+
 "