Skip to content

Commit ca62db5

Browse files
authored
Merge pull request #7675 from cormacpayne/renamed-param-fix
Fix bug in StaticAnalysis that threw when renaming a parameter
2 parents f364f43 + 7d4c2e7 commit ca62db5

File tree

6 files changed

+1910
-201
lines changed

6 files changed

+1910
-201
lines changed

tools/StaticAnalysis/BreakingChangeAnalyzer/ParameterSetMetadataHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Collections.Generic;
16+
using System.Linq;
1617
using Tools.Common.Loggers;
1718
using Tools.Common.Models;
1819

@@ -115,7 +116,8 @@ public void CompareParameterSetMetadata(
115116
bool foundAdditional = false;
116117
foreach (var parameter in newParameterSet.Parameters)
117118
{
118-
if (parameterDictionary.ContainsKey(parameter.ParameterMetadata.Name))
119+
if (parameterDictionary.ContainsKey(parameter.ParameterMetadata.Name) ||
120+
parameter.ParameterMetadata.AliasList.Any(a => parameterDictionary.ContainsKey(a)))
119121
{
120122
continue;
121123
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
2-
"Microsoft.Azure.Commands.Profile.dll","Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand","Connect-AzureRmAccount","0","1050","The parameter set 'ServicePrincipalWithSubscriptionId' for cmdlet 'Connect-AzureRmAccount' has been removed.","Add parameter set 'ServicePrincipalWithSubscriptionId' back to cmdlet 'Connect-AzureRmAccount'."
3-
"Microsoft.Azure.Commands.Profile.dll","Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand","Connect-AzureRmAccount","0","1050","The parameter set 'ServicePrincipalCertificateWithSubscriptionId' for cmdlet 'Connect-AzureRmAccount' has been removed.","Add parameter set 'ServicePrincipalCertificateWithSubscriptionId' back to cmdlet 'Connect-AzureRmAccount'."
1+
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
2-
"Microsoft.Azure.Commands.Profile.dll","Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand","Connect-AzureRmAccount","0","1050","The parameter set 'ServicePrincipalWithSubscriptionId' for cmdlet 'Connect-AzureRmAccount' has been removed.","Add parameter set 'ServicePrincipalWithSubscriptionId' back to cmdlet 'Connect-AzureRmAccount'."
3-
"Microsoft.Azure.Commands.Profile.dll","Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand","Connect-AzureRmAccount","0","1050","The parameter set 'ServicePrincipalCertificateWithSubscriptionId' for cmdlet 'Connect-AzureRmAccount' has been removed.","Add parameter set 'ServicePrincipalCertificateWithSubscriptionId' back to cmdlet 'Connect-AzureRmAccount'."
1+
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"

tools/StaticAnalysis/StaticAnalysis.Test/BreakingChangeAnalyzerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,5 +832,19 @@ public void ChangeValidateRangeMaximum()
832832
.Where<int>((problemId) => problemId.Equals(BreakingChangeProblemId.ChangedValidateRangeMaximum))
833833
.SingleOrDefault<int>().Equals(BreakingChangeProblemId.ChangedValidateRangeMaximum));
834834
}
835+
836+
[Fact]
837+
[Trait(Category.AcceptanceType, Category.CheckIn)]
838+
public void ParameterReplacedByAlias()
839+
{
840+
cmdletBreakingChangeAnalyzer.Analyze(
841+
new List<string> { _testCmdletDirPath },
842+
((dirList) => { return new List<string> { _testCmdletDirPath }; }),
843+
(cmdletName) => cmdletName.Equals("Test-ParameterReplacedByAlias", StringComparison.OrdinalIgnoreCase));
844+
845+
AnalysisReport testReport = cmdletBreakingChangeAnalyzer.GetAnalysisReport();
846+
847+
Assert.Equal(0, testReport.ProblemIdList.Count);
848+
}
835849
}
836850
}

tools/StaticAnalysis/StaticAnalysis.Test/TestCmdlets/BreakingChangeAnalyzer_Cmdlet.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ namespace StaticAnalysis.Test.CmdletTest.BreakingChange.ChangeOutputGenericTypeA
477477
using System.Collections.Generic;
478478
using System.Management.Automation;
479479

480-
[Cmdlet(VerbsDiagnostic.Test, "ChangeOutputGenericTypeArgument"), OutputType(typeof(string))]
480+
[Cmdlet(VerbsDiagnostic.Test, "ChangeOutputGenericTypeArgument"), OutputType(typeof(List<string>))]
481481
public class TestChangeOutputGenericTypeArgument : Cmdlet
482482
{
483483
protected override void BeginProcessing()
@@ -758,4 +758,24 @@ protected override void BeginProcessing()
758758
WriteInformation("Info", null);
759759
}
760760
}
761+
}
762+
763+
namespace StaticAnalysis.Test.CmdletTest.BreakingChange.ParameterReplacedByAlias
764+
{
765+
using System.Collections.Generic;
766+
using System.Management.Automation;
767+
768+
[Cmdlet(VerbsDiagnostic.Test, "ParameterReplacedByAlias")]
769+
public class TestDifferentGenericTypeArgumentSize : Cmdlet
770+
{
771+
[Parameter(Mandatory = true)]
772+
[Alias("Parameter")]
773+
public string Param { get; set; }
774+
775+
protected override void BeginProcessing()
776+
{
777+
WriteObject("Test-ParameterReplacedByAlias BeginProcessing()");
778+
WriteInformation("Info", null);
779+
}
780+
}
761781
}

0 commit comments

Comments
 (0)