Exclude block-style comments in wrap_str/filter_normal_code check
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
There's a utility function, wrap_str, used in various locations throughout the rustfmt codebase which does some checks against a string of formatted code, including whether each line in the string will fit within the width constraints.
The width check is supposed to exclude comments, and does so successfully for line-style comments (e.g. // foo bar). However, there is an issue where it does not exclude block-style comments (e.g. /* foo bar */).
The code that handles sorting out comments can be found in the comments.rs file:
https://github.com/rust-lang/rustfmt/blob/79c36960af85fa52ae4dc60ec1f83ec7f9b2733f/src/formatting/comment.rs#L1613-L1629
and this would need to be extended to exclude block-style comments as well. Remember that multi-line block style comments are a possibility, so that needs to be accounted for as well, though happy to accept improvements that cover single-line block style comments.
The changes should include tests, for example additional unit tests like the existing ones for filter_normal_code:
https://github.com/rust-lang/rustfmt/blob/79c36960af85fa52ae4dc60ec1f83ec7f9b2733f/src/formatting/comment.rs#L1984-L1999
Additionally, it would be beneficial to include the standard system/idempotence tests with an input file (tests/source/...) that contains snippets that result in the above code paths getting hit, such as a chain that contains a block-style comment that exceeds max_width, along with a target/output file (tests/target/...) that shows the resultant formatting.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/formatting/comment.rs around the comment-handling code at lines 1613-1629 and the filter_normal_code unit tests around lines 1984-1999. Cover block-style comments, including multiline cases, and add tests plus tests/source and tests/target fixtures showing formatting of an over-width block comment; done means the width check excludes those comments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100