PowerShell / DscResource.Tests

Common meta tests for PowerShell DSC resources repositories.
MIT License
51 stars 49 forks source link

Code formatting: newlines before and after if statement block #345

Open SSvilen opened 5 years ago

SSvilen commented 5 years ago

Hello,

Is the standard for DSC code to have a newline before and after if/ if else statement block? This is not how I write my code and often I need to reformat it to get my PR approved. If it is a standard, then I could do a custom PSScriptAnalyzerRule for that.

johlju commented 5 years ago

I like to have air in the code so it easier for new contributors to read the code, it is easier for the eyes to see blocks, and those blociks are written the same throughout a repo. Most code is written with air, but there are no specific guideline around it (see https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#whitespace). But I love to see this as a guideline and a new custom rule (and more custom rules for the entire style guideline).

So this

$something = $true
if ($something)
{
}
if ()
{
}

I would rather see written as

$something = $true

if ($something)
{
}

if ()
{
}

With the exception of the previous line starts with an open brace. I like to see this as valid.

$something = $true

try
{
    if ($something)
    {
    }
}