sloc
sloc copied to clipboard
limiting to a single file type.
Is there any working solution to limit analysis to a single file extension? I tried using the -e (--exclude) switch to limit e.g. to JavaScript files. The idea is to exclude all files which are not javascript files.
sloc -e ".+^(\.js)$" -d .
But it is not working.
Yeah, I was looking for something like this as well - most projects have a primary language, and typically, you want the line count for that language.
We have the --exclude
option for blacklisting files matching a given pattern - may I suggest a complementary --include
option for whitelisting?
Since both options could be used together, I'd suggest running the whitelist filter first (if present) then running the blacklist filter on the remaining files.
Isn't there a library that we can use? Something like minimatch ?
Or node-glob. Minimatch
is the just the matcher, while glob
operates on the filesystem and returns actual filenames instead of regexes. It uses minimatch
internally.
Maybe the readDir
part in cli.coffee
could be simplified by using glob
?
glob = require 'glob'
pattern = "**"
options =
ignore: ["**/*.json", "node_modules/**"]
nodir: yes # only files
glob pattern, options, (err, matches) -> console.log matches
This returns all filenames that match pattern
, filtered by ignore
. Supports ~~only one pattern, but~~ multiple ignore-patterns.
Edit: Multiple patterns are possible with a workaround: glob('{' + pattern1 + ',' + pattern2 + '}', cb)
from isaacs/node-glob#217
Looks like this will do multiple include and exclude:
https://github.com/mklabs/node-fileset
one cheap solution to keep it for single file type. run sloc two times. first on all files and after that on all files except the one you wanted and then you can use powershell to minus the second result from first to get the result for single file type.
I got this to work... npx sloc --format cli-table --format-option head --exclude "node_modules|build|\.svg$\.xml" ./