PSUseConsistentIndentation: Check indentation of lines where first token is a LParen not followed by comment or new line by liamjpeters · Pull Request #1995 · PowerShell/PSScriptAnalyzer

I've used it across several large code bases at work. I'm happy with the corrections it's suggested on those.

Alongside the test run I did on the PSScriptAnalyzer module, I've tested it on a public module I've used a bit recently, IntuneManagement. It has a fairly large PowerShell codebase.

Without this PR applied, using settings to limit analysis to just the rule in question, PSUseConsistentIndentation, I get 3,304 violations.

With this PR applied I get 3,305.

Just like the PSScriptAnalyzer module anyalysis, all previously found violations were still found. So there was 1 additional violation found.

It's here on line 1,394.

image

New PR would fix it to be:

image

This is because Two Left-Parens are on line 1,393, with just the one Right-Paren. So the indentation on the following line is increased by 1.

To me it reads slightly clearer as I scan down the code-block: if statement, indentation, left curly brace for the body of the statement.

I'd personally probably format the code-block like:

if (
    ($obj.PSObject.Properties | Where-Object Name -EQ 'securityRequireSafetyNetAttestationBasicIntegrity') -and 
    ($obj.PSObject.Properties | Where-Object Name -EQ 'securityRequireSafetyNetAttestationCertifiedDevice')
) {

But that's personal preference.

Where's no sort of definitive style guide that covers this scenario (that I'm aware of anyway), it's not clear cut what should be done here.

Ultimately if this PR moves things in a 'more correct' direction (whatever 'correct' is), then I'd say I'm happy that this doesn't break anything. But if you think this change is moving the other way - I won't be offended with it being rejected or some changes being suggested; it's all good 😀.