Content-Length: 417710 | pFad | https://github.com/cpplint/cpplint/pull/115

ad Fix recursive exclude Issue #114 by GrueMaster · Pull Request #115 · cpplint/cpplint · GitHub
Skip to content

Fix recursive exclude Issue #114 - #115

Merged
aaronliu0130 merged 2 commits into
cpplint:masterfrom
GrueMaster:master
Feb 2, 2024
Merged

Fix recursive exclude Issue #114#115
aaronliu0130 merged 2 commits into
cpplint:masterfrom
GrueMaster:master

Conversation

@GrueMaster

Copy link
Copy Markdown
Contributor

I fixed the --exclude issue and added a new testcase for cpplint_clitest.py. Tested, works.

@tkruse

tkruse commented Dec 8, 2019

Copy link
Copy Markdown
Contributor

Thanks for this PR. Sorry about #96, I just was not active merging open PRs since then.

Comment thread cpplint.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs a lot more explaining. The elements of _excludes are already globbed, so "foo/*" would become a list of files in folder foo. I assume what you are trying to achieve is a recursive globbing, as commonly requested here https://stackoverflow.com/questions/2186525. As in the answers there, it seems the current code would already to the right thing starting with python3.5 and an exclude like --exclude="third_party/**/*" (I have not tried it). Even if that did not work, the correct approach here would likely be to either fix the globbing, or to use a robust path/subpath identification (not string.startswith)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the answers there, it seems the current code would already to the right thing starting with python3.5 and an exclude like --exclude="third_party/**/*" (I have not tried it).

I did try it, multiple ways. It doesn't work. Hence the fix. The idea here is to exclude an entire subdirectory, not each individual file within that subdirectory.

Here is a simple test that you can run on the current tree:
./cpplint.py --recursive --exclude='sample/boost-sample/**/*' samples 2>&1 |fgrep boost-sample

If it returns output , your code is broken. I tested it on both python 3.5.2 (Ubuntu 16.04 LTS) and python 3.6.9 (Ubuntu 18.04 LTS).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, in that case something safer than string startswith would be acceptable. If the user excludes folder /foo, we should not exclude folder /foobar.

In another project I used this snippet:

def _is_parent_path(parent, child):
    """Return true if child is subdirectory of parent.
    Assumes both paths are absolute and don't contain symlinks.
    """
    parent = os.path.normpath(parent)
    child = os.path.normpath(child)

    prefix = os.path.commonprefix([parent, child])

    if prefix == parent:
        # Note: os.path.commonprefix operates on character basis, so
        # take extra care of situations like '/foo/ba' and '/foo/bar/baz'

        child_suffix = child[len(prefix):]
        child_suffix = child_suffix.lstrip(os.sep)

        if child == os.path.join(prefix, child_suffix):
            return True

    return False

@GrueMaster GrueMaster Dec 9, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done more testing by copying boost-sample to boost-sample2 (to simulate foobar vs foobaz). If I run:
./cpplint.py --recursive --exclude='samples/boost-sample' samples 2>&1 |fgrep boost
it excludes both. But, if I run:
./cpplint.py --recursive --exclude='samples/boost-sample/*' samples 2>&1 |fgrep boost
It only excludes boost-sample, not boost-sample2.
I also tried with --exclude='boost-sample', in which case both paths were included. So it really is up to the user to properly terminate the exclude string.

For your example, '--exclude=/foo' would in fact get /foo, /foobar. /foobaz, etc. but if they type '--exclude=/foo/*' it would not exclude /foobar or /foobaz.

@GrueMaster

Copy link
Copy Markdown
Contributor Author

Updated to fix merge conflicts.

@GrueMaster GrueMaster changed the title Fix #114 and include PR#96 Fix #114 Dec 11, 2019
@GrueMaster GrueMaster changed the title Fix #114 Fix Issue #114 Dec 11, 2019
@tkruse

tkruse commented Dec 14, 2019

Copy link
Copy Markdown
Contributor

Do you see any issue with merging #124 instead? I can see that with your simple solution, the foo/foobar problem can be worked around, but I would prefer no workaround to be necessary for backward compatible behavior.

@tkruse tkruse changed the title Fix Issue #114 Fix recursive exclude Issue #114 Jan 13, 2020
@aaronliu0130
aaronliu0130 merged commit 141ebb7 into cpplint:master Feb 2, 2024
@aaronliu0130

Copy link
Copy Markdown
Member

Aaah, wrong branch!
Hopefully cherry picking has no issues

aaronliu0130 pushed a commit that referenced this pull request Feb 2, 2024
aaronliu0130 added a commit that referenced this pull request Feb 2, 2024
aaronliu0130 added a commit that referenced this pull request Feb 2, 2024
already implemented, all it does is change a test file now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/cpplint/cpplint/pull/115

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy