diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d0f72c26..46beac7d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,7 +23,7 @@ variables: steps: - task: UseDotNet@2 inputs: - version: '6.x' + version: '7.x' - task: DotNetCoreCLI@2 displayName: 'Build' diff --git a/src/Analyzer.BicepProcessor/Analyzer.BicepProcessor.csproj b/src/Analyzer.BicepProcessor/Analyzer.BicepProcessor.csproj index a7d071a0..61ea9dfb 100644 --- a/src/Analyzer.BicepProcessor/Analyzer.BicepProcessor.csproj +++ b/src/Analyzer.BicepProcessor/Analyzer.BicepProcessor.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Analyzer.BicepProcessor/BicepTemplateProcessor.cs b/src/Analyzer.BicepProcessor/BicepTemplateProcessor.cs index 7b83e6d3..18021637 100644 --- a/src/Analyzer.BicepProcessor/BicepTemplateProcessor.cs +++ b/src/Analyzer.BicepProcessor/BicepTemplateProcessor.cs @@ -20,11 +20,13 @@ using Bicep.Core.Semantics.Namespaces; using Bicep.Core.Syntax; using Bicep.Core.Text; -using Bicep.Core.TypeSystem.Az; +using Bicep.Core.TypeSystem.Providers; +using Bicep.Core.Utils; using Bicep.Core.Workspaces; using Microsoft.Extensions.DependencyInjection; -using Microsoft.WindowsAzure.ResourceStack.Common.Extensions; +using BicepEnvironment = Bicep.Core.Utils.Environment; using IOFileSystem = System.IO.Abstractions.FileSystem; +using SysEnvironment = System.Environment; namespace Microsoft.Azure.Templates.Analyzer.BicepProcessor { @@ -40,17 +42,18 @@ public static class BicepTemplateProcessor /// public static IServiceCollection AddBicepCore(this IServiceCollection services) => services .AddSingleton() - .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() // needed for below .AddSingleton() // enable source mapping .AddSingleton() @@ -85,14 +88,14 @@ public static (string, BicepMetadata) ConvertBicepToJson(string bicepPath) var bicepIssues = emitResult.Diagnostics .Where(diag => diag.Level == DiagnosticLevel.Error) .Select(diag => diag.Message); - throw new Exception($"Bicep issues found:{Environment.NewLine}{string.Join(Environment.NewLine, bicepIssues)}"); + throw new Exception($"Bicep issues found:{SysEnvironment.NewLine}{string.Join(SysEnvironment.NewLine, bicepIssues)}"); } string GetPathRelativeToEntryPoint(string absolutePath) => Path.GetRelativePath( Path.GetDirectoryName(compilation.SourceFileGrouping.EntryPoint.FileUri.AbsolutePath), absolutePath); // Collect all needed module info from SourceFileGrouping metadata - var moduleInfo = compilation.SourceFileGrouping.UriResultByArtifactReference.Select(sourceFileAndMetadata => + var moduleInfo = compilation.SourceFileGrouping.FileUriResultByArtifactReference.Select(sourceFileAndMetadata => { var bicepSourceFile = sourceFileAndMetadata.Key as BicepSourceFile; var pathRelativeToEntryPoint = GetPathRelativeToEntryPoint(bicepSourceFile.FileUri.AbsolutePath); diff --git a/src/Analyzer.BicepProcessor/SourceMapFeatureProvider.cs b/src/Analyzer.BicepProcessor/SourceMapFeatureProvider.cs index b44cb761..9bef1a70 100644 --- a/src/Analyzer.BicepProcessor/SourceMapFeatureProvider.cs +++ b/src/Analyzer.BicepProcessor/SourceMapFeatureProvider.cs @@ -76,5 +76,11 @@ public SourceMapFeatureProvider(IFeatureProvider features) /// public bool PublishSourceEnabled => features.PublishSourceEnabled; + + /// + public bool ProviderRegistryEnabled => features.ProviderRegistryEnabled; + + /// + public bool OptionalModuleNamesEnabled => features.OptionalModuleNamesEnabled; } } diff --git a/src/Analyzer.JsonRuleEngine.UnitTests/JsonRuleEngineTests.cs b/src/Analyzer.JsonRuleEngine.UnitTests/JsonRuleEngineTests.cs index 4cf866b8..da16080d 100644 --- a/src/Analyzer.JsonRuleEngine.UnitTests/JsonRuleEngineTests.cs +++ b/src/Analyzer.JsonRuleEngine.UnitTests/JsonRuleEngineTests.cs @@ -372,6 +372,12 @@ public void FilterRules_ConfigurationIsNull_ExceptionIsThrown() ""ids"": [""RuleId0""] } }", "RuleId0", DisplayName = "Only Id RuleId0")] + [DataRow(@"{ + ""inclusions"": {}, + ""exclusions"": { + ""ids"": [""RuleId3""] + } + }", "RuleId0", "RuleId1", "RuleId2", "RuleId4", DisplayName = "Empty inclusions object, exclude RuleId3")] [DataRow(@"{ ""exclusions"": { ""ids"": [""RuleId3""] @@ -412,6 +418,20 @@ public void FilterRules_ConfigurationIsNull_ExceptionIsThrown() ""ids"": [""RuleId2""] } }", "RuleId2", "RuleId3", "RuleId4", DisplayName = "Include Severity 3; Exclusions object is ignored")] + [DataRow(@"{ + ""exclusions"": {}, + ""inclusions"": { + ""ids"": [""RuleId3""] + } + }", "RuleId3", DisplayName = "Empty exclusions object listed first, include RuleId3; Exclusions object is ignored")] + [DataRow(@"{ + ""exclusions"": { + ""ids"": [""RuleId3""] + }, + ""inclusions"": { + ""ids"": [""RuleId3""] + } + }", "RuleId3", DisplayName = "Exclusions object listed first, include RuleId3; Exclusions object is ignored")] [DataRow(@"{ ""inclusions"": { ""severity"": [1] diff --git a/src/Analyzer.JsonRuleEngine/JsonRuleEngine.cs b/src/Analyzer.JsonRuleEngine/JsonRuleEngine.cs index 3ed51bbb..fa5c7bfb 100644 --- a/src/Analyzer.JsonRuleEngine/JsonRuleEngine.cs +++ b/src/Analyzer.JsonRuleEngine/JsonRuleEngine.cs @@ -64,7 +64,8 @@ public void FilterRules(ConfigurationDefinition configuration) if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - if (configuration.InclusionsConfigurationDefinition != null) + if (configuration.InclusionsConfigurationDefinition?.Severity != null + || configuration.InclusionsConfigurationDefinition?.Ids != null) { var includeSeverities = configuration.InclusionsConfigurationDefinition.Severity; var includeIds = configuration.InclusionsConfigurationDefinition.Ids; @@ -72,7 +73,8 @@ public void FilterRules(ConfigurationDefinition configuration) RuleDefinitions = RuleDefinitions.Where(r => (includeSeverities != null && includeSeverities.Contains(r.Severity)) || (includeIds != null && includeIds.Contains(r.Id))).ToList().AsReadOnly(); } - else if (configuration.ExclusionsConfigurationDefinition != null) + else if (configuration.ExclusionsConfigurationDefinition?.Severity != null + || configuration.ExclusionsConfigurationDefinition?.Ids != null) { var excludeSeverities = configuration.ExclusionsConfigurationDefinition.Severity; var excludeIds = configuration.ExclusionsConfigurationDefinition.Ids;