Skip to content

Add new lint for the location of a semicolon depending on whether its block is singleline or multiline #10654

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

Closed
Centri3 opened this issue Apr 17, 2023 · 0 comments · Fixed by #10656
Labels
A-lint Area: New lints

Comments

@Centri3
Copy link
Member

Centri3 commented Apr 17, 2023

What it does

This is the same as both semicolon-inside-block and semicolon-outside-block, but decides which one to use based on whether the block is singleline or multiline.

Lint Name

semicolon-inside-block-if-multiline or semicolon-outside-block-if-singleline (I prefer this one)

Category

restriction

Advantage

  • rustfmt will make an unsafe block containing only one expression multiline if the semicolon is inside the block, but won't if it's on the outside. Adding this lint will allow swapping the location to allow rustfmt to make it a singleline, while also encouraging some consistency.
  • Some may find outside cleaner only in the case that it's singleline.

Drawbacks

  • The descriptions of both semicolon-inside-block and semicolon-outside-block suggest consistency, so this may contradict that.
  • If rustfmt is invoked, what was previously fine could become a warning (or an error if a library author is a bit zealous about warnings). This may be unexpected.

Example

    unsafe {
        WriteProcessMemory(
            self.inner,
            base as _,
            bytes.as_ptr() as _,
            bytes.len(),
            None,
        )
    };

    unsafe {
        ExitProcess(0i32);
    }

Could be written as:

    unsafe {
        WriteProcessMemory(
            self.inner,
            base as _,
            bytes.as_ptr() as _,
            bytes.len(),
            None,
        );
    }

    unsafe { ExitProcess(0i32) };
@Centri3 Centri3 added the A-lint Area: New lints label Apr 17, 2023
bors added a commit that referenced this issue Apr 25, 2023
Add configuration for `semicolon_block` lints

Does exactly what it says on the tin, suggests moving a block's final semicolon inside if it's multiline and outside if it's singleline.

I don't really like how this is implemented so I'm not too sure if this is ready yet. Alas, it might be ok.

---

fixes #10654

changelog: Enhancement: [`semicolon_inside_block`]: Added `semicolon-inside-block-ignore-singleline` as a new config value.
[#10656](#10656)
changelog: Enhancement: [`semicolon_outside_block`]: Added `semicolon-outside-block-ignore-multiline` as a new config value.
[#10656](#10656)
<!-- changelog_checked -->
@bors bors closed this as completed in 990bbdc Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant