rust-lang / rust-lang/rustfmt

[Feature Request] Add mechanism to skip formatting specific comments

Open
#5,727 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments C-feature-request
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

rustfmt usually leaves comments alone, but will edit comments when wrap_comments=true is enabled, Additionally rustfmt sometimes removes leading / trailing spaces. However, in some cases its desirable to prevent modifications for specific comments. The #[rustfmt::skip] attribute exists to prevent rustfmt from modifying annotated code, and although this will sometimes prevent comments from being modified it's not ideal because it also prevents the code from being formatted.

Related Issues where modifying comments isn't desirable:

  • #5725
  • #5440
  • #5638

If anyone has ideas for how this mechanism could work please comment them down bellow.

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 reviewing related issues #5725, #5440, and #5638, then compare the existing #[rustfmt::skip] behavior with comment formatting when wrap_comments=true. Done means a defined mechanism can preserve selected comments without also skipping formatting for their surrounding code.

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.