diff --git a/Rules/AlignAssignmentStatement.cs b/Rules/AlignAssignmentStatement.cs index 083b6dcb5..d66ac1411 100644 --- a/Rules/AlignAssignmentStatement.cs +++ b/Rules/AlignAssignmentStatement.cs @@ -191,15 +191,7 @@ private IEnumerable FindHashtableViolations(TokenOperations to continue; } - var widestKeyExtent = extentTuples - .Select(t => t.Item1) - .Aggregate((t1, tAggregate) => - { - return TokenOperations.GetExtentWidth(tAggregate) > TokenOperations.GetExtentWidth(t1) - ? tAggregate - : t1; - }); - var expectedStartColumnNumber = widestKeyExtent.EndColumnNumber + 1; + var expectedStartColumnNumber = extentTuples.Max(x => x.Item1.EndColumnNumber) + 1; foreach (var extentTuple in extentTuples) { if (extentTuple.Item2.StartColumnNumber != expectedStartColumnNumber) diff --git a/Tests/Rules/AlignAssignmentStatement.tests.ps1 b/Tests/Rules/AlignAssignmentStatement.tests.ps1 index 31bbfa81d..29a39eeee 100644 --- a/Tests/Rules/AlignAssignmentStatement.tests.ps1 +++ b/Tests/Rules/AlignAssignmentStatement.tests.ps1 @@ -55,6 +55,16 @@ $hashtable = @{ Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' } + It "Should not crash if property name reaches further to the right than the longest property name (regression test for issue 1067)" { + $def = @' +$hashtable = @{ property1 = "value" + anotherProperty = "another value" +} +'@ + + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings -ErrorAction Stop | Get-Count | Should -Be 0 + } + It "Should ignore if a hashtable is empty" { $def = @' $x = @{ }