Open PrzemyslawKlys opened 2 months ago
I've tried a bunch of variations. You can reproduce it with almost any expression that starts with a (
($x = 10)
$y = 30
formats as
($x = 10)
$y = 30
1, ($x = 10)
formats correctly
1, ($x = 10)
($x = 10), 1
# formats as the same
($x = 10), 1
Oh weird, thanks for the report. Did you try it under PSSA directly too?
No I didn't, sorry.
The latest version of the extension is using PSSA 1.22, which just came out. It would be helpful to know if this repros directly with Invoke-Formatter
and if so we can move the bug over there and get it fixed.
I would say it's PSScriptAnalyzer issue. Will you move it?
Thanks so much @PrzemyslawKlys!
Stepping through Formatter.Format()
this behaviour arises from the PSUseConsistentIndentation
rule.
Specifically from:
The issue seems to be that, if the left paren (
is:
AND
THEN that line's indentation is not checked against what we expect it to be. (Other necessary things still happen however)
Coming at it for the first time, I find the code-flow of the rule to be difficult to follow. The actual evaluation of whether the indentation is correct happens within the AddViolation()
function, and only if onNewLine
is true. It reads as though at each token parse, we're adding a rule violation - when in reality, checks are being performed and conditionally a violation is being added.
I believe, in the short-term, a change should be made so that in the situation outlined above, we still check the lines indentation is at the level we expect (but we don't increment the indentation level). Longer-term perhaps this rule should be revisited to make it a bit easier to follow and update it's styling slightly.
@bergmeister - this looks to be a rule you've put a lot of time and effort into, and you put together the PR that introduced this LParen check (#1469) - What do you think?
Prerequisites
Summary
Extension works perfectly most of the time in recent months. Today I've noticed weird issue
Where a simple code like this format mostly everything with the exception of lines with Get-Item
Trying to format it, leaves it as is, at the same time it formats everything else around it. So it seems there's something special about it.
PowerShell Version
Visual Studio Code Version
Extension Version
Steps to Reproduce
Visuals
No response
Logs
No response