-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSUseConsistantWhiteSpace #2089
Comments
Well that was interesting...->I pulled the code to see what was happening cause I was curious, it seems to come down to somewhat weird behavior of the UsingStatementAst vs other kinds of Asts like say ScriptBlockAst which flip the SkipChildren to a Continue inside it's the internalvisit but the internal visit of the UsingStatementAst just passes the SkipChildren through instead of flipping it to a continue when visiting a InternalVisit of UsingStatementAst vs I can't tell if this is a bug in the system automation stuff or some weird expected behavior, if you parse a file with using statements, once the visitor hits the script block, sets that as it's visit and then exits out after hitting the UsingStatementAst (usually the next one in my testing), Investigation reproduction:Input to pester test passing:#using namespace somethin
$ht = @{
variable = 3
other = 4
}
$alpha = @{
beta =
delta = 4
}
'@ Passing output of ast tree:
Input script when failing:using namespace something
$ht = @{
variable = 3
other = 4
}
$alpha = @{
beta =
delta = 4
}
'@ Failing output of ast tree:
I added some logging inside the Visit function of the FindAstPositionVisitor.cs class private AstVisitAction Visit(Ast ast)
{
Console.WriteLine($"Visiting {ast.GetType().Name}");
if (ast.Extent.StartOffset > searchPosition.Offset || ast.Extent.EndOffset <= searchPosition.Offset)
{
Console.WriteLine($" Skipping Kids...");
return AstVisitAction.SkipChildren;
}
Console.WriteLine($" Setting As Position...");
AstPosition = ast;
return AstVisitAction.Continue;
} and the output when passing was:
and when failing it was:
as a result the type of the AST returned is a ScriptBlockAst instead of a HashTableAst here the UseConsistantWhiteSpace.cs and an error is reported instead of being skipped... Quick Fix:I don't believe PSScriptAnalyzer does anything related using statements currently? if that's accurate then simply returning AstVisitAction.Continue instead of passing the UsingStatementAst down to your visit function function fixed it locally for me. Otherwise some specialized logic inside your Visit function will likely be required. Of course it could also be it's a bug in the system automation but I feel like that'll be longer fix unless y'all are on the same team :) |
Steps to reproduce
Attaching our PSD fille for the analyzer config
We have
PSUseConsistentWhitespace with IgnoreAssignmentOperatorInsideHashTable = $true
PSAlignAssignmentStatement with Enabled = $true and CheckHashTable = $true
It generally works as advertised... except...
When a using statement is present... we get a "Use space before and after binary and assignment operators.PSScriptAnalyzer(PSUseConsistentWhitespace)" error.
This does not work ...
This works in our setup...
The text was updated successfully, but these errors were encountered: