rust-lang / rust-lang/rust-clippy
Enforce which link types can be used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Rust uses markdown for doc comments. Markdown is a pretty loose standard and behaves differently based on the implementation. Rustdoc supports three different ways to specify a link with a link location:
# 1
[<text 1>](https://github.com/rust-lang/rust-clippy)
# 2
[<text 2>][https://github.com/rust-lang/rust-clippy]
# 3
[<text 3>]
[<text 3>]: https://github.com/rust-lang/rust-clippy
See: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
This lint should have a configuration, that can specify which links are allowed in doc comments. The configuration could be called: allowed-doc-link-styles or something similar, taking a list of items like:
InlineBracketsfor[][]InlineParenthesisfor[]()- maybe
Referencefor the third case.
By default, I'd allow InlineParenthesis and Reference as these are normal Markdown links.
This should be a relatively simple lint, as Clippy already has a markdown parser for doc comments, however, it might require some handling to correctly detect which type of link is actually used
Lint Name
comment_link_style
Category
restriction
Advantage
- Unifies the codebase
Drawbacks
- Might cause many reports, when it's not a restriction lint
Example
/// # 1
/// [<text 1>](`Option`)
///
/// # 2
/// [<text 2>][`Option`]
///
/// # 3
/// [<text 3>]
///
/// [<text 3>]: `Option`
struct CoolItem;
Could be written as:
/// # 1
/// [<text 1>](`Option`)
///
/// # 2
/// [<text 2>](`Option`)
///
/// # 3
/// [<text 3>]
///
/// [<text 3>]: `Option`
struct CoolItem;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Clippy's existing markdown parser for doc comments and the configuration handling for new lints. Define detection for the three link styles, apply the proposed default and configurable allowed styles, and verify that disallowed styles are reported while allowed styles are accepted using the issue's examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100