Skip to content

Commit 46ff932

Browse files
authored
Include file path in AlignAssignmentStatement corrections (#2202)
* Fix #2201: Include file path in SuggestedCorrections from AlignAssignmentStatement The CorrectionExtent constructor was being called with the rule message as the 6th argument (file), when it should be the 7th (description). * Fix #2201: Add test for AlignAssignmentStatement to check SuggestedCorrection format
1 parent b1c09c5 commit 46ff932

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Rules/AlignAssignmentStatement.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ int targetColumn
650650
lhsExtent.EndColumnNumber,
651651
equalsExtent.StartColumnNumber,
652652
new string(' ', targetColumn - lhsExtent.EndColumnNumber),
653+
lhsExtent.File,
653654
string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementError)
654655
)
655656
};

Tests/Rules/AlignAssignmentStatement.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ Configuration C1 {
126126

127127
Context 'When Hashtable checking is enabled' {
128128

129+
It 'Should set correction file and description when analyzing a file' {
130+
$path = Join-Path -Path $TestDrive -ChildPath 'unaligned.ps1'
131+
Set-Content -LiteralPath $path -Value '@{"Key" = "Value"}'
132+
133+
$settings = New-AlignAssignmentSettings -CheckHashtable $true
134+
135+
$violations = Invoke-ScriptAnalyzer -Path $path -Settings $settings |
136+
Get-NonParseDiagnostics
137+
138+
$violations | Should -HaveCount 1
139+
$correction = $violations[0].SuggestedCorrections[0]
140+
$correction.File | Should -Be ([IO.Path]::GetFullPath($path))
141+
$correction.Description | Should -Be 'Assignment statements are not aligned'
142+
}
143+
129144
It 'Should not find violations in empty single-line hashtable' {
130145
$def = '@{}'
131146

0 commit comments

Comments
 (0)