Skip to content

Commit 7a8ab5e

Browse files
author
Kapil Borle
committed
Sort items for correction text in UseToExportFieldsInManifest rule
1 parent 9af76ec commit 7a8ab5e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Rules/UseToExportFieldsInManifest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
9393

9494
}
9595

96-
private string GetListLiteral<T>(Dictionary<string, T> exportedItems)
96+
private string GetListLiteral<T>(Dictionary<string, T> exportedItemsDict)
9797
{
9898
const int lineWidth = 64;
99+
var exportedItems = new SortedDictionary<string, T>(exportedItemsDict);
99100
if (exportedItems == null || exportedItems.Keys == null)
100101
{
101102
return null;

Tests/Rules/UseToExportFieldsInManifest.tests.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Describe "UseManifestExportFields" {
4343
It "suggests corrections for FunctionsToExport with wildcard" {
4444
$violations = Run-PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
4545
$violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsWildcardPath
46-
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('Get-Foo', 'Get-Bar')"
47-
$violations[0].SuggestedCorrections[0].Description | Should Be "Replace '*' with @('Get-Foo', 'Get-Bar')"
46+
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('Get-Bar', 'Get-Foo')"
47+
$violations[0].SuggestedCorrections[0].Description | Should Be "Replace '*' with @('Get-Bar', 'Get-Foo')"
4848
}
4949

5050
It "detects FunctionsToExport with null" {
@@ -56,7 +56,8 @@ Describe "UseManifestExportFields" {
5656
It "suggests corrections for FunctionsToExport with null and line wrapping" {
5757
$violations = Run-PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
5858
$violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsNullPath
59-
Test-CorrectionExtent $violationFilepath $violations[0] 1 '$null' "@('Get-Foo1', 'Get-Foo2', 'Get-Foo3', 'Get-Foo4', 'Get-Foo5', 'Get-Foo6', `r`n`t`t'Get-Foo7', 'Get-Foo8', 'Get-Foo9', 'Get-Foo10', 'Get-Foo11', `r`n`t`t'Get-Foo12')"
59+
$expectedCorrectionExtent = "@('Get-Foo1', 'Get-Foo10', 'Get-Foo11', 'Get-Foo12', 'Get-Foo2', 'Get-Foo3', {0}`t`t'Get-Foo4', 'Get-Foo5', 'Get-Foo6', 'Get-Foo7', 'Get-Foo8', {0}`t`t'Get-Foo9')" -f [System.Environment]::NewLine
60+
Test-CorrectionExtent $violationFilepath $violations[0] 1 '$null' $expectedCorrectionExtent
6061
}
6162

6263
It "detects array element containing wildcard" {
@@ -84,7 +85,7 @@ Describe "UseManifestExportFields" {
8485
It "suggests corrections for AliasesToExport with wildcard" {
8586
$violations = Run-PSScriptAnalyzerRule $testManifestBadAliasesWildcardPath
8687
$violationFilepath = Join-path $testManifestPath $testManifestBadAliasesWildcardPath
87-
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('gfoo', 'gbar')"
88+
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('gbar', 'gfoo')"
8889
}
8990

9091
It "detects all the *ToExport violations" {

0 commit comments

Comments
 (0)