Include file path in AlignAssignmentStatement corrections - #2202
Include file path in AlignAssignmentStatement corrections#2202peanut (teanup) wants to merge 2 commits into
Conversation
…lignAssignmentStatement The CorrectionExtent constructor was being called with the rule message as the 6th argument (file), when it should be the 7th (description).
There was a problem hiding this comment.
Pull request overview
Fixes AlignAssignmentStatement suggested corrections so CorrectionExtent receives the correct file argument (and the rule message remains in the description argument), ensuring the file path is included properly in correction metadata.
Changes:
- Adds the missing
lhsExtent.Fileargument to theCorrectionExtentconstructor call inAlignAssignmentStatement.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
👋 peanut (@teanup) - Thanks for finding and fixing this! All of the current tests use Something like the below, where a violation is emitted to a file and then analysed. It 'sets correction file and description when analyzing a file' {
$path = Join-Path $TestDrive 'unaligned.ps1'
Set-Content -LiteralPath $path -Value '@{"Key" = "Value"}'
$violations = Invoke-ScriptAnalyzer -Path $path -Settings (New-AlignAssignmentSettings -CheckHashtable $true) |
Get-NonParseDiagnostics
$violations | Should -HaveCount 1
$correction = $violations[0].SuggestedCorrections[0]
$correction.File | Should -Be ([IO.Path]::GetFullPath($path))
$correction.Description | Should -Be 'Assignment statements are not aligned'
} |
…uggestedCorrection format
|
@microsoft-github-policy-service agree |
|
Thanks for the suggestion Liam Peters (@liamjpeters)! I've added a Pester test that validates the corrected behavior with file path inputs |
PR Summary
This PR adds a missing argument for the CorrectionExtent constructor in the AlignAssignmentStatement rule definition.
PR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.