这是indexloc提供的服务,不要输入任何密码
Skip to content

Implement globby.GlobFiles using doublestar.GlobWalk #1108

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

Merged
merged 6 commits into from
Apr 27, 2022

Conversation

nathanhammond
Copy link
Contributor

@nathanhammond nathanhammond commented Apr 25, 2022

This change aims to improve the performance of our file walking by only walking the portions of the directory that we care about. In this iteration it aims to be 100% backwards compatible with the previous implementation, excepting one obvious bug, resulting in a boolean change to the tests.

It also adopts a set instead of a range for storage as doublestar will happily walk a directory multiple times if you feed it a nonsensical glob pattern such as **/**/**.

@vercel
Copy link

vercel bot commented Apr 25, 2022

@nathanhammond is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Apr 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
turbo-site ✅ Ready (Inspect) Visit Preview Apr 27, 2022 at 7:03PM (UTC)

This change aims to improve the performance of our file walking by only walking the portions of the directory that we care about. In this iteration it aims to be 100% backwards compatible with the previous implementation, excepting one obvious bug, resulting in a boolean change to the tests.

It also adopts a set instead of a range for storage as doublestar will happily walk a directory multiple times if you feed it a nonsensical glob pattern such as `**/**/**/*.*`.
@nathanhammond nathanhammond force-pushed the globby-globwalk branch 2 times, most recently from 1c60a02 to a199d1d Compare April 27, 2022 04:31
}

// isRelativePath ensures that the the requested file path is a child of `from`.
func isRelativePath(from string, to string) (isRelative bool, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is somewhat a judgment call and I didn't find anything explicitly in the style guide, so push back if you disagree (also not really a blocker):

The community has a range of opinions on named return values, and their sometimes-companion, the naked return[0][1]. I think it's unfortunate that the documentation aspects incur the downsides that enable naked return. As a result, my preference is to avoid named return values altogether, as I think they tend to end up less readable and subject to unintentional shadowing.

I did find a linter, nakedret that catches half of this problem, and I would be happy to enable if you're on board.

In this particular case, I can see the intention to label a bool return value. My opinion is that the function name and associated comment is sufficient, but therein lies the judgment call. I also think you have shadowed err via := assignment, which works out in this case, but may not have been your intention(?).

Sample of opinions:
0 : https://dave.cheney.net/practical-go/presentations/gophercon-israel.html#_avoid_named_return_values
1 : golang/go#21291

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ... did not fully understand how that worked when I wrote it. 😅 I was treating it as a "typed tuple" for the return values with "naming hints" without needing to go so far as actually creating a struct.

Name Hints

I believe naked returns in a function with any branching is not a particularly great idea and prefer explicit over implicit. I'd love to enable nakedret with l set to something silly like 3. ("If you can fit a naked return in a function this size, you know what, have at it.")

I also found shadow which might help me not shoot my foot off:

go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
go vet -vettool=$(which shadow) globby.go # 0 right now

Thoughts on somehow enabling that as a linter?


I'm going to move this away from named return values, I agree that it's really easy to accidentally stumble into a minefield with this approach.

@kodiakhq kodiakhq bot merged commit 8864753 into vercel:main Apr 27, 2022
@nathanhammond nathanhammond deleted the globby-globwalk branch April 28, 2022 02:41
kodiakhq bot pushed a commit that referenced this pull request Apr 28, 2022
This PR is a fast-follow to #1108 to plumb through the error cases. This work is intentionally split to reduce the scope for each change (1. change implementation, 2. change interface).

This results in user-facing changes if they have globs or patterns that push them outside of their root directory.
@gsoltis gsoltis mentioned this pull request May 3, 2022
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.

2 participants