rust-lang / rust-lang/rust-clippy

Lint suggestion: Suggest separating (or combining) attributes which accept a list of parameters

Open
#11,331 2 comments 2 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

Common practice in a lot of Rust code is to separate #![feature(...)], #![allow(...)], #![deny(...)], and #![warn(...)] attributes so that each item is a separate attribute, rather than a list of several. The proposal would be, for some potentially configurable list of attributes, suggest to either separate these attributes or combine them when applied to an item.

Advantage

Generally, separating onto multiple lines makes it easier to not "miss" items where a list is included on a single line. So, having a lint to enforce (and automatically fix) these cases would be very helpful.

However, because some people might also like the alternative method, and it's possible to format the attributes so that the list items are still on their own lines if the list is sufficiently large, I'm proposing to also add the ability to format in that way too.

Drawbacks

It might be too good.

Example

Valid combined:

#![allow(clippy::cursed_rust_patterns, live_code, rustc::eating_laundry)]
#![feature(cursed_types, java_style_inheritance, return_position_type_alias_impl_trait_in_struct)]

Valid separated:

#![allow(clippy::cursed_rust_patterns)]
#![allow(live_code)]
#![allow(rustc::eating_laundry)]
#![feature(cursed_types)]
#![feature(java_style_inheritance)]
#![feature(return_position_type_alias_impl_trait_in_struct)]

Invalid in both cases:

#![allow(clippy::cursed_rust_patterns, rustc::eating_laundry)]
#![allow(live_code)]
#![feature(cursed_types, return_position_type_alias_impl_trait_in_struct)]
#![feature(java_style_inheritance)]
Prior Art

This would have been helpful when working on rust-lang/rust#114766.

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 with the issue's valid and invalid examples and review the cited rust-lang/rust#114766 prior art. Determine the configurable attribute list and whether combined or separated formatting is the intended policy; done means the lint and its automatic fix consistently enforce the chosen behavior.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.