drahnr / cargo-spellcheck

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
Apache License 2.0
314 stars 32 forks source link

Don't flag valid identifiers as misspelled in doc comments #329

Closed sdankel closed 2 weeks ago

sdankel commented 1 month ago

Is your feature request related to a particular use-case?

I tried this out, hoping to fix a bunch of typos in doc comments in my repo. However, there are thousands of errors everywhere that I have a comment with an valid identifier, for example:

/// A [HashMap] that can hold multiple values and ...

image

A possible workaround for now is using the regex transform to ignore anything inside of square brackets, but I haven't been able to get it to work. I think it should be a built-in option since it is conventional to use square brackets around types in rust doc comments for features like hover documentation.

Describe the solution you'd like to implement/see implemented

Ideally I wouldn't have to ignore everything inside of square brackets, as the parser could tell if the identifier is a valid name or not.

If you have any suggestions about the regex transform, it would be much appreciated!

Describe alternatives you've considered

Use a different spell checker

drahnr commented 1 month ago

Hey, thank you for flagging. Commonly I'd expect any inline code or types to be enclosed in back ticks, this includes linkage i.e.

Fred [`HashMap`] ghji.

And that works both for both, intra doc linkage as well as spell checking.

If you want to implement the collection of all types and doing a prefix tree match against [] enclosed strings, happy to help, it's by no means a trivial endavour to do it efficiently beyond a single file scope, and a single file scope would break due to wildcard imports.

tl;dr using [Foo] works, doing a special case impl is quite a bit of work and not necessary