air icon indicating copy to clipboard operation
air copied to clipboard

Idea: Glob-based include/exclude configuration

Open silverwind opened this issue 1 year ago • 9 comments

Air currently supports 6 config options to include/exclude files:

include_ext = ["go", "tpl", "tmpl", "html"]
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
include_dir = []
include_file = []
exclude_file = []
exclude_regex = ["_test\\.go"]

I think from a user perspective, these options are hard to understand and I suggest to additionally support a glob-based configuration with include and exclude options. exclude should take precedence. Above could be rewritten as:

include = [
  "**/*.{go,tpl,tmpl,html}",
]
exclude = [
  "./{assets,tmp,vendor}",
  "./frontend/node_modules",
  "**/*_test.go",
]

silverwind avatar Dec 09 '24 17:12 silverwind

Currently, I'm considering this feature because the current air options are a little bit confusing to the users

xiantang avatar Nov 16 '25 08:11 xiantang

If you are willing to do a breaking change (v2), I'd suggest making the glob-based include and exclude options the only options and remove all the others.

silverwind avatar Nov 18 '25 20:11 silverwind

Yes, I plan to keep other options until the next v2 breaking change

xiantang avatar Nov 19 '25 03:11 xiantang

I want to know if the glob-based configuration can unify different OS configurations. I don't want users to have to consider OS differences.

xiantang avatar Nov 20 '25 14:11 xiantang

Make the patterns accept forward slashes only and when on Windows, replace foward with backward slashes. That's how pretty much all glob implementations that I know work.

I'm not sure which package is the premier glob package nowadays in golang, it was https://github.com/gobwas/glob at one point, but that one seems to have gone out of maintenance.

silverwind avatar Nov 20 '25 16:11 silverwind

Yes, we need to find a reliable package in Go.

xiantang avatar Nov 24 '25 03:11 xiantang

gobwas/glob is definitely not right, it's a pattern matching library, not a file system glob library. I just noticed how misnamed it actually is.

I think stdlib https://pkg.go.dev/path/filepath#Glob might be good. The only thing that seems to be missing (compared to other implementations) is to specify exclude patterns, so exclusion patterns need to be applied in a post-processing step, which will hurt theoretical performance.

silverwind avatar Nov 24 '25 14:11 silverwind

You might also consider the https://github.com/bmatcuk/doublestar. It supports a range of extended globbing patterns, including exclusion rules, recursive directory matching, and more. It’s also used in arelo, so it has some proven usage in similar tools.

makiuchi-d avatar Nov 24 '25 16:11 makiuchi-d

Let me try https://github.com/bmatcuk/doublestar and https://pkg.go.dev/path/filepath#Glob. By the way, please do not advertise in the issue. If I reference your code, I will include your repository in the README credit section.

xiantang avatar Nov 25 '25 02:11 xiantang