Skip to content

[Feature-Request] Blank-lines surrounding curly braces #5963

Open
@richardpringle

Description

@richardpringle

Sorry if this is a dup, I searched for a little bit and only found issues related to blank lines inside curly braces.

I have no idea how hard this would be, but it would be really nice to have a configurable option to add blank lines surrounding anything with curly braces.

with the rule on

fn main() {
  let some_optional_value = map.get(&key); 
  
  if let Some(value) = some_optional_value {
      do_something_with_value(value);
  }
}

with the rule off

fn main() {
  let some_optional_value = map.get(&key);  
  if let Some(value) = some_optional_value {
      do_something_with_value(value);
  }
}

This would include for-loop, loop, while, etc. Any expressions with a scope defined by curly braces.

I'm thinking something akin to this rule: https://eslint.org/docs/latest/rules/padding-line-between-statements

I'm trying to have some automatic way to not get code that looks like this:

        let mut items = HashMap::new();
        for _ in 0..100 {
            let val: Vec<u8> = (0..10).map(|_| rng.borrow_mut().gen()).collect();
            items.insert(generate_key(), val);
        }
        let mut items_ordered: Vec<_> = items.clone();
        items_ordered.sort();
        items_ordered.shuffle(&mut *rng.borrow_mut());
        for (k, v) in items.into_iter() {
            other_map.insert(&k, v)?;
        }

and have the formatted add some empty lines to make the code easier to read

        let mut items = HashMap::new();

        for _ in 0..100 {
            let val: Vec<u8> = (0..10).map(|_| rng.borrow_mut().gen()).collect();
            items.insert(generate_key(), val);
        }

        let mut items_ordered: Vec<_> = items.clone();
        items_ordered.sort();
        items_ordered.shuffle(&mut *rng.borrow_mut());

        for (k, v) in items.into_iter() {
            other_map.insert(&k, v)?;
        }

Obviously, not everyone wants this, but it would be great if it were an option. I'm happy to PR, if someone can point me in the right direction.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions