crate-ci / typos

Source code spell checker
Apache License 2.0
2.52k stars 96 forks source link

RFE: extend-glob for files in specific paths #725

Open scop opened 1 year ago

scop commented 1 year ago

It seems currently extend-glob does not work if given a path rather than a file basename.

For example, in https://github.com/scop/bash-completion I would like to specify that all files (well except for Makefile*) in the completions/ subdir are shell files, but I'm failing to accomplish that:

$ grep -A 1 -F type.sh .typos.toml
[type.sh]
extend-glob = ["bash_completion", "completions/*"]
$ typos --file-types | grep -F completions/ | head -n 1
./completions/cancel:-
Broken pipe (os error 32)

(Curious that Broken pipe error BTW, but I digress.)

epage commented 1 year ago

In theory, this would be a relatively easy change

I'm just not too sure about the idea of relying on a directory to know what a file type is. Wouldn't #726 better fit the cases?

scop commented 1 year ago

726 would likely fit the bill, depending on the implementation, and be a cleaner solution overall. But there are a number of concerns already raised over there; this one's much simpler.

Regarding the concern about relying on a dir to know a file's type, the glob in the example might lead thoughts that way. But if we use a specific file (including its path) rather than a glob as the example, wouldn't it make perfect sense to be able to label a specific file as some type when we know that's the case, instead of having to label all files that might have the same basename and for which the type would be incorrect?

scootermon commented 4 months ago

I just ran into this limitation as well. I have multiple directories containing test related files (mostly .csv and .log files) which get picked up by typos. They contain "spelling errors", but these are essentially false-positives as the files don't contain text and "fixing" them also isn't possible because it would mean changing the test data. These directories always match the path tests/data/ so I was hoping to just exclude them, but as I know now that doesn't work :)

I was especially confused because the documentation mentions "gitignore syntax":

https://github.com/crate-ci/typos/blob/27ba9761d15d0f85acd8d0b500ac227e414d084d/docs/reference.md?plain=1#L20

Looking at the implementation it's really only a small subset of gitignore's capabilities. I'm not saying that it should support full gitignore syntax, I'm just wondering whether this part of the documentation should be changed.

Would you accept this feature as a contribution or do you think it should be solved differently? In this case, #726 wouldn't help either.

epage commented 3 months ago

@scootermon this issue is about extend-glob while extend-exclude is a lot more flexible.

Could you start a separate Discussion or Issue with a reproduction case?