typos icon indicating copy to clipboard operation
typos copied to clipboard

RFE: extend-glob for files in specific paths

Open scop opened this issue 2 years ago • 4 comments

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.)

scop avatar May 21 '23 11:05 scop

In theory, this would be a relatively easy change

  • Create a path relative to the config dir to pass down: https://github.com/crate-ci/typos/blob/master/crates/typos-cli/src/policy.rs#L96
  • Stop grabbing only the extension: https://github.com/crate-ci/typos/blob/master/crates/typos-cli/src/file_type.rs#L110

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?

epage avatar May 22 '23 17:05 epage

#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?

scop avatar May 22 '23 19:05 scop

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.

scootermon avatar May 15 '24 18:05 scootermon

@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?

epage avatar Jun 06 '24 21:06 epage