Coder Social home page Coder Social logo

How to exclude subdir about cloc HOT 10 CLOSED

aldanial avatar aldanial commented on July 17, 2024 2
How to exclude subdir

from cloc.

Comments (10)

jolkdarr avatar jolkdarr commented on July 17, 2024 5

cloc should deny invocations with option --excludir-dir containing separators like src/test because the user might think the directory has been successfully filtered.

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024 3

OK, so maybe the solution was easy after all. Internally, the problem came down to --not-match-d only examining the last directory in the path, ie, for /usr/local/lib, cloc would only test --not-match-d's regex against lib. Git commit 242c795 expands the --fullpath switch so that it also updates --not-match-d's behavior to consider the full path.

With the new code you should be able to achieve what you're after. Here's an example session:

mkdir -p test/foo/bar/lala test/bar/foo/momo
echo "echo hi"    > test/foo/bar/lala/tfbl.sh
echo "echo hello" > test/bar/foo/momo/tbfm.sh
# run 1: count everything
cloc --by-file test
       2 text files.
       2 unique files.                              
       0 files ignored.
github.com/AlDanial/cloc v 1.67  T=0.01 s (140.6 files/s, 140.6 lines/s)
---------------------------------------------------------------------------------------
File                                     blank        comment           code
---------------------------------------------------------------------------------------
test/bar/foo/momo/tbfm.sh                    0              0              1
test/foo/bar/lala/tfbl.sh                    0              0              1
---------------------------------------------------------------------------------------
SUM:                                         0              0              2
---------------------------------------------------------------------------------------
# run 2: only exclude test/bar/* but not test/foo/bar/
cloc --by-file --fullpath --not-match-d test/bar test
       1 text file.
       1 unique file.                              
       1 file ignored.
github.com/AlDanial/cloc v 1.67  T=0.01 s (89.8 files/s, 89.8 lines/s)
---------------------------------------------------------------------------------------
File                                     blank        comment           code
---------------------------------------------------------------------------------------
test/foo/bar/lala/tfbl.sh                    0              0              1
---------------------------------------------------------------------------------------
# run 3: only exclude test/foo/bar but not test/bar/
cloc --by-file --fullpath --not-match-d test/foo/bar test
       1 text file.
       1 unique file.                              
       1 file ignored.
github.com/AlDanial/cloc v 1.67  T=0.01 s (80.6 files/s, 80.6 lines/s)
---------------------------------------------------------------------------------------
File                                     blank        comment           code
---------------------------------------------------------------------------------------
test/bar/foo/momo/tbfm.sh                    0              0              1
---------------------------------------------------------------------------------------

One last thing remains before I can close this out: give the same treatment to --exclude-dir.

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024

See the section "Filter Options" at https://github.com/AlDanial/cloc#options

from cloc.

luanjampa avatar luanjampa commented on July 17, 2024

@AlDanial works when used --exclude-dir=test
But if try --excludir-dir=src/test not works :\

another question, if exist another directory called 'test', exemple:
spec/test.
When I execute cloc with "--exclude-dir=test " both directory(src/test,spec/test) are excluded?

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024

If you say --exclude-dir=test then both src/test and spec/test are excluded.

There isn't (yet) a way to prune directories based on anything except the last directory name in a path.

from cloc.

luanjampa avatar luanjampa commented on July 17, 2024

thanks for answer @AlDanial, and I think this would be a great feature.

indeed @jolkdarr

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024

Good idea @jolkdarr. I'll add a warning if --exclude-dir and --not-match-d contain separators.

from cloc.

IncludeSec avatar IncludeSec commented on July 17, 2024

Any chance of getting exclude dir or another option for excluding a path. For instance if I have a dir name test/foo/bar/lala and test/bar/foo/momo I want to only exclude test/bar/* but NOT test/foo/bar/

I don't think there is a way to do that currently in cloc short of xargs/find magic feeding a file list into cloc.

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024

Yes, this is definitely on my to-do plan.

I actually took a shot at implementing the solution--I figured it would be a piece of cake--but it was a bit more involved than I first thought. Until last week my focus was getting v1.66 checked out solidly enough to release. Now that it is out I will turn my attention back to the harder problems.

from cloc.

AlDanial avatar AlDanial commented on July 17, 2024

Actually, --exclude-dir serves a slightly different purpose. I left its behavior alone and implemented @jolkdarr's suggestion to prohibit path separators in --exclude-dir.

from cloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.