sloc icon indicating copy to clipboard operation
sloc copied to clipboard

limiting to a single file type.

Open ceelian opened this issue 9 years ago • 7 comments

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.

ceelian avatar Dec 02 '15 10:12 ceelian

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.

mindplay-dk avatar Feb 01 '16 09:02 mindplay-dk

Isn't there a library that we can use? Something like minimatch ?

flosse avatar Feb 04 '16 22:02 flosse

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?

bwin avatar Feb 05 '16 00:02 bwin

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

bwin avatar Feb 05 '16 00:02 bwin

Looks like this will do multiple include and exclude:

https://github.com/mklabs/node-fileset

mindplay-dk avatar Feb 08 '16 06:02 mindplay-dk

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.

shyambhiogade avatar Feb 05 '17 15:02 shyambhiogade

I got this to work... npx sloc --format cli-table --format-option head --exclude "node_modules|build|\.svg$\.xml" ./

listenlight avatar Sep 27 '18 12:09 listenlight