◐ Shell
clean mode source ↗

Do not increase indentation after LParen if the previous token is a Newline and the next token is not a Newline by bergmeister · Pull Request #1469 · PowerShell/PSScriptAnalyzer

PR Summary

Fixes #1407 cc @felixbecker

This is to fix a long-standing bug in the formatter that has been present probably since day 1.
There are a few cases that were similar to this one where an LParen and LBrace are both on the same line cause an increase of indentation that is twice as much as needed.

Therefore this PR adds a check to see if the LParen is the first token on a line by checking the previous token is of kind Newline. Then it also checks that the following token (comments have to be skipped) is also not a Newline so that the following case would still indent:

$result = (
    Get-Something
).Property

In order to prevent the RParen code from de-indenting too much, we have to keep a stack of when we skipped the indentation caused by tokens that require a closing RParen (which are LParen, AtParen and DollarParen).

PR Checklist