From 7412976b4c8db42c5a2bc28dab16af6367e9e6a6 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav B <ajbaaska@microsoft.com> Date: Mon, 6 Jul 2020 14:35:10 -0700 Subject: [PATCH] Update Roslyn package versions (#23630) * Update Roslyn package versions * Fixes * Fix analyzer warnings * Fix root cause for analyzer warnings * Fixed RuntimeCompilation test * Add back nowarns --- eng/Versions.props | 6 +++--- src/Analyzers/Analyzers/src/MiddlewareAnalyzer.cs | 4 ++-- src/Analyzers/Analyzers/src/ServicesAnalyzer.cs | 4 ++-- .../Analyzers/src/StartupAnalyzer.Diagnostics.cs | 1 + src/Analyzers/Analyzers/src/StartupFacts.cs | 9 ++------- src/Components/Analyzers/src/DiagnosticDescriptors.cs | 1 + src/Mvc/Mvc.Analyzers/src/DiagnosticDescriptors.cs | 1 + ...nsDoNotRequireExplicitModelValidationCheckAnalyzer.cs | 2 ++ .../Mvc.Api.Analyzers/src/ApiDiagnosticDescriptors.cs | 1 + .../test/RuntimeViewCompilerTest.cs | 2 +- .../Language/IntegrationTests/IntegrationTestBase.cs | 2 +- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 99fd5d6f4ec..7db7ce79406 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -185,9 +185,9 @@ <MicrosoftBuildFrameworkPackageVersion>15.8.166</MicrosoftBuildFrameworkPackageVersion> <MicrosoftBuildLocatorPackageVersion>1.2.6</MicrosoftBuildLocatorPackageVersion> <MicrosoftBuildUtilitiesCorePackageVersion>15.8.166</MicrosoftBuildUtilitiesCorePackageVersion> - <MicrosoftCodeAnalysisCommonPackageVersion>3.4.0</MicrosoftCodeAnalysisCommonPackageVersion> - <MicrosoftCodeAnalysisCSharpPackageVersion>3.4.0</MicrosoftCodeAnalysisCSharpPackageVersion> - <MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.4.0</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion> + <MicrosoftCodeAnalysisCommonPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCommonPackageVersion> + <MicrosoftCodeAnalysisCSharpPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCSharpPackageVersion> + <MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion> <MicrosoftIdentityModelClientsActiveDirectoryPackageVersion>3.19.8</MicrosoftIdentityModelClientsActiveDirectoryPackageVersion> <MicrosoftIdentityModelLoggingPackageVersion>6.6.0</MicrosoftIdentityModelLoggingPackageVersion> <MicrosoftIdentityModelProtocolsOpenIdConnectPackageVersion>6.6.0</MicrosoftIdentityModelProtocolsOpenIdConnectPackageVersion> diff --git a/src/Analyzers/Analyzers/src/MiddlewareAnalyzer.cs b/src/Analyzers/Analyzers/src/MiddlewareAnalyzer.cs index 0a8deb5dc4b..1395969e103 100644 --- a/src/Analyzers/Analyzers/src/MiddlewareAnalyzer.cs +++ b/src/Analyzers/Analyzers/src/MiddlewareAnalyzer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Analyzers if (context.Operation is IInvocationOperation invocation && invocation.Instance == null && invocation.Arguments.Length >= 1 && - invocation.Arguments[0].Parameter?.Type == _context.StartupSymbols.IApplicationBuilder) + SymbolEqualityComparer.Default.Equals(invocation.Arguments[0].Parameter?.Type, _context.StartupSymbols.IApplicationBuilder)) { middleware.Add(new MiddlewareItem(invocation)); } diff --git a/src/Analyzers/Analyzers/src/ServicesAnalyzer.cs b/src/Analyzers/Analyzers/src/ServicesAnalyzer.cs index dc79cf47279..ac74481a885 100644 --- a/src/Analyzers/Analyzers/src/ServicesAnalyzer.cs +++ b/src/Analyzers/Analyzers/src/ServicesAnalyzer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Analyzers if (context.Operation is IInvocationOperation invocation && invocation.Instance == null && invocation.Arguments.Length >= 1 && - invocation.Arguments[0].Parameter?.Type == _context.StartupSymbols.IServiceCollection) + SymbolEqualityComparer.Default.Equals(invocation.Arguments[0].Parameter?.Type, _context.StartupSymbols.IServiceCollection)) { services.Add(new ServicesItem(invocation)); } diff --git a/src/Analyzers/Analyzers/src/StartupAnalyzer.Diagnostics.cs b/src/Analyzers/Analyzers/src/StartupAnalyzer.Diagnostics.cs index 0ba7239936c..cb2f50997ee 100644 --- a/src/Analyzers/Analyzers/src/StartupAnalyzer.Diagnostics.cs +++ b/src/Analyzers/Analyzers/src/StartupAnalyzer.Diagnostics.cs @@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Analyzers { public partial class StartupAnalyzer : DiagnosticAnalyzer { + [System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] internal static class Diagnostics { public static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics; diff --git a/src/Analyzers/Analyzers/src/StartupFacts.cs b/src/Analyzers/Analyzers/src/StartupFacts.cs index f5f833429a6..3c5bc9ee9a4 100644 --- a/src/Analyzers/Analyzers/src/StartupFacts.cs +++ b/src/Analyzers/Analyzers/src/StartupFacts.cs @@ -74,12 +74,7 @@ namespace Microsoft.AspNetCore.Analyzers return false; } - if (symbol.Parameters[0].Type != symbols.IServiceCollection) - { - return false; - } - - return true; + return SymbolEqualityComparer.Default.Equals(symbol.Parameters[0].Type, symbols.IServiceCollection); } // Based on StartupLoader. The philosophy is that we want to do analysis only on things @@ -114,7 +109,7 @@ namespace Microsoft.AspNetCore.Analyzers // IApplicationBuilder can appear in any parameter, but must appear. for (var i = 0; i < symbol.Parameters.Length; i++) { - if (symbol.Parameters[i].Type == symbols.IApplicationBuilder) + if (SymbolEqualityComparer.Default.Equals(symbol.Parameters[i].Type, symbols.IApplicationBuilder)) { return true; } diff --git a/src/Components/Analyzers/src/DiagnosticDescriptors.cs b/src/Components/Analyzers/src/DiagnosticDescriptors.cs index 05b98d3b4af..8b4bfdb1544 100644 --- a/src/Components/Analyzers/src/DiagnosticDescriptors.cs +++ b/src/Components/Analyzers/src/DiagnosticDescriptors.cs @@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.Components.Analyzers { + [System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] internal static class DiagnosticDescriptors { // Note: The Razor Compiler (including Components features) use the RZ prefix for diagnostics, so there's currently diff --git a/src/Mvc/Mvc.Analyzers/src/DiagnosticDescriptors.cs b/src/Mvc/Mvc.Analyzers/src/DiagnosticDescriptors.cs index 76b068a9289..8c374422f8c 100644 --- a/src/Mvc/Mvc.Analyzers/src/DiagnosticDescriptors.cs +++ b/src/Mvc/Mvc.Analyzers/src/DiagnosticDescriptors.cs @@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.Mvc.Analyzers { + [System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] public static class DiagnosticDescriptors { public static readonly DiagnosticDescriptor MVC1000_HtmlHelperPartialShouldBeAvoided = diff --git a/src/Mvc/Mvc.Api.Analyzers/src/ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs b/src/Mvc/Mvc.Api.Analyzers/src/ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs index 274609128f3..d884ed3504c 100644 --- a/src/Mvc/Mvc.Api.Analyzers/src/ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs +++ b/src/Mvc/Mvc.Api.Analyzers/src/ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs @@ -84,7 +84,9 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers return; } +#pragma warning disable RS1030 // Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer var semanticModel = operationAnalysisContext.Compilation.GetSemanticModel(methodSyntax.SyntaxTree); +#pragma warning restore RS1030 // Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer var methodSymbol = semanticModel.GetDeclaredSymbol(methodSyntax, operationAnalysisContext.CancellationToken); if (!ApiControllerFacts.IsApiControllerAction(symbolCache, methodSymbol)) diff --git a/src/Mvc/Mvc.Api.Analyzers/src/ApiDiagnosticDescriptors.cs b/src/Mvc/Mvc.Api.Analyzers/src/ApiDiagnosticDescriptors.cs index ff56f64f1c6..da4184604c1 100644 --- a/src/Mvc/Mvc.Api.Analyzers/src/ApiDiagnosticDescriptors.cs +++ b/src/Mvc/Mvc.Api.Analyzers/src/ApiDiagnosticDescriptors.cs @@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.Mvc.Api.Analyzers { + [System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] internal static class ApiDiagnosticDescriptors { public static readonly DiagnosticDescriptor API1000_ActionReturnsUndocumentedStatusCode = diff --git a/src/Mvc/Mvc.Razor.RuntimeCompilation/test/RuntimeViewCompilerTest.cs b/src/Mvc/Mvc.Razor.RuntimeCompilation/test/RuntimeViewCompilerTest.cs index e9f22da610a..6c916309dc6 100644 --- a/src/Mvc/Mvc.Razor.RuntimeCompilation/test/RuntimeViewCompilerTest.cs +++ b/src/Mvc/Mvc.Razor.RuntimeCompilation/test/RuntimeViewCompilerTest.cs @@ -765,7 +765,7 @@ this should fail"; // Arrange var viewPath = "some-relative-path"; var fileContent = "file content"; - var content = "this should fail"; + var content = "public class Bad { this should fail }"; var compiler = GetViewCompiler(new TestFileProvider()); var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create(fileContent, viewPath)); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs index 4cb0df598b2..02024ecb1d4 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests protected CSharpSyntaxTree AddCSharpSyntaxTree(string text, string? filePath = null) { - var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(text, CSharpParseOptions, path: filePath); + var syntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(text, CSharpParseOptions, path: filePath ?? string.Empty); CSharpSyntaxTrees.Add(syntaxTree); return syntaxTree; } -- GitLab