diff --git a/Rules/AlignAssignmentStatement.cs b/Rules/AlignAssignmentStatement.cs index 5b941924a..a727bc7d7 100644 --- a/Rules/AlignAssignmentStatement.cs +++ b/Rules/AlignAssignmentStatement.cs @@ -650,6 +650,7 @@ int targetColumn lhsExtent.EndColumnNumber, equalsExtent.StartColumnNumber, new string(' ', targetColumn - lhsExtent.EndColumnNumber), + lhsExtent.File, string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementError) ) }; diff --git a/Tests/Rules/AlignAssignmentStatement.tests.ps1 b/Tests/Rules/AlignAssignmentStatement.tests.ps1 index 1262acdf8..a115af9d0 100644 --- a/Tests/Rules/AlignAssignmentStatement.tests.ps1 +++ b/Tests/Rules/AlignAssignmentStatement.tests.ps1 @@ -126,6 +126,21 @@ Configuration C1 { Context 'When Hashtable checking is enabled' { + It 'Should set correction file and description when analyzing a file' { + $path = Join-Path -Path $TestDrive -ChildPath 'unaligned.ps1' + Set-Content -LiteralPath $path -Value '@{"Key" = "Value"}' + + $settings = New-AlignAssignmentSettings -CheckHashtable $true + + $violations = Invoke-ScriptAnalyzer -Path $path -Settings $settings | + 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' + } + It 'Should not find violations in empty single-line hashtable' { $def = '@{}'