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

Consider - forcing braces on loops and if statements. #930

Open
danfma opened this issue Aug 11, 2023 · 3 comments
Open

Consider - forcing braces on loops and if statements. #930

danfma opened this issue Aug 11, 2023 · 3 comments

Comments

@danfma
Copy link

danfma commented Aug 11, 2023

Hello,

It would be nice if we could enforce the curly brackets for conditions and loops. Probably, a strategy for that would be better, something like:

  • always => always use;
  • when_multiline => only when there are more than two statements;

What do you think?

@belav
Copy link
Owner

belav commented Aug 11, 2023

CSharpier is an opinionated formatter and adding an option goes against that.

I would consider always forcing braces, but I don't know how split developers are in the always braces vs no braces. There are also other tools to force braces, they just don't run on save.

@belav belav changed the title Define strategies for curly brackets on conditions and loops Consider - forcing braces on loops and if statements. Aug 11, 2023
@jods4
Copy link

jods4 commented Aug 16, 2023

I feel like this is unlikely to get strong consensus in community.

Personally, I like no-brace style for short single-line statements like if (!alive) return;.
I know other people who swear by always-use-braces.

I think it's probably simpler for CSharpier to stick to its "no-syntax change, whitespace formatting-only" general policy on this one.
Braces can be enforced by linters (even C# by itself can be configured through .editorconfig to error on if without braces).

(BTW in the same category: dropping brackets around single-argument, type-less lambdas? Prettier has an option to change (x) => true into x => true. I like this but I feel my comment applies just the same for this one.)

@danfma
Copy link
Author

danfma commented Sep 18, 2024

Yeah, I understand csharpier is opinionated and that adding more options will make the code harder to maintain, so that was just an idea.

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

3 participants