rust-lang / rust-lang/rust-clippy

Conditional compilation for configuration file?

Open
#11,433 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-ui C-question G-Rust-for-Linux
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Some lints that are configured via clippy.toml may need to react to conditional compilation.

For instance, for disallowed_macros, a project may want to warn only about a particular macro in some configurations (e.g. CI vs. development).

It could also be useful if Clippy were to identify unexpected paths to prevent mistakes (https://github.com/rust-lang/rust-clippy/issues/11432), since it would allow the user to e.g. remove a given macro from the list if the macro is compiled out.

A workaround could be users generating Clippy's config file on the fly.

Perhaps Clippy could instead allow to be configured within the Rust source code (step-by-step), so that the #[cfg] syntax/machinery is reused, but I imagine there is a reason it was not done there (e.g. workspaces sharing config easily?), e.g.

// `m1` always disallowed.
#[clippy_config(disallowed_macros, "m1")]

// `m2` only disallowed if `X`.
#[cfg(X)]
#[clippy_config(disallowed_macros, "m2")]

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 Clippy's configuration handling and Rust's conditional-compilation machinery. Compare the proposed clippy.toml and source-attribute approaches, including workspace sharing and the disallowed_macros example. Done means a decided configuration design that supports configuration-dependent lint settings and identifies the required implementation and tests.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.