JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.48k stars 65 forks source link

Glob matching ignores ignore list #869

Open alerque opened 2 weeks ago

alerque commented 2 weeks ago

If I add a file test.lua to my .styluaignore, it will correctly get ignored in both of these usages:

$ stylua --respect-ignores test.sua
$ ls *.lua | xargs stylua --respect-ignores

Unfortunately it does not get ignored if matched in a glob pattern:

$ stylua --respect-ignores -g '*.lua' .

I would have expected that scenario to skip the file as well, but it does not. In my case this causes problems in several projects and I have to manually generate lists of files with other tooling and pass them as arguments instead of being able to use glob patterns.

JohnnyMorganz commented 1 week ago

I can't seem to repro this on latest main if I understood correctly: image

JohnnyMorganz commented 1 week ago

I, in fact, did not understand correctly. Can repro when not explicitly listing the filepath i.e. stylua --respect-ignores -g '*.lua' .

It seems like the ignore (walkerbuilder) crate might be making explicit globs take precedence over ignore files. That would be unfortunate

JohnnyMorganz commented 1 week ago

Indeed that seems to be the case: https://docs.rs/ignore/latest/ignore/struct.WalkBuilder.html

First, glob overrides are checked. If a path matches a glob override, then matching stops. The path is then only skipped if the glob that matched the path is an ignore glob. (An override glob is a whitelist glob unless it starts with a !, in which case it is an ignore glob.)

We should probably not use the glob support in walkerbuilder and do our own matching instead