Uh oh!
There was an error while loading. Please reload this page.
Add support for ignoring spelling mistakes in URIs specifically. - #1656
Conversation
peternewman
commented
Sep 4, 2020
I suspect we should potentially leave discussion of the regex itself to a separate PR to avoid potentially derailing this one, but here is something interesting to look at/test: |
| for uri_word in extract_words(uri, word_regex, | ||
| ignore_word_regex): | ||
| if "*" in uri_ignore_words or uri_word in uri_ignore_words: | ||
| check_words.remove(uri_word) |
There was a problem hiding this comment.
Can you not just drop the entire uri if * is present? Like your previous PR.
Also won't this currently mean that:I like to eat foo you can buy it from my online store at http://example.com/foo
Would miss foo->food in the free text because it exists in the URI if I set --uri-ignore-word-list=foo?
There was a problem hiding this comment.
Edit, I see your test says not. Is it actually finding the right one, or just working because there are two hits on the line and it just removes one of them?
There was a problem hiding this comment.
It's working because there are two hits on the line, and removing one. codespell doesn't track where the hit was when doing spell corrections, so if there is a repeated misspelling on the line, and it's told to fix the spelling, it'll probably fix both. I don't think that's particularly bad though: while something might be ignored in a uri, if it's there in plain text, I'd expect the common case to be that it needs to either be fixed in both or ignored in both. (either way, this is an edge case scenario)
If you prefer though, I could switch things around to do something more like:
if "*" in uri_ignore_words:
line = uri_regex.sub('', line)
check_words = extract_words(line, word, ignore_word_regex)
if "*" not in uri_ignore_words:
apply_uri_ignore_words(...)
I hadn't gone that route just because it felt more symmetric to use a similar approach with "*"
There was a problem hiding this comment.
I wonder if something even more like this might make more sense. Especially because your initial comment was people will just want to skip all typos in URIs wasn't it? Which means that 90% of the time we just want to hide the URI rather than process it twice.
| foruri_wordinextract_words(uri, word_regex, | |
| ignore_word_regex): | |
| if"*"inuri_ignore_wordsoruri_wordinuri_ignore_words: | |
| check_words.remove(uri_word) | |
| if"*"inuri_ignore_words: | |
| text=uri_regex.sub(' ', text) | |
| returnword_regex.findall(text) | |
| defapply_uri_ignore_words(check_words, line, word_regex, ignore_word_regex, | |
| uri_regex, uri_ignore_words): | |
| foruriinre.findall(uri_regex, line): | |
| foruri_wordinextract_words(uri, word_regex, | |
| ignore_word_regex): | |
| ifuri_wordinuri_ignore_words: | |
| check_words.remove(uri_word) |
@larsoner do you have any strong feelings either way?
There was a problem hiding this comment.
No strong opinion, either way seems fine to me
There was a problem hiding this comment.
I've switched the code to check for "*". I don't think it's a performance issue, but whatever's easiest to understand.
I'm not clear what the suggested edit was intended for. If the top half was supposed to be rewriting extract_words, I'd note that extract_words is also used for the options.check_filenames code path, where I felt URI checks shouldn't be done (felt more likely to hit false positives).
Uh oh!
There was an error while loading. Please reload this page.
jonmeow
commented
Sep 8, 2020
Added tests. I've loosened the regex a little accordingly, too. |
peternewman
left a comment
There was a problem hiding this comment.
A few more comments, I still need to take a final look at the main code changes.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jonmeow
left a comment
There was a problem hiding this comment.
Added a few more tests based on comments.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jonmeow
commented
Apr 20, 2021
Just checking here, is there still a chance of getting this merged? If not, I'll probably close the PR given its age. |
larsoner
commented
Apr 21, 2021
@peternewman did you want to look again? I'm going to close and reopen so that CIs get restarted -- there are some marked as pending which is weird. But I don't see a problem with merging this given the positive reception from @peternewman before, so feel free to ping me in a few days if you haven't heard anything @jonmeow ! |
peternewman
commented
Apr 23, 2021
Sorry @jonmeow . I suck, I'll make sure to have a look at this again later today. |
| '# Please see mailto:abandonned@example.com?subject=Test' | ||
| ' for info\n'): |
There was a problem hiding this comment.
I don't know if this is actually a match or a miss with the regex, but would be good to get "documented" in a test:
| '# Please see mailto:abandonned@example.com?subject=Test' | |
| ' for info\n'): | |
| '# Please see mailto:abandonned@example.com?subject=Test' | |
| ' for info\n', | |
| '# Please see mailto:foo@example.com?subject=Test' | |
| 'abandonned\n',): |
There was a problem hiding this comment.
This suggestion is missing a space in Testabandonned, but I'm assuming that's an oversight rather than deliberate: added a test around line 633 similar to the test on line 581.
There was a problem hiding this comment.
Oops, it was indeed @jonmeow . I was actually thinking of the example where the subject of the email was "Test abandonned", which I guess probably needs to be entered as "Test%20abandonned" or similar, which probably breaks any cleverness we have in place currently.
Uh oh!
There was an error while loading. Please reload this page.
peternewman
left a comment
There was a problem hiding this comment.
Just a few minor comments if you wouldn't mind addressing them.
Really sorry again for the delay.
Uh oh!
There was an error while loading. Please reload this page.
jonmeow
commented
May 27, 2021
Just pinging again, I don't think I can merge this because I don't have write access |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
peternewman
commented
May 28, 2021
Hi @jonmeow, I left a few comments in a hopefully final review after you pinged last time, although only one ended up attached to the review, the other was just a comment. Would you mind addressing them? @bl-ue 's comments don't seem unreasonable (and pretty quick fixes) if you're happy to look after them. |
Co-authored-by: bl-ue <54780737+bl-ue@users.noreply.github.com>
jonmeow
commented
Jun 1, 2021
Done. |
jonmeow
left a comment
There was a problem hiding this comment.
LGTM.
@jonmeow did you see https://github.com/codespell-project/codespell/pull/1656/files#r619284923?
Thanks, I wasn't seeing that.
| '# Please see mailto:abandonned@example.com?subject=Test' | ||
| ' for info\n'): |
There was a problem hiding this comment.
This suggestion is missing a space in Testabandonned, but I'm assuming that's an oversight rather than deliberate: added a test around line 633 similar to the test on line 581.
peternewman
left a comment
There was a problem hiding this comment.
Thanks very much for this @jonmeow it looks great. Sorry it's taken quite so long to get merged!
This is per discussion on #676, particularly:
#676 (comment)
The URI/email regex is deliberately simple to help with maintainability. False positives are possible but would likely have a low cost associated, particularly as nothing is ignored without setting --uri-ignore-words-list. False negatives would probably cause more trouble, so the regex is over-inclusive.