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

detect ['foo'] (quotes, not backticks) in doc comments #8383

Closed
cameron1024 opened this issue Feb 1, 2022 · 2 comments · Fixed by #8385
Closed

detect ['foo'] (quotes, not backticks) in doc comments #8383

cameron1024 opened this issue Feb 1, 2022 · 2 comments · Fixed by #8385
Labels
A-lint Area: New lints

Comments

@cameron1024
Copy link
Contributor

What it does

Highlights when someone writes:

/// ['foo::Bar']

when they probably meant

/// [`foo::Bar`]

This recently caught me out. cargo doc reported no broken links, but I had a couple lurking that were using this format, so were missed by the broken link check.

The characters are visually similar enough to be very easy to confuse

Lint Name

doc_link_with_quotes

Category

suspicious

Advantage

Typing ['foo::Bar'] (with single quotes) is almost certainly a mistake, either because they genuinely think that is the correct syntax, or as a typo. Having clippy flag likely leads to better

Drawbacks

There are likely some false positives, since this syntax is meaningful in other languages (e.g. in JS/TS, Python and Dart (probably more than that) they represent list containing a string literal, though in those cases I suspect it would already be enclosed in backticks, so the actual false positive rate is likely quite low

Example

/// Does the same thing as ['bar']
fn foo() {}

Could be written as:

/// Does the same thing as [`bar`]
fn foo() {}
@cameron1024 cameron1024 added the A-lint Area: New lints label Feb 1, 2022
@cameron1024
Copy link
Contributor Author

FWIW, if people think this would be helpful, I'd be happy to try implementing this myself. I've not worked on clippy before but keen to learn 😁

@llogiq
Copy link
Contributor

llogiq commented Feb 1, 2022

Sure! I guess the best starting point is writing a UI test (a .rs file in tests/ui containing Rust code the lint should pick up on) and then looking at clippy_lints/doc.rs where the other documentation lints are.

Feel free to comment here or on your PR if you have questions or encounter any problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants