Separate Where-Object comparison parameters and reject malformed native selectors

This commit is contained in:
NINI
2026-10-07 00:22:54 +09:00
parent 913f19c360
commit cc88785e7c
2 changed files with 6 additions and 5 deletions
+3 -2
View File
@@ -4,8 +4,9 @@ New-Item -ItemType Directory -Path $EvidenceDir -Force|Out-Null
if(!$Sources){$Sources=@(Get-ChildItem $PSScriptRoot -Filter '*.ps1'|Select-Object -ExpandProperty FullName)}
$results=@(foreach($source in $Sources){
$errors=$null
[Management.Automation.Language.Parser]::ParseFile($source,[ref]$null,[ref]$errors)|Out-Null
@{source=$source;passed=($errors.Count-eq0);errors=@($errors|Select-Object ErrorId,Message,@{n='line';e={$_.Extent.StartLineNumber}})}
$ast=[Management.Automation.Language.Parser]::ParseFile($source,[ref]$null,[ref]$errors)
$malformed=@($ast.FindAll({param($n)$n-is[Management.Automation.Language.CommandParameterAst]-and$n.ParameterName-match'^(eq|ne|gt|lt|ge|le)\d+$'},$true)|ForEach-Object{$_.Extent.Text})
@{source=$source;passed=($errors.Count-eq0-and$malformed.Count-eq0);malformedOperatorParameters=$malformed;errors=@($errors|Select-Object ErrorId,Message,@{n='line';e={$_.Extent.StartLineNumber}})}
})
$passed=$results.Count-gt0-and@($results|Where-Object passed -ne $true).Count-eq0
@{passed=$passed;checks=$results}|ConvertTo-Json -Depth 8|Set-Content (Join-Path $EvidenceDir 'syntax-result.json')