Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the check rules for UX metadata #20647

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{
"name":"-ResourceGroupName",
"value":"[path.resourceGroupName]"
},
{
"name":"-Name",
"value":"[path.containerGroupName]"
}
]
}
Expand Down
1 change: 0 additions & 1 deletion tools/ExecuteCIStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ If ($StaticAnalysisUX)
If ("" -Ne $UXModuleList)
{
Write-Host "Running static analysis for UX metadata..."
.("$PSScriptRoot/StaticAnalysis/UXMetadataAnalyzer/PrepareUXMetadata.ps1") -RepoArtifacts $RepoArtifacts -Configuration $Configuration
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers ux -u -m $UXModuleList
}
Return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Module","Severity","ResourceType","SubResourceType","Command","Description"
"Az.Compute","1","Microsoft.Compute","virtualMachineScaleSets","Stop-AzVmss","The value of -StayProvisioned is not defined."
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"Module","Severity","ResourceType","SubResourceType","Command","Description"
"Az.KeyVault","1","Microsoft.KeyVault","vaults","Get-AzKeyVaultKey","resourceGroupName is defined in path but cannot find in example"
"Az.KeyVault","1","Microsoft.KeyVault","vaults","Get-AzKeyVaultCertificate","resourceGroupName is defined in path but cannot find in example"
"Az.KeyVault","1","Microsoft.KeyVault","vaults","Get-AzKeyVaultSecret","resourceGroupName is defined in path but cannot find in example"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Module","Severity","ResourceType","SubResourceType","Command","Description"
"Az.RedisEnterpriseCache","1","Microsoft.Cache","redisEnterprise-databases","Invoke-AzRedisEnterpriseCacheForceDatabaseUnlink","Cannot find a matched parameter set for example of Invoke-AzRedisEnterpriseCacheForceDatabaseUnlink"
"Az.RedisEnterpriseCache","1","Microsoft.Cache","redisEnterprise-databases","Invoke-AzRedisEnterpriseCacheForceDatabaseUnlink","databaseName is defined in path but cannot find in example"
66 changes: 0 additions & 66 deletions tools/StaticAnalysis/UXMetadataAnalyzer/PrepareUXMetadata.ps1

This file was deleted.

27 changes: 16 additions & 11 deletions tools/StaticAnalysis/UXMetadataAnalyzer/UXMetadataAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,19 @@ public void Analyze(
continue;
}
string moduleName = Path.GetFileName(directory);

string moduleFolder = Path.Combine(savedDirectory, "src", moduleName.Replace("Az.", ""));
Directory.SetCurrentDirectory(directory);

var moduleMetadata = MetadataLoader.GetModuleMetadata(moduleName);

string UXFolder = Path.Combine(directory, "UX");
if (!Directory.Exists(UXFolder))
{
continue;
}

var UXMetadataPathList = Directory.EnumerateFiles(UXFolder, "*.json", SearchOption.AllDirectories);
foreach (var UXMetadataPath in UXMetadataPathList)
string[] UXFolders = Directory.GetDirectories(moduleFolder, "UX", SearchOption.AllDirectories);
foreach (var UXFolder in UXFolders)
{
ValidateUXMetadata(moduleName, UXMetadataPath, moduleMetadata, issueLogger);
var UXMetadataPathList = Directory.EnumerateFiles(UXFolder, "*.json", SearchOption.AllDirectories);
foreach (var UXMetadataPath in UXMetadataPathList)
{
ValidateUXMetadata(moduleName, UXMetadataPath, moduleMetadata, issueLogger);
}
}
Directory.SetCurrentDirectory(savedDirectory);
}
Expand Down Expand Up @@ -261,8 +259,15 @@ private void ValidateParametersDefinedInPathContainsInExample(IssueLoggerContext
private void ValidateParametersInExampleDefinedInPath(IssueLoggerContext context, HashSet<string> parametersFromHttpPath, UXMetadataCommandExample example, ReportLogger<UXMetadataIssue> issueLogger)
{
var exampleParameterPathRegex = new Regex(@"path\.([\w]+)");
foreach (string parameterInExample in example.Parameters.Select(x => x.Value))
foreach (var parameter in example.Parameters)
{
string parameterInExample = parameter.Value;
if (parameterInExample == null)
{
string description = string.Format("The value of {0} is not defined.", parameter.Name);
issueLogger.LogUXMetadataIssue(context, 1, description);
continue;
}
var match = exampleParameterPathRegex.Match(parameterInExample);
if (!match.Success)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/StaticAnalysis/UXMetadataAnalyzer/UXMetadataIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public bool Match(IReportRecord other)

public IReportRecord Parse(string line)
{
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\"";
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]*)\",\"([^\"]+)\"";
var match = Regex.Match(line, matcher);
if (!match.Success || match.Groups.Count < 7)
{
Expand Down