Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excludes are relative to current directory, not typos.toml location #593

Open
embe-pw opened this issue Oct 13, 2022 · 3 comments
Open

excludes are relative to current directory, not typos.toml location #593

embe-pw opened this issue Oct 13, 2022 · 3 comments
Labels
bug Not as expected

Comments

@embe-pw
Copy link

embe-pw commented Oct 13, 2022

When $DIR/typos.toml contains

[files]
extend-exclude = ["a/*.txt"]

and we run typos in $DIR, the file a/test.txt is correctly excluded. But when typos is run in $DIR/a, the exclude is not respected:

$ cat typos.toml
[files]
extend-exclude = ["a/*.txt"]
$ typos
$ (cd a; typos)
error: `tpyo` should be `typo`
  --> ./test.txt:1:1
  |
1 | tpyo
  | ^^^^
  |

When typos.toml excludes *.txt both cases work, so the issue is not caused by ignoring the configuration in the parent directory:

$ cat typos.toml
[files]
extend-exclude = ["*.txt"]
$ typos
$ (cd a; typos)

It would make sense to interpret the excludes relative to the typos.toml location.

(tested with typos 1.12.8 binary from the GitHub release)

@epage epage added the bug Not as expected label Oct 13, 2022
@epage
Copy link
Collaborator

epage commented Oct 23, 2023

If resolving this, a question would be what to do for --config. See #861 where using the parent directory of the config wouldn't be correct. Maybe we use the parent directory of the auto-discovered config only and make --config relative to that?

@brandonkal
Copy link

brandonkal commented Aug 10, 2024

It seems the toml file it is ignored if I call the file directly.
I find that typos often has false positives with SOPS files, for example within the BEGIN AGE ENCRYPTED FILE block.
Ideally, typos would recognize and ignore sops files, as most content is encrypted. That is easy to detect.
But for now I created a typos.toml in the root of the repository.

[files]
extend-exclude = ["*.sops.*"]

If I run typos I get no output but if I call the file directly:

❯ typos nomad/secrets.sops.yaml 
error: `Ba` should be `By`, `Be`
  --> nomad/secrets.sops.yaml:18:24
   |
18 |         NndQOEpqVWNyK1JBa2xTbjlHRmdXalpEVlhvCmVpNTdDRWZlN1ZRcUZmSkV6SjYy
   |                        ^^
   |

Which is unexpected because the config file exists. My lefthook pre-commit has typos {staged_files}

Further, it seems to me typos should understand that the word "Ba" was found in a long string with high entropy, so it should not flag this as an error ever.

@brandonkal
Copy link

Even calling typos --config typos.toml nomad/secrets.sops.yaml returns the same error. Which is its own bug. So there is no way to configure typos here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not as expected
Projects
None yet
Development

No branches or pull requests

3 participants