question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question/Rule Proposal for blank line after one line if

See original GitHub issue

I didn’t find any rule to check for a blank line after one line if statements that don’t use braces. I don’t want to force the use of curly braces for one line if statements to be able to enforce a blank line separation from if to if (rule 1513)

If there is no such rule, I would like to propose it, something like “Single line if statements should be followed by a blank line”

I want to avoid this type of code:

if (somevar == somevalue)
    // A line of code
if (someothervar == someothervalue)
    // Another line of code

and favor this:

if (somevar == somevalue)
    // A line of code

if (someothervar == someothervalue)
    // Another line of code

without having to do this:

if (somevar == somevalue)
{
    // A line of code
}

if (someothervar == someothervalue)
{
    // Another line of code
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SeidChrcommented, Dec 5, 2019

Hey, you asked me why i dislike options in codestyle. The answer was about this, and not about your requested new rule.

Your answers appear to me as if i personally attack you in any way. This is not the case. Or at least i did not intend to do so.

Regarding breaking a build on violating sc rules. I can understand why people do this, but i never ever would work with that tool if I wouldn’t have to. Especially with legacy code.

Regarding StyleCop in the compiler: i never got the point why Microsoft did not communicate sc as their suggested codestyle. Some blogs about this mention that people there are just as stubborn as developers everywhere else. So now we get a new codestyle every second year or so from some important team at ms, and everyone feels the urge to change his style to this. 🤷‍♂️

Closing this bucket of discussion now.

1reaction
sharwellcommented, Dec 4, 2019

I’m generally in favor of having an analyzer for this case, but there are a few exceptions that I believe would be important. The first two that come to mind are:

  1. Allow else or else if to follow without a blank line
  2. Allow consecutive if statements without a blank line if the child of each one either returns or throws (i.e. the behavior is equivalent to using else if)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why will a blank line not be added if I add a "\n" before and ...
Whether an empty line appears before The number of odd numbers is depends on the terminal: on linux and OS/X, reading from the...
Read more >
How to insert a blank line above another line
You can make use of the :g command. There are probably already answers here on how to use :g and there is also...
Read more >
notepad - Find and replace multiple blank lines
Within notepad there is no way to use the Find and Replace and target blank lines. Consider Notepad++ and the regex search and...
Read more >
Solved: How do I get rid of the blank line at the beginnin...
Solved: I've added a Table of Contents Zone macro and set the minimum heading level to 2, but a blank line still precedes...
Read more >
Removing blank lines - Power Platform Community - Microsoft
When I try to remove the blank line. replace(body('Html_to_text'),variables('txtCR'),'') //txtCR is just a variable with a line break. I get this:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found