Skip to content

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

Closed
@cameron1024

Description

@cameron1024

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() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions