When CheckParameter is $true for the rule PSUseConsistentWhitespace, it checks whitespace between parameters by inspecting the AST. It gets all direct children of each CommandAst and checks, in order, that each's extent is separated by exactly 1 character.
This relies on the implicit assumption that the AST returns the children in something resembling token order.
In the case of redirect operators, this is not always the case (they anecdotally appear to be returned in the order of the stream they're redirecting). See the issue here for more detailed breakdown.
This PR adds sorting of the children before subsequently performing the same checks on the tokens extents.
Running the below across PS5.1 and PS7.4 with and without the PR change applied shows the performance impact of the change to be minimal.
Awesome @liamjpeters . I will try to take some time soon to review this and all your other good work that I've glanced over. Thanks for your patience in the meantime, definitely excited to get your changes in.
PR Summary
When
CheckParameter
is$true
for the rulePSUseConsistentWhitespace
, it checks whitespace between parameters by inspecting the AST. It gets all direct children of eachCommandAst
and checks, in order, that each's extent is separated by exactly 1 character.This relies on the implicit assumption that the AST returns the children in something resembling token order.
In the case of redirect operators, this is not always the case (they anecdotally appear to be returned in the order of the stream they're redirecting). See the issue here for more detailed breakdown.
This PR adds sorting of the children before subsequently performing the same checks on the tokens extents.
Running the below across PS5.1 and PS7.4 with and without the PR change applied shows the performance impact of the change to be minimal.
Invoke-Formatter
Invoke-ScriptAnalyzer
Fixes #2000
PR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.