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
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix