JohnnyMorganz/StyLua

Glob matching ignores ignore list

alerque opened this issue · 3 comments

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.

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

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

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