diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0932e7bdc..f0c69f600 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,8 @@ jobs: - id: compute-version name: Compute version run: | - $(Invoke-WebRequest "https://www.nuget.org/api/v2/package/Meziantou.Analyzer/").BaseResponse.RequestMessage.RequestUri -match "meziantou\.analyzer\.2\.0\.([0-9]+).nupkg" - $NewVersion = "2.0.$([int]$Matches.1 + 1)" + $(Invoke-WebRequest "https://www.nuget.org/api/v2/package/Meziantou.Analyzer/").BaseResponse.RequestMessage.RequestUri -match "meziantou\.analyzer\.3\.0\.([0-9]+).nupkg" + $NewVersion = "3.0.$([int]$Matches.1 + 1)" if ($env:GITHUB_REF -ne 'refs/heads/main') { $NewVersion = $NewVersion + '-build.${{ github.run_id }}' } @@ -66,9 +66,6 @@ jobs: - run: dotnet run --project src/ListDotNetTypes/ListDotNetTypes.csproj -- src/Meziantou.Analyzer/Resources/ - - run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn3.8 /p:Version=${{ needs.compute_package_version.outputs.package_version }} /bl:Meziantou.Analyzer.roslyn3.8.binlog - - run: dotnet build src/Meziantou.Analyzer.CodeFixers/Meziantou.Analyzer.CodeFixers.csproj --configuration Release /p:RoslynVersion=roslyn3.8 /p:Version=${{ needs.compute_package_version.outputs.package_version }} /bl:Meziantou.Analyzer.CodeFixers.roslyn3.8.binlog - - run: dotnet build src/Meziantou.Analyzer/Meziantou.Analyzer.csproj --configuration Release /p:RoslynVersion=roslyn4.2 /p:Version=${{ needs.compute_package_version.outputs.package_version }} /bl:Meziantou.Analyzer.roslyn4.2.binlog - run: dotnet build src/Meziantou.Analyzer.CodeFixers/Meziantou.Analyzer.CodeFixers.csproj --configuration Release /p:RoslynVersion=roslyn4.2 /p:Version=${{ needs.compute_package_version.outputs.package_version }} /bl:Meziantou.Analyzer.CodeFixers.roslyn4.2.binlog @@ -137,7 +134,7 @@ jobs: matrix: runs-on: [ ubuntu-latest ] configuration: [ Release ] - roslyn-version: [ 'roslyn3.8', 'roslyn4.2', 'roslyn4.4', 'roslyn4.6', 'roslyn4.8', 'roslyn4.14', 'default' ] + roslyn-version: [ 'roslyn4.2', 'roslyn4.4', 'roslyn4.6', 'roslyn4.8', 'roslyn4.14', 'default' ] fail-fast: false steps: - uses: actions/checkout@v4 diff --git a/Directory.Build.targets b/Directory.Build.targets index e1195bb21..6c3714700 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -6,19 +6,6 @@ - - - - - - - - $(DefineConstants);ROSLYN_3_8 - $(DefineConstants);CSHARP9_OR_GREATER - $(NoWarn);nullable - - - diff --git a/src/Meziantou.Analyzer.CodeFixers/Internals/DocumentBasedFixAllProvider.cs b/src/Meziantou.Analyzer.CodeFixers/Internals/DocumentBasedFixAllProvider.cs deleted file mode 100644 index 15d9a9199..000000000 --- a/src/Meziantou.Analyzer.CodeFixers/Internals/DocumentBasedFixAllProvider.cs +++ /dev/null @@ -1,112 +0,0 @@ -#if ROSLYN_3_8 -#pragma warning disable IDE0130 // Namespace does not match folder structure -// File initially copied from -// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/4d9b3e3bb785a55f73b3029a843f0c0b73cc9ea7/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/DocumentBasedFixAllProvider.cs -// Original copyright statement: -// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Threading.Tasks; -using Meziantou.Analyzer.Internals; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CodeFixes; - -namespace Meziantou.Analyzer; - -/// -/// Provides a base class to write a that fixes documents independently. -/// -internal abstract class DocumentBasedFixAllProvider : FixAllProvider -{ - protected abstract string GetFixAllTitle(FixAllContext fixAllContext); - - public override Task GetFixAsync(FixAllContext fixAllContext) - { - return Task.FromResult(fixAllContext.Scope switch - { - FixAllScope.Document => CodeAction.Create( - GetFixAllTitle(fixAllContext), - cancellationToken => GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)), - nameof(DocumentBasedFixAllProvider)), - FixAllScope.Project => CodeAction.Create( - GetFixAllTitle(fixAllContext), - cancellationToken => GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken), fixAllContext.Project), - nameof(DocumentBasedFixAllProvider)), - FixAllScope.Solution => CodeAction.Create( - GetFixAllTitle(fixAllContext), - cancellationToken => GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)), - nameof(DocumentBasedFixAllProvider)), - _ => null, - }); - } - - /// - /// Fixes all occurrences of a diagnostic in a specific document. - /// - /// The context for the Fix All operation. - /// The document to fix. - /// The diagnostics to fix in the document. - /// - /// The new representing the root of the fixed document. - /// -or- - /// , if no changes were made to the document. - /// - protected abstract Task FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray diagnostics); - - private async Task GetDocumentFixesAsync(FixAllContext fixAllContext) - { - var document = fixAllContext.Document!; - var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false); - if (!documentDiagnosticsToFix.TryGetValue(document, out var diagnostics)) - { - return document; - } - - var newDocument = await FixAllAsync(fixAllContext, document, diagnostics).ConfigureAwait(false); - return newDocument ?? document; - } - - private async Task GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray documents) - { - var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false); - - var solution = fixAllContext.Solution; - var newDocuments = new List>(documents.Length); - foreach (var document in documents) - { - if (!documentDiagnosticsToFix.TryGetValue(document, out var diagnostics)) - { - newDocuments.Add(Task.FromResult(document)); - continue; - } - - newDocuments.Add(FixAllAsync(fixAllContext, document, diagnostics)); - } - - for (var i = 0; i < documents.Length; i++) - { - var newDocumentRoot = await newDocuments[i].ConfigureAwait(false); - if (newDocumentRoot is null) - continue; - - //solution = solution.WithDocumentSyntaxRoot(documents[i].Id, newDocumentRoot); - } - - return solution; - } - - private Task GetProjectFixesAsync(FixAllContext fixAllContext, Project project) - { - return GetSolutionFixesAsync(fixAllContext, project.Documents.ToImmutableArray()); - } - - private Task GetSolutionFixesAsync(FixAllContext fixAllContext) - { - var documents = fixAllContext.Solution.Projects.SelectMany(i => i.Documents).ToImmutableArray(); - return GetSolutionFixesAsync(fixAllContext, documents); - } -} -#endif diff --git a/src/Meziantou.Analyzer.CodeFixers/Rules/ReplaceEnumToStringWithNameofFixer.cs b/src/Meziantou.Analyzer.CodeFixers/Rules/ReplaceEnumToStringWithNameofFixer.cs index 8000eb42f..b4ccf5f70 100644 --- a/src/Meziantou.Analyzer.CodeFixers/Rules/ReplaceEnumToStringWithNameofFixer.cs +++ b/src/Meziantou.Analyzer.CodeFixers/Rules/ReplaceEnumToStringWithNameofFixer.cs @@ -8,10 +8,6 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Operations; -#if ROSLYN_3_8 -using System.Linq; -#endif - namespace Meziantou.Analyzer.Rules; [ExportCodeFixProvider(LanguageNames.CSharp), Shared] diff --git a/src/Meziantou.Analyzer.Pack/Meziantou.Analyzer.Pack.csproj b/src/Meziantou.Analyzer.Pack/Meziantou.Analyzer.Pack.csproj index 115183275..e906affbb 100644 --- a/src/Meziantou.Analyzer.Pack/Meziantou.Analyzer.Pack.csproj +++ b/src/Meziantou.Analyzer.Pack/Meziantou.Analyzer.Pack.csproj @@ -23,9 +23,6 @@ - - - diff --git a/src/Meziantou.Analyzer/Internals/CompilationExtensions.cs b/src/Meziantou.Analyzer/Internals/CompilationExtensions.cs index a8632b95a..2ddb3237b 100644 --- a/src/Meziantou.Analyzer/Internals/CompilationExtensions.cs +++ b/src/Meziantou.Analyzer/Internals/CompilationExtensions.cs @@ -1,7 +1,4 @@ -#if ROSLYN_3_8 -using System.Collections.Immutable; -#endif -using System.Diagnostics; +using System.Diagnostics; using Microsoft.CodeAnalysis; namespace Meziantou.Analyzer.Internals; @@ -15,33 +12,6 @@ public static bool IsNet9OrGreater(this Compilation compilation) return version.Major >= 9; } -#if ROSLYN_3_8 - public static ImmutableArray GetTypesByMetadataName(this Compilation compilation, string typeMetadataName) - { - var result = ImmutableArray.CreateBuilder(); - var symbol = compilation.Assembly.GetTypeByMetadataName(typeMetadataName); - if (symbol != null) - { - result.Add(symbol); - } - - foreach (var reference in compilation.References) - { - var assemblySymbol = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; - if (assemblySymbol == null) - continue; - - symbol = assemblySymbol.GetTypeByMetadataName(typeMetadataName); - if (symbol != null) - { - result.Add(symbol); - } - } - - return result.ToImmutable(); - } -#endif - // Copy from https://github.com/dotnet/roslyn/blob/d2ff1d83e8fde6165531ad83f0e5b1ae95908289/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/CompilationExtensions.cs#L11-L68 /// /// Gets a type by its metadata name to use for code analysis within a . This method diff --git a/src/Meziantou.Analyzer/Internals/OperationExtensions.cs b/src/Meziantou.Analyzer/Internals/OperationExtensions.cs index a4dfbe883..62f4033a3 100644 --- a/src/Meziantou.Analyzer/Internals/OperationExtensions.cs +++ b/src/Meziantou.Analyzer/Internals/OperationExtensions.cs @@ -12,11 +12,6 @@ public static IOperation.OperationList GetChildOperations(this IOperation operat { return operation.ChildOperations; } -#elif ROSLYN_3_8 - public static IEnumerable GetChildOperations(this IOperation operation) - { - return operation.Children; - } #endif public static LanguageVersion GetCSharpLanguageVersion(this IOperation operation) diff --git a/src/Meziantou.Analyzer/Rules/ReplaceEnumToStringWithNameofAnalyzer.cs b/src/Meziantou.Analyzer/Rules/ReplaceEnumToStringWithNameofAnalyzer.cs index 129c73900..46acb416b 100644 --- a/src/Meziantou.Analyzer/Rules/ReplaceEnumToStringWithNameofAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/ReplaceEnumToStringWithNameofAnalyzer.cs @@ -4,10 +4,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Operations; -#if ROSLYN_3_8 -using System.Linq; -#endif - namespace Meziantou.Analyzer.Rules; [DiagnosticAnalyzer(LanguageNames.CSharp)] diff --git a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs index c184dd453..306dbbc37 100755 --- a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs +++ b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs @@ -325,11 +325,6 @@ private async Task GetSortedDiagnosticsFromDocuments(IList