rust-lang / rust-lang/rust-clippy

Enforce which link types can be used

Open
#10,176 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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:

  • InlineBrackets for [][]
  • InlineParenthesis for []()
  • maybe Reference for 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.