rust-lang / rust-lang/rustfmt

feature request: add ability to enforce no blank lines in fn implementations

Open
#5,230 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently there is an option to specify minimum and maximum of blank lines between items.

I think it would be nice if the option set would be expanded with:
maximum-blank-lines-in-fn-definitions.

I personally sometimes add blank lines for readability, but I can see the argument for not having any blank lines in the functions at all, ( and I do often end up landing blank lines at random )
it gives a coherent style across a codebase.

Example:
Instead of:

fn mini() {}

fn something(a: i32) -> i32 {
  if (a == 3) {
    return 0;
  }
  
  return 1;
}

A requested formatting would tighten up this code to:

fn mini() {} 

fn something(a: i32) -> i32 {
  if (a == 3) {
    return 0;
  }
  return 1;
}

Note that spacing between the defs would remain the same.
I think the defs of types should still allow a separation of inside the fn definitions. ( but that may be my prejudice speaking )

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 tracing the existing minimum and maximum blank-line options in rustfmt and compare their behavior with the Rust examples in this issue. The change is complete when a maximum-blank-lines-in-fn-definitions option removes excess blank lines inside function bodies while preserving spacing between function definitions and allowing the stated type-definition behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.