Skip to content

Lint macro definitions that don't allow trailing commas #1848

@killercup

Description

@killercup

You know how every few weeks I drop by this repo to suggest madly complex new lints? Yep, it's this time again.

Rustfmt and the formatting RFCs have come a long way, and seem to slowly settle on a stable formatting for most Rust code. From what I can gather, one of the guidelines is to use trailing commas in pretty much all multi-line lists (function arguments, but also where clauses, struct fields, and arrays). This is a guideline I like very much, as trailing commas help reduce the noise in diffs and allow one to easily reorder lines. (For the vec! macro, Rustfmt already does some reformatting, but for other macros it (rightly) does not change the tokens.)

I'd like to propose a lint that checks macro_rules! definitions, sees if there are repeated patterns and, if necessary, suggests to change the pattern to allow trailing commas.

I'm not entirely sure what the best way to do that is. An easy way to add trailing comma support is adding $(,)*, but that allows 0 to ∞ many trailing commas…

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions