From c60e2211c22caf9e8d7e50f8b6c6ef931e2ba0aa Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 25 Jan 2024 22:12:17 +0100 Subject: [PATCH] update --- .../InvocationExpressionCodeFixProvider.cs | 8 ++++---- src/Analyzers.xml | 4 ++-- .../Analysis/InvocationExpressionAnalyzer.cs | 6 +++--- ...rpolationInsteadOfStringConcatAnalysis.cs} | 4 ++-- .../CSharp/DiagnosticIdentifiers.Generated.cs | 2 +- .../CSharp/DiagnosticRules.Generated.cs | 10 +++++----- ...nterpolationInsteadOfStringConcatTests.cs} | 20 +++++++++---------- .../src/configurationFiles.generated.ts | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) rename src/Analyzers/CSharp/Analysis/{ConvertStringConcatToInterpolatedStringAnalysis.cs => UseStringInterpolationInsteadOfStringConcatAnalysis.cs} (92%) rename src/Tests/Analyzers.Tests/{RCS1267ConvertStringConcatToInterpolatedStringTests.cs => RCS1267UseStringInterpolationInsteadOfStringConcatTests.cs} (72%) diff --git a/src/Analyzers.CodeFixes/CSharp/CodeFixes/InvocationExpressionCodeFixProvider.cs b/src/Analyzers.CodeFixes/CSharp/CodeFixes/InvocationExpressionCodeFixProvider.cs index 12aef8d2b2..2c5a601e60 100644 --- a/src/Analyzers.CodeFixes/CSharp/CodeFixes/InvocationExpressionCodeFixProvider.cs +++ b/src/Analyzers.CodeFixes/CSharp/CodeFixes/InvocationExpressionCodeFixProvider.cs @@ -34,7 +34,7 @@ public override ImmutableArray FixableDiagnosticIds DiagnosticIdentifiers.CombineEnumerableWhereMethodChain, DiagnosticIdentifiers.CallExtensionMethodAsInstanceMethod, DiagnosticIdentifiers.CallThenByInsteadOfOrderBy, - DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString); + DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat); } } @@ -119,11 +119,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix(codeAction, diagnostic); break; } - case DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString: + case DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat: { CodeAction codeAction = CodeAction.Create( "Use string interpolation", - ct => ConvertStringConcatToInterpolatedStringAsync(context.Document, invocation, ct), + ct => UseStringInterpolationInsteadOfStringConcatAsync(context.Document, invocation, ct), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); @@ -163,7 +163,7 @@ private static Task CallThenByInsteadOfOrderByAsync( return document.ReplaceNodeAsync(invocationExpression, newInvocationExpression, cancellationToken); } - private static Task ConvertStringConcatToInterpolatedStringAsync( + private static Task UseStringInterpolationInsteadOfStringConcatAsync( Document document, InvocationExpressionSyntax invocationExpression, CancellationToken cancellationToken) diff --git a/src/Analyzers.xml b/src/Analyzers.xml index 647a06ac36..05c21abb96 100644 --- a/src/Analyzers.xml +++ b/src/Analyzers.xml @@ -7693,8 +7693,8 @@ finally RCS1267 - ConvertStringConcatToInterpolatedString - Convert 'string.Concat' to interpolated string + UseStringInterpolationInsteadOfStringConcat + Use string interpolation instead of 'string.Concat' Info true diff --git a/src/Analyzers/CSharp/Analysis/InvocationExpressionAnalyzer.cs b/src/Analyzers/CSharp/Analysis/InvocationExpressionAnalyzer.cs index 491077666e..36dbfec4ce 100644 --- a/src/Analyzers/CSharp/Analysis/InvocationExpressionAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/InvocationExpressionAnalyzer.cs @@ -45,7 +45,7 @@ public override ImmutableArray SupportedDiagnostics DiagnosticRules.SimplifyLogicalNegation, DiagnosticRules.UseCoalesceExpression, DiagnosticRules.OptimizeMethodCall, - DiagnosticRules.ConvertStringConcatToInterpolatedString); + DiagnosticRules.UseStringInterpolationInsteadOfStringConcat); } return _supportedDiagnostics; @@ -456,10 +456,10 @@ private static void AnalyzeInvocationExpression(SyntaxNodeAnalysisContext contex } case "Concat": { - if (DiagnosticRules.ConvertStringConcatToInterpolatedString.IsEffective(context) + if (DiagnosticRules.UseStringInterpolationInsteadOfStringConcat.IsEffective(context) && argumentCount > 1) { - ConvertStringConcatToInterpolatedStringAnalysis.Analyze(context, invocationInfo); + UseStringInterpolationInsteadOfStringConcatAnalysis.Analyze(context, invocationInfo); } break; diff --git a/src/Analyzers/CSharp/Analysis/ConvertStringConcatToInterpolatedStringAnalysis.cs b/src/Analyzers/CSharp/Analysis/UseStringInterpolationInsteadOfStringConcatAnalysis.cs similarity index 92% rename from src/Analyzers/CSharp/Analysis/ConvertStringConcatToInterpolatedStringAnalysis.cs rename to src/Analyzers/CSharp/Analysis/UseStringInterpolationInsteadOfStringConcatAnalysis.cs index f56fe64fcb..6dc2d5c76c 100644 --- a/src/Analyzers/CSharp/Analysis/ConvertStringConcatToInterpolatedStringAnalysis.cs +++ b/src/Analyzers/CSharp/Analysis/UseStringInterpolationInsteadOfStringConcatAnalysis.cs @@ -8,7 +8,7 @@ namespace Roslynator.CSharp.Analysis; -internal static class ConvertStringConcatToInterpolatedStringAnalysis +internal static class UseStringInterpolationInsteadOfStringConcatAnalysis { internal static void Analyze(SyntaxNodeAnalysisContext context, SimpleMemberInvocationExpressionInfo invocationInfo) { @@ -56,7 +56,7 @@ internal static void Analyze(SyntaxNodeAnalysisContext context, SimpleMemberInvo if (isVerbatim is not null && invocationInfo.ArgumentList.IsSingleLine()) { - DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.ConvertStringConcatToInterpolatedString, invocationInfo.InvocationExpression); + DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.UseStringInterpolationInsteadOfStringConcat, invocationInfo.InvocationExpression); } } } diff --git a/src/Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs b/src/Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs index 0ced988d39..fb7b45e44c 100644 --- a/src/Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs +++ b/src/Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs @@ -222,6 +222,6 @@ public static partial class DiagnosticIdentifiers public const string InvalidReferenceInDocumentationComment = "RCS1263"; public const string UseVarOrExplicitType = "RCS1264"; public const string RemoveRedundantCatchBlock = "RCS1265"; - public const string ConvertStringConcatToInterpolatedString = "RCS1267"; + public const string UseStringInterpolationInsteadOfStringConcat = "RCS1267"; } } \ No newline at end of file diff --git a/src/Analyzers/CSharp/DiagnosticRules.Generated.cs b/src/Analyzers/CSharp/DiagnosticRules.Generated.cs index d4468d34e2..75af2ce1ff 100644 --- a/src/Analyzers/CSharp/DiagnosticRules.Generated.cs +++ b/src/Analyzers/CSharp/DiagnosticRules.Generated.cs @@ -2628,15 +2628,15 @@ public static partial class DiagnosticRules customTags: Array.Empty()); /// RCS1267 - public static readonly DiagnosticDescriptor ConvertStringConcatToInterpolatedString = DiagnosticDescriptorFactory.Create( - id: DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString, - title: "Convert 'string.Concat' to interpolated string", - messageFormat: "Convert 'string.Concat' to interpolated string", + public static readonly DiagnosticDescriptor UseStringInterpolationInsteadOfStringConcat = DiagnosticDescriptorFactory.Create( + id: DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat, + title: "Use string interpolation instead of 'string.Concat'", + messageFormat: "Use string interpolation instead of 'string.Concat'", category: DiagnosticCategories.Roslynator, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: true, description: null, - helpLinkUri: DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString, + helpLinkUri: DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat, customTags: Array.Empty()); } diff --git a/src/Tests/Analyzers.Tests/RCS1267ConvertStringConcatToInterpolatedStringTests.cs b/src/Tests/Analyzers.Tests/RCS1267UseStringInterpolationInsteadOfStringConcatTests.cs similarity index 72% rename from src/Tests/Analyzers.Tests/RCS1267ConvertStringConcatToInterpolatedStringTests.cs rename to src/Tests/Analyzers.Tests/RCS1267UseStringInterpolationInsteadOfStringConcatTests.cs index 96b890ec21..e7b3e1db8e 100644 --- a/src/Tests/Analyzers.Tests/RCS1267ConvertStringConcatToInterpolatedStringTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1267UseStringInterpolationInsteadOfStringConcatTests.cs @@ -8,11 +8,11 @@ namespace Roslynator.CSharp.Analysis.Tests; -public class RCS1267ConvertStringConcatToInterpolatedStringTests : AbstractCSharpDiagnosticVerifier +public class RCS1267UseStringInterpolationInsteadOfStringConcatTests : AbstractCSharpDiagnosticVerifier { - public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.ConvertStringConcatToInterpolatedString; + public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.UseStringInterpolationInsteadOfStringConcat; - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task Test() { await VerifyDiagnosticAndFixAsync(""" @@ -39,7 +39,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task Test_Verbatim() { await VerifyDiagnosticAndFixAsync(""" @@ -66,7 +66,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_SingleArgument() { await VerifyNoDiagnosticAsync(""" @@ -83,7 +83,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_NoStringLiteral() { await VerifyNoDiagnosticAsync(""" @@ -100,7 +100,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_ContainsInterpolatedString() { await VerifyNoDiagnosticAsync(""" @@ -117,7 +117,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_ContainsVerbatimAndNonVerbatimLiterals() { await VerifyNoDiagnosticAsync(""" @@ -134,7 +134,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_ContainsVerbatimAndNonVerbatimLiterals2() { await VerifyNoDiagnosticAsync(""" @@ -151,7 +151,7 @@ void M() ); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertStringConcatToInterpolatedString)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseStringInterpolationInsteadOfStringConcat)] public async Task TestNoDiagnostic_SpansOverMultipleLines() { await VerifyNoDiagnosticAsync(""" diff --git a/src/VisualStudioCode/package/src/configurationFiles.generated.ts b/src/VisualStudioCode/package/src/configurationFiles.generated.ts index 8e72591655..ebd555d9ca 100644 --- a/src/VisualStudioCode/package/src/configurationFiles.generated.ts +++ b/src/VisualStudioCode/package/src/configurationFiles.generated.ts @@ -910,7 +910,7 @@ roslynator_analyzers.enabled_by_default = true|false # Remove redundant catch block #dotnet_diagnostic.rcs1265.severity = suggestion -# Convert 'string.Concat' to interpolated string +# Use string interpolation instead of 'string.Concat' #dotnet_diagnostic.rcs1267.severity = suggestion # Use pattern matching