crate-ci / typos

Source code spell checker
Apache License 2.0
2.57k stars 101 forks source link

[Q] Can't match `git diff` output #1118

Open zaufi opened 1 day ago

zaufi commented 1 day ago

I want to exclude some lines from Git commit message files (see #1117) and have this in my .typos.toml for now:

[default]
extend-ignore-re = [ "(?Rm)^index [0-9a-f]{9}\\.\\.[0-9a-f]{9} [0-9]+$" ]

However, the COMMIT_EDITMSG like this does not match and causes an error:

test: `typos` exclude check
# NOTE: Leave the next line empty to separate the title from the body

# Explain why this change is being made below... (max 120 chars per line)
Playing w/ `extend-ignore-re`

#---[The diff inserted by Git is shown below]-------------------------
…
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/tests/010-simple-secret.sh b/tests/010-simple-secret.sh
index 7f5ba185f..0ebe349ef 100644
--- a/tests/010-simple-secret.sh
+++ b/tests/010-simple-secret.sh
…

result in the error:

error: `ba` should be `by`, `be`
  --> path/to/my/repo/.git/worktrees/my-work-tree/COMMIT_EDITMSG:12:10
   |
12 | index 7f5ba185f..0ebe349ef 100644
   |          ^^

It doesn't match even if I reduce regex to the trivial as ^index .*$!

Please help…

epage commented 1 day ago

I put that config in a directory with that block of text in a file and typos succeeded. To test my setup, I removed the config and it failed.

The only thin I can think of is that typos isn't finding the config. If you could run typos with -vvv that might provide some things.

We determine where to load the config based on the file or directory path passed to typos https://github.com/crate-ci/typos/blob/6802cc60d4e7f78b9d5454f6cf3935c042d5e1e3/crates/typos-cli/src/bin/typos-cli/main.rs#L192-L221