crate-ci / typos

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

--extend-exclude doesn't work with absolute paths #1075

Open ember91 opened 1 month ago

ember91 commented 1 month ago

I hope this hasn't been reported before.

typos version: 1.23.6

/some/path/some_misspellings.txt is a file with errors which typos in its default configuration would detect.

/some/path/_typos.toml has the contents:

[files]
extend-exclude = [
    '/some_misspellings.txt'
]

This works as expected, i.e. no errors are reported:

cd /some/path/
typos --force-exclude some_misspellings.txt

Although this reports spelling errors:

cd /some/path/
typos --force-exclude /some/path/some_misspellings.txt

I assumed that they would lead to the same result.

epage commented 1 month ago

extend-exclude makes paths relative to a "base directory", using gitignore syntax. So /some_misspellings.txt says that some_misspellings.txt should only be excluded if its in the root directory.

So the question is what is the root in this case. From a quick glance, it looks like its ".". It should probably be the parent directory of the config file. We are tracking this in #593.

Whatever the root is, we should make sure that a passed in path is checked against the root, regardless of format.

ember91 commented 1 month ago

Just to lessen any confusion: Removing the initial slash from extend-exclude leads to the same behavior as with a slash.

epage commented 1 month ago

Now, that is surprising.