Skip to content

Add support for ignoring spelling mistakes in URIs specifically. - #1656

Merged
peternewman merged 13 commits into
codespell-project:masterfrom
jonmeow:ignore-uris
Jun 1, 2021
Merged

Add support for ignoring spelling mistakes in URIs specifically.#1656
peternewman merged 13 commits into
codespell-project:masterfrom
jonmeow:ignore-uris

Conversation

@jonmeow

Copy link
Copy Markdown
Contributor

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.

@peternewman

Copy link
Copy Markdown
Collaborator

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:
https://mathiasbynens.be/demo/url-regex

@peternewmanpeternewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few comments.

Comment on lines +528 to +531
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

@jonmeowjonmeowSep 8, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

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 "*"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Suggested change
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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No strong opinion, either way seems fine to me

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

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).

Comment threadcodespell_lib/_codespell.py Outdated
@jonmeow

Copy link
Copy Markdown
ContributorAuthor

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:
https://mathiasbynens.be/demo/url-regex

Added tests. I've loosened the regex a little accordingly, too.

@peternewmanpeternewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few more comments, I still need to take a final look at the main code changes.

Comment threadcodespell_lib/tests/test_basic.py
Comment threadcodespell_lib/tests/test_basic.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py

@jonmeowjonmeow left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Added a few more tests based on comments.

Comment threadcodespell_lib/tests/test_basic.py
Comment threadcodespell_lib/tests/test_basic.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py
Comment threadcodespell_lib/_codespell.py
@jonmeow

Copy link
Copy Markdown
ContributorAuthor

Just checking here, is there still a chance of getting this merged? If not, I'll probably close the PR given its age.

@larsoner

Copy link
Copy Markdown
Member

@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 !

@larsonerlarsoner reopened this Apr 21, 2021
@peternewman

Copy link
Copy Markdown
Collaborator

Sorry @jonmeow . I suck, I'll make sure to have a look at this again later today.

Comment on lines +623 to +624
'# Please see mailto:abandonned@example.com?subject=Test'
' for info\n'):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

Suggested change
'# 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',):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jonmeow this one.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment threadcodespell_lib/_codespell.py

@peternewmanpeternewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a few minor comments if you wouldn't mind addressing them.

Really sorry again for the delay.

Comment threadcodespell_lib/_codespell.py Outdated
@jonmeow

Copy link
Copy Markdown
ContributorAuthor

Just pinging again, I don't think I can merge this because I don't have write access

Comment threadcodespell_lib/_codespell.py Outdated
Comment threadcodespell_lib/_codespell.py Outdated
@peternewman

Copy link
Copy Markdown
Collaborator

Just pinging again, I don't think I can merge this because I don't have write access

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.

@peternewmanpeternewman added this to the v2.1.0 milestone May 28, 2021
jonmeowand others added 2 commits June 1, 2021 10:17
Co-authored-by: bl-ue <54780737+bl-ue@users.noreply.github.com>
@jonmeow

Copy link
Copy Markdown
ContributorAuthor

Just pinging again, I don't think I can merge this because I don't have write access

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.

Done.

@bl-uebl-ue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jonmeowjonmeow left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Comment on lines +623 to +624
'# Please see mailto:abandonned@example.com?subject=Test'
' for info\n'):

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

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.

@peternewmanpeternewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks very much for this @jonmeow it looks great. Sorry it's taken quite so long to get merged!

@peternewman
peternewman merged commit 0338e3c into codespell-project:masterJun 1, 2021
@peternewmanpeternewman linked an issue Jun 1, 2021 that may be closed by this pull request
@jonmeow
jonmeow deleted the ignore-uris branch April 23, 2024 17:01
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't report spelling mistakes in HTTP URLs (e.g. in comments)

4 participants

@jonmeow@peternewman@larsoner@bl-ue