rust-lang / rust-lang/rust-clippy

[epic] Improve lint config discoverability

Open
#9,880 21 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ui C-an-interesting-project
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description

There are almost 50 Clippy configuration parameters. Most of them are likely unused by the users, in part because users do not know about them. I would like to propose a simple method to improve config param visibility: all lints should print a note, just once, in its output if the lint's behavior can be changed by a config parameter. The note should not be printed if the config param is already used. This approach would address some concerns from #9787

Note that the current config parser resolves defaults early on, so the lint doesn't know whether the config value is not set, or if it is set to the same value as default. We may want to introduce an additional flag for this in the future.

Example

span_lint_and_then(
    cx,
    DBG_MACRO,
    macro_call.span,
    "`dbg!` macro is intended as a debugging tool",
    |diag| {
        diag.span_suggestion(
            macro_call.span,
            "ensure to avoid having uses of it in version control",
            suggestion,
            applicability,
        );

        // ######################################
        // #########  Add this new code #########
        // ######################################
        if !self.allow_dbg_in_tests {
            // Improve lint config discoverability
            diag.note_once(
                "this lint can ignore test functions if \
                `allow-dbg-in-tests = true` is added in the `clippy.toml` file",
            );
        }
    },
);

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 reading the current config parser and how lint diagnostics are built, using the span_lint_and_then example and its allow-dbg-in-tests setting as the concrete entry point. Check how defaults are resolved and how all configurable lints could report unused configuration parameters only once. Done means the proposed note behavior is implemented consistently without reporting parameters already set by users.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.