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

Tweak --ignore-regex to ignore consecutive matches #2049

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

peterjc
Copy link
Contributor

@peterjc peterjc commented Aug 30, 2021

Consider this example for ignoring 2 or 3 letter upper case words (typical of acronyms):

codespell --ignore-regex '\W([A-Z]{2,3})\W'

If there are two consecutive matches in a string like "text TE OTU text" only one gets removed - the problem is the space needs to be used twice, the end of TE and the start of OTU as the second but overlapping regex match.

Cross reference #1578.

Copy link
Collaborator

@peternewman peternewman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense thanks @peterjc .

Please can you add some tests for it so we won't regress in future (even if we change to a different workaround).

@peterjc
Copy link
Contributor Author

peterjc commented Sep 14, 2021

I wasn't sure if this change was in the spirit of the original regex implementation, but since you like the idea, I agree a test or two is a good idea.

@peterjc
Copy link
Contributor Author

peterjc commented Sep 14, 2021

I've tested this locally now:

$ codespell flag.txt 
flag.txt:1: TE ==> THE, BE, WE, TO
flag.txt:1: OTU ==> OUT
$ codespell --ignore-regex '\W([A-Z]{2,3})\W' flag.txt 
$ codespell --ignore-regex "\W([A-Z]{2,3})\W" flag.txt 
$ codespell --ignore-regex="\W([A-Z]{2,3})\W" flag.txt 
$ codespell --ignore-regex='\W([A-Z]{2,3})\W' flag.txt 
$ codespell --ignore-regex \W([A-Z]{2,3})\W flag.txt 
-bash: syntax error near unexpected token `('
$ codespell --ignore-regex=\W([A-Z]{2,3})\W flag.txt 
-bash: syntax error near unexpected token `('

Looks like the protective quotes are being lost somewhere in the test framework...

Consider this example for 2 or 3 letter upper case words
(typical of acronyms):

```
codespell --ignore-regex '\W([A-Z]{2,3})\W'
```

If there are two consecutive matches in a string like
"text TE OTU text" only one gets removed - the problem
is the space needs to be used twice, the end of `` TE ``
and the start of `` OTU `` as the second but overlapping
regex match.
@peterjc
Copy link
Contributor Author

peterjc commented Sep 14, 2021

Solved, rather than doing what works at the command line, I needed to match what Python receives from the command line.

Also rebased for a clearer history.

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

Successfully merging this pull request may close these issues.

2 participants