diff --git a/ChangeLog.md b/ChangeLog.md index 0b03d8dace..350b05b96f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix analyzer [RCS1019](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1019) ([PR](https://github.com/dotnet/roslynator/pull/1402)) - Fix analyzer [RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250) ([PR](https://github.com/dotnet/roslynator/pull/1403), [PR](https://github.com/dotnet/roslynator/pull/1404)) - Fix code fix for [CS8600](https://josefpihrt.github.io/docs/roslynator/fixes/CS8600) changing the wrong type when casts or `var` are involved ([PR](https://github.com/dotnet/roslynator/pull/1393) by @jroessel) +- Fix Roslyn multi-targeting ([PR](https://github.com/dotnet/roslynator/pull/1407)) ## [4.10.0] - 2024-01-24 diff --git a/src/Analyzers.CodeFixes/CSharp/CodeFixes/RawStringLiteralCodeFixProvider.cs b/src/Analyzers.CodeFixes/CSharp/CodeFixes/RawStringLiteralCodeFixProvider.cs index 8c6f2f3974..9f44fdbf24 100644 --- a/src/Analyzers.CodeFixes/CSharp/CodeFixes/RawStringLiteralCodeFixProvider.cs +++ b/src/Analyzers.CodeFixes/CSharp/CodeFixes/RawStringLiteralCodeFixProvider.cs @@ -1,5 +1,4 @@ -#if ROSLYN_4_2 -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; using System.Composition; @@ -33,6 +32,7 @@ public override ImmutableArray FixableDiagnosticIds public override async Task RegisterCodeFixesAsync(CodeFixContext context) { +#if ROSLYN_4_2 SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out SyntaxNode node, predicate: f => f.IsKind(SyntaxKind.StringLiteralExpression, SyntaxKind.InterpolatedStringExpression))) @@ -83,8 +83,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix(codeAction, diagnostic); } } +#else + await Task.CompletedTask; +#endif } +#if ROSLYN_4_2 private static Task RefactorAsync( Document document, LiteralExpressionSyntax literalExpression, @@ -221,5 +225,5 @@ private static Task UseRawStringLiteralAsync( return document.WithTextChangeAsync(interpolatedString.Span, sb.ToString(), cancellationToken); } -} #endif +} diff --git a/src/Analyzers/CSharp/Analysis/UnnecessaryRawStringLiteralAnalyzer.cs b/src/Analyzers/CSharp/Analysis/UnnecessaryRawStringLiteralAnalyzer.cs index 1981ddb5f8..11afe77350 100644 --- a/src/Analyzers/CSharp/Analysis/UnnecessaryRawStringLiteralAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/UnnecessaryRawStringLiteralAnalyzer.cs @@ -1,5 +1,4 @@ -#if ROSLYN_4_2 -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; using Microsoft.CodeAnalysis; @@ -26,10 +25,10 @@ public override ImmutableArray SupportedDiagnostics } } +#if ROSLYN_4_2 public override void Initialize(AnalysisContext context) { base.Initialize(context); - context.RegisterCompilationStartAction(startContext => { if (((CSharpCompilation)startContext.Compilation).LanguageVersion >= LanguageVersion.CSharp11) @@ -116,5 +115,5 @@ private static bool ContainsBackSlashOrQuoteOrOpenBrace(string text, int start, return false; } -} #endif +} diff --git a/src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs b/src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs index 2f8c5e46c6..3e79ae275b 100644 --- a/src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs @@ -1,5 +1,4 @@ -#if ROSLYN_4_2 -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; using Microsoft.CodeAnalysis; @@ -26,6 +25,7 @@ public override ImmutableArray SupportedDiagnostics } } +#if ROSLYN_4_2 public override void Initialize(AnalysisContext context) { base.Initialize(context); @@ -89,5 +89,5 @@ private static void AnalyzeInterpolatedStringExpression(SyntaxNodeAnalysisContex } } } -} #endif +} diff --git a/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs b/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs index 76d39eb577..6c7093e515 100644 --- a/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs +++ b/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs @@ -1,5 +1,4 @@ -#if ROSLYN_4_0 -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; using Microsoft.CodeAnalysis; @@ -27,6 +26,7 @@ public override ImmutableArray SupportedDiagnostics } } +#if ROSLYN_4_0 public override void Initialize(AnalysisContext context) { base.Initialize(context); @@ -86,5 +86,5 @@ internal static SyntaxNode GetNodeAfterNamespaceDeclaration(FileScopedNamespaceD ? usingDirective : memberDeclaration; } -} #endif +}