Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is (no) lint for keeping spaces between functions #4866

Closed
sagudev opened this issue Jun 12, 2021 · 2 comments
Closed

There is (no) lint for keeping spaces between functions #4866

sagudev opened this issue Jun 12, 2021 · 2 comments

Comments

@sagudev
Copy link

sagudev commented Jun 12, 2021

Look at the playground and try rustfmt. I expect one blank lines between functions as that's how most code is formatted in rust as far as I know. I didn't find it as existing lint but it would be very similar to blank_lines_lower_bound but only for outside blocks.

What I would expect from lint to do:
Before:

mod my_mod {
    fn private_function() {
        println!("called `my_mod::private_function()`");
    }
    pub fn function() {
        println!("called `my_mod::function()`");
    }
}
mod my_mod2 {
    fn private_function() {
        println!("called `my_mod::private_function()`");
    }
    pub fn function() {
        println!("called `my_mod::function()`");
    }
}
fn function() {
    println!("called `function()` 1");
    println!("called `function()` 2");
    println!("called `function()` 3");
}
fn function2() {
    println!("called `function2()` 1");
    println!("called `function2()` 2");
    println!("called `function2()` 3");
}

After:

mod my_mod {
    fn private_function() {
        println!("called `my_mod::private_function()`");
    }

    pub fn function() {
        println!("called `my_mod::function()`");
    }
}

mod my_mod2 {
    fn private_function() {
        println!("called `my_mod::private_function()`");
    }

    pub fn function() {
        println!("called `my_mod::function()`");
    }
}

fn function() {
    println!("called `function()` 1");
    println!("called `function()` 2");
    println!("called `function()` 3");
}

fn function2() {
    println!("called `function2()` 1");
    println!("called `function2()` 2");
    println!("called `function2()` 3");
}
@calebcartwright
Copy link
Member

Thanks for reaching out, but this is actually a duplicate of bugs (e.g. #2954) with blank_lines_lower_bound where newlines were inserted just about everywhere instead of between Items as it should. That has been fixed in source but on a different experimental branch for a potential v2 of rustfmt, and the fix hasn't been backported into the rustfmt mainline and release train (#2954 is labeled accordingly).

Getting that fix backported is definitely on the radar, so I'm going to go ahead and close this. You may want to subscribe to that issue for any updates, as well as potentially the stabilization tracking issue (#3382) where other bugs and discussion may take place, as blank_lines_lower_bound is still an unstable/in-process option.

@sagudev
Copy link
Author

sagudev commented Jun 21, 2021

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants