Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclude path feature #70

Closed
wants to merge 1 commit into from
Closed

Conversation

Shikugawa
Copy link

This PR introduces to skip check while filePath walk.

@laurentsimon
Copy link

@mco-gh @TomerAberbach do you have cycles to review this PR?
We need support for this for Google's scorecard project. How can we be unblocked?

@laurentsimon
Copy link

@dlorenc whom shall we talk to have this PR reviewed/merged?

@mco-gh
Copy link
Contributor

mco-gh commented Jul 28, 2021 via email

@@ -52,6 +52,7 @@ var (
license = flag.String("l", "apache", "license type: apache, bsd, mit, mpl")
licensef = flag.String("f", "", "license file")
year = flag.String("y", fmt.Sprint(time.Now().Year()), "copyright year(s)")
exclude = flag.String("e", "", "Files which exclude from check")
Copy link
Contributor

Choose a reason for hiding this comment

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

"Files to exclude from check" seems more accurate


func (e *ExcludePath) Contains(path string) bool {
for _, p := range e.paths {
if p == path {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work if someone specifies a relative path, e.g. /foo/bar, ./foo, ../foo/bar?
Perhaps you should canonicalize both strings to a full path to ensure you catch all those cases.


cmd := exec.Command(os.Args[0],
"-test.run=TestExcludePath",
"-y", "2018", "-e", origin1, origin1, origin2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Two questions: 1) this is excluding a file. Isn't the more likely use case to exclude an entire dir tree? If so, could you add a test for that case? 2) Is the two appearances of origin1 a mistake or because you want to verify the logic handles duplicate paths?

Copy link
Author

@Shikugawa Shikugawa Jul 28, 2021

Choose a reason for hiding this comment

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

  1. In this implementation, I expect that only to accept filename. for example in current implementation, we get /foo/bar, /foo/bar/baz.txt after filepath walk and configured /foo/bar as exclude path then /foo/bar/baz.txt won't be ignored.
  2. It also includes dup path test.

Copy link

@laurentsimon laurentsimon Jul 28, 2021

Choose a reason for hiding this comment

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

I think it'd be beneficial to support directories: the main use case (and ours!) is dev teams removing test folders from the path. Test folders have a number of files that change over time, so it's cumbersome to update the command every time a new file is added.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree - I think dirs is likely to be a far more valuable use case than enumerating individual files. If you do a prefix match then you get both, dirs and files, with a one line change.

@mco-gh
Copy link
Contributor

mco-gh commented Jul 28, 2021 via email

@willnorris
Copy link
Collaborator

gah, I did it again! I started working on a feature before realizing there is another PR in flight. Well in any event, it may be worth a look, since I ended up taking a bit more of a flexible option by using https://github.com/bmatcuk/doublestar. This allows us to deprecate the existing -skip which is pretty limited in only supporting file extensions.

You can see the implementation here, and the test cases give a pretty clear example of what kinds of patterns would be possible: willnorris@6ac0919. This implementation may still suffer from the relative vs absolute path issue discussed here. I haven't looked closely enough yet to see if you all settled on a solution to that yet.

@mco-gh
Copy link
Contributor

mco-gh commented Jul 29, 2021 via email

@willnorris
Copy link
Collaborator

willnorris commented Jul 29, 2021

It's also worth noting, and I only realized it later, that doublestar requires go1.16 because it's using the io/fs package. In #81, I have it testing against the last two minor releases, which would include 1.15. That's what we do for google/go-github, and what the Go project itself supports. Go typically releases at the end of July, so go1.17 should drop any day now. In that case, we might wait until go1.17 releases before adding in doublestar, if that's the approach you'd like to go with. Then we can continue to support the last two minor releases.

@mco-gh
Copy link
Contributor

mco-gh commented Jul 29, 2021 via email

@willnorris
Copy link
Collaborator

alternate implementation of this feature was added in #84

@willnorris willnorris closed this Aug 9, 2021
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.

4 participants