From ee2ba64a91a9349b41ee4f8e98eb7f6c7cc3511d Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sat, 2 Dec 2023 18:47:52 +0100 Subject: [PATCH 1/2] Rename analyzers RCS0030, RCS0033 --- src/Analyzers.xml | 8 +++--- .../CSharp/StatementCodeFixProvider.cs | 8 +++--- .../CSharp/DiagnosticIdentifiers.Generated.cs | 4 +-- .../CSharp/DiagnosticRules.Generated.cs | 20 ++++++------- ...tEmbeddedStatementOnItsOwnLineAnalyzer.cs} | 6 ++-- ...cs => PutStatementOnItsOwnLineAnalyzer.cs} | 6 ++-- ...0PutEmbeddedStatementOnItsOwnLineTests.cs} | 28 +++++++++---------- ...> RCS0033PutStatementOnItsOwnLineTests.cs} | 12 ++++---- 8 files changed, 46 insertions(+), 46 deletions(-) rename src/Formatting.Analyzers/CSharp/{AddNewLineBeforeEmbeddedStatementAnalyzer.cs => PutEmbeddedStatementOnItsOwnLineAnalyzer.cs} (95%) rename src/Formatting.Analyzers/CSharp/{AddNewLineBeforeStatementAnalyzer.cs => PutStatementOnItsOwnLineAnalyzer.cs} (92%) rename src/Tests/Formatting.Analyzers.Tests/{RCS0030AddNewLineBeforeEmbeddedStatementTests.cs => RCS0030PutEmbeddedStatementOnItsOwnLineTests.cs} (82%) rename src/Tests/Formatting.Analyzers.Tests/{RCS0033AddNewLineBeforeStatementTests.cs => RCS0033PutStatementOnItsOwnLineTests.cs} (74%) diff --git a/src/Analyzers.xml b/src/Analyzers.xml index f3b61637dd..06188eec75 100644 --- a/src/Analyzers.xml +++ b/src/Analyzers.xml @@ -782,8 +782,8 @@ namespace N RCS0030 - AddNewLineBeforeEmbeddedStatement - Add new line before embedded statement + PutEmbeddedStatementOnItsOwnLine + Put embedded statement on its own line Info false @@ -850,8 +850,8 @@ namespace N RCS0033 - AddNewLineBeforeStatement - Add new line before statement + PutStatementOnItsOwnLine + Put statement on its own line Info false diff --git a/src/Formatting.Analyzers.CodeFixes/CSharp/StatementCodeFixProvider.cs b/src/Formatting.Analyzers.CodeFixes/CSharp/StatementCodeFixProvider.cs index d25ede471c..5d503237b0 100644 --- a/src/Formatting.Analyzers.CodeFixes/CSharp/StatementCodeFixProvider.cs +++ b/src/Formatting.Analyzers.CodeFixes/CSharp/StatementCodeFixProvider.cs @@ -23,8 +23,8 @@ public override ImmutableArray FixableDiagnosticIds get { return ImmutableArray.Create( - DiagnosticIdentifiers.AddNewLineBeforeStatement, - DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement, + DiagnosticIdentifiers.PutStatementOnItsOwnLine, + DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine, DiagnosticIdentifiers.AddNewLineAfterSwitchLabel, DiagnosticIdentifiers.AddBlankLineAfterEmbeddedStatement); } @@ -42,8 +42,8 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) switch (diagnostic.Id) { - case DiagnosticIdentifiers.AddNewLineBeforeStatement: - case DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement: + case DiagnosticIdentifiers.PutStatementOnItsOwnLine: + case DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine: case DiagnosticIdentifiers.AddNewLineAfterSwitchLabel: { CodeAction codeAction = CodeAction.Create( diff --git a/src/Formatting.Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs b/src/Formatting.Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs index a40b11bcc0..bc1589c385 100644 --- a/src/Formatting.Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs +++ b/src/Formatting.Analyzers/CSharp/DiagnosticIdentifiers.Generated.cs @@ -32,10 +32,10 @@ public static partial class DiagnosticIdentifiers public const string PlaceNewLineAfterOrBeforeBinaryOperator = "RCS0027"; public const string PlaceNewLineAfterOrBeforeConditionalOperator = "RCS0028"; public const string PutConstructorInitializerOnItsOwnLine = "RCS0029"; - public const string AddNewLineBeforeEmbeddedStatement = "RCS0030"; + public const string PutEmbeddedStatementOnItsOwnLine = "RCS0030"; public const string PutEnumMemberOnItsOwnLine = "RCS0031"; public const string PlaceNewLineAfterOrBeforeArrowToken = "RCS0032"; - public const string AddNewLineBeforeStatement = "RCS0033"; + public const string PutStatementOnItsOwnLine = "RCS0033"; public const string PutTypeParameterConstraintOnItsOwnLine = "RCS0034"; public const string RemoveBlankLineBetweenSingleLineDeclarationsOfSameKind = "RCS0036"; public const string RemoveBlankLineBetweenUsingDirectivesWithSameRootNamespace = "RCS0038"; diff --git a/src/Formatting.Analyzers/CSharp/DiagnosticRules.Generated.cs b/src/Formatting.Analyzers/CSharp/DiagnosticRules.Generated.cs index ee9d66b5d5..3636d0c7ec 100644 --- a/src/Formatting.Analyzers/CSharp/DiagnosticRules.Generated.cs +++ b/src/Formatting.Analyzers/CSharp/DiagnosticRules.Generated.cs @@ -298,15 +298,15 @@ public static partial class DiagnosticRules customTags: Array.Empty()); /// RCS0030 - public static readonly DiagnosticDescriptor AddNewLineBeforeEmbeddedStatement = DiagnosticDescriptorFactory.Create( - id: DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement, - title: "Add new line before embedded statement", - messageFormat: "Add new line before embedded statement", + public static readonly DiagnosticDescriptor PutEmbeddedStatementOnItsOwnLine = DiagnosticDescriptorFactory.Create( + id: DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine, + title: "Put embedded statement on its own line", + messageFormat: "Put embedded statement on its own line", category: DiagnosticCategories.Roslynator, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: false, description: null, - helpLinkUri: DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement, + helpLinkUri: DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine, customTags: Array.Empty()); /// RCS0031 @@ -334,15 +334,15 @@ public static partial class DiagnosticRules customTags: Array.Empty()); /// RCS0033 - public static readonly DiagnosticDescriptor AddNewLineBeforeStatement = DiagnosticDescriptorFactory.Create( - id: DiagnosticIdentifiers.AddNewLineBeforeStatement, - title: "Add new line before statement", - messageFormat: "Add new line before statement", + public static readonly DiagnosticDescriptor PutStatementOnItsOwnLine = DiagnosticDescriptorFactory.Create( + id: DiagnosticIdentifiers.PutStatementOnItsOwnLine, + title: "Put statement on its own line", + messageFormat: "Put statement on its own line", category: DiagnosticCategories.Roslynator, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: false, description: null, - helpLinkUri: DiagnosticIdentifiers.AddNewLineBeforeStatement, + helpLinkUri: DiagnosticIdentifiers.PutStatementOnItsOwnLine, customTags: Array.Empty()); /// RCS0034 diff --git a/src/Formatting.Analyzers/CSharp/AddNewLineBeforeEmbeddedStatementAnalyzer.cs b/src/Formatting.Analyzers/CSharp/PutEmbeddedStatementOnItsOwnLineAnalyzer.cs similarity index 95% rename from src/Formatting.Analyzers/CSharp/AddNewLineBeforeEmbeddedStatementAnalyzer.cs rename to src/Formatting.Analyzers/CSharp/PutEmbeddedStatementOnItsOwnLineAnalyzer.cs index e293e3e3d8..58515f1456 100644 --- a/src/Formatting.Analyzers/CSharp/AddNewLineBeforeEmbeddedStatementAnalyzer.cs +++ b/src/Formatting.Analyzers/CSharp/PutEmbeddedStatementOnItsOwnLineAnalyzer.cs @@ -11,7 +11,7 @@ namespace Roslynator.Formatting.CSharp; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class AddNewLineBeforeEmbeddedStatementAnalyzer : BaseDiagnosticAnalyzer +public sealed class PutEmbeddedStatementOnItsOwnLineAnalyzer : BaseDiagnosticAnalyzer { private static ImmutableArray _supportedDiagnostics; @@ -20,7 +20,7 @@ public override ImmutableArray SupportedDiagnostics get { if (_supportedDiagnostics.IsDefault) - Immutable.InterlockedInitialize(ref _supportedDiagnostics, DiagnosticRules.AddNewLineBeforeEmbeddedStatement); + Immutable.InterlockedInitialize(ref _supportedDiagnostics, DiagnosticRules.PutEmbeddedStatementOnItsOwnLine); return _supportedDiagnostics; } @@ -125,7 +125,7 @@ private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, Statemen { DiagnosticHelpers.ReportDiagnostic( context, - DiagnosticRules.AddNewLineBeforeEmbeddedStatement, + DiagnosticRules.PutEmbeddedStatementOnItsOwnLine, Location.Create(statement.SyntaxTree, statement.Span.WithLength(0))); } } diff --git a/src/Formatting.Analyzers/CSharp/AddNewLineBeforeStatementAnalyzer.cs b/src/Formatting.Analyzers/CSharp/PutStatementOnItsOwnLineAnalyzer.cs similarity index 92% rename from src/Formatting.Analyzers/CSharp/AddNewLineBeforeStatementAnalyzer.cs rename to src/Formatting.Analyzers/CSharp/PutStatementOnItsOwnLineAnalyzer.cs index 59aa63cdd0..7fbaea7379 100644 --- a/src/Formatting.Analyzers/CSharp/AddNewLineBeforeStatementAnalyzer.cs +++ b/src/Formatting.Analyzers/CSharp/PutStatementOnItsOwnLineAnalyzer.cs @@ -10,7 +10,7 @@ namespace Roslynator.Formatting.CSharp; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class AddNewLineBeforeStatementAnalyzer : BaseDiagnosticAnalyzer +public sealed class PutStatementOnItsOwnLineAnalyzer : BaseDiagnosticAnalyzer { private static ImmutableArray _supportedDiagnostics; @@ -19,7 +19,7 @@ public override ImmutableArray SupportedDiagnostics get { if (_supportedDiagnostics.IsDefault) - Immutable.InterlockedInitialize(ref _supportedDiagnostics, DiagnosticRules.AddNewLineBeforeStatement); + Immutable.InterlockedInitialize(ref _supportedDiagnostics, DiagnosticRules.PutStatementOnItsOwnLine); return _supportedDiagnostics; } @@ -63,7 +63,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SyntaxList +public class RCS0030PutEmbeddedStatementOnItsOwnLineTests : AbstractCSharpDiagnosticVerifier { - public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.AddNewLineBeforeEmbeddedStatement; + public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.PutEmbeddedStatementOnItsOwnLine; - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_If() { await VerifyDiagnosticAndFixAsync(@" @@ -39,7 +39,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_Else() { await VerifyDiagnosticAndFixAsync(@" @@ -70,7 +70,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_ForEach() { await VerifyDiagnosticAndFixAsync(@" @@ -103,7 +103,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_ForEachVariable() { await VerifyDiagnosticAndFixAsync(@" @@ -136,7 +136,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_For() { await VerifyDiagnosticAndFixAsync(@" @@ -169,7 +169,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_Using() { await VerifyDiagnosticAndFixAsync(@" @@ -200,7 +200,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_While() { await VerifyDiagnosticAndFixAsync(@" @@ -227,7 +227,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_Do() { await VerifyDiagnosticAndFixAsync(@" @@ -256,7 +256,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_Lock() { await VerifyDiagnosticAndFixAsync(@" @@ -283,7 +283,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task Test_Fixed() { await VerifyDiagnosticAndFixAsync(@" @@ -316,7 +316,7 @@ void M() ", options: Options.WithAllowUnsafe(true)); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task TestNoDiagnostic_EmbeddedStatement() { await VerifyNoDiagnosticAsync(@" @@ -367,7 +367,7 @@ private static void M() ", options: Options.WithAllowUnsafe(true)); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeEmbeddedStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutEmbeddedStatementOnItsOwnLine)] public async Task TestNoDiagnostic_Block() { await VerifyNoDiagnosticAsync(@" diff --git a/src/Tests/Formatting.Analyzers.Tests/RCS0033AddNewLineBeforeStatementTests.cs b/src/Tests/Formatting.Analyzers.Tests/RCS0033PutStatementOnItsOwnLineTests.cs similarity index 74% rename from src/Tests/Formatting.Analyzers.Tests/RCS0033AddNewLineBeforeStatementTests.cs rename to src/Tests/Formatting.Analyzers.Tests/RCS0033PutStatementOnItsOwnLineTests.cs index 71e0e97b42..c377e2c8f7 100644 --- a/src/Tests/Formatting.Analyzers.Tests/RCS0033AddNewLineBeforeStatementTests.cs +++ b/src/Tests/Formatting.Analyzers.Tests/RCS0033PutStatementOnItsOwnLineTests.cs @@ -8,11 +8,11 @@ namespace Roslynator.Formatting.CSharp.Tests; -public class RCS0033AddNewLineBeforeStatementTests : AbstractCSharpDiagnosticVerifier +public class RCS0033PutStatementOnItsOwnLineTests : AbstractCSharpDiagnosticVerifier { - public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.AddNewLineBeforeStatement; + public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.PutStatementOnItsOwnLine; - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutStatementOnItsOwnLine)] public async Task Test_Block() { await VerifyDiagnosticAndFixAsync(@" @@ -35,7 +35,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutStatementOnItsOwnLine)] public async Task Test_Block_SingleLine() { await VerifyDiagnosticAndFixAsync(@" @@ -55,7 +55,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutStatementOnItsOwnLine)] public async Task Test_SwitchSection() { await VerifyDiagnosticAndFixAsync(@" @@ -90,7 +90,7 @@ void M() "); } - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddNewLineBeforeStatement)] + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutStatementOnItsOwnLine)] public async Task TestNoDiagnostic_EmptyStatement() { await VerifyNoDiagnosticAsync(@" From 681bde02a73ca366041e93b32b62ab985e8eae23 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sat, 2 Dec 2023 18:50:17 +0100 Subject: [PATCH 2/2] update --- ChangeLog.md | 3 +++ .../package/src/configurationFiles.generated.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index a0a24c5ca7..dc790f4111 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Group code fix "Change accessibility to ..." ([PR](https://github.com/dotnet/roslynator/pull/1305)) - [CLI] Bump Roslyn to 4.8.0 ([PR](https://github.com/dotnet/roslynator/pull/1307)). - Group refactoring "Remove members above/below'" ([PR](https://github.com/dotnet/roslynator/pull/1308)) +- Rename analyzers ([PR](https://github.com/dotnet/roslynator/pull/1314)) + - "Add new line before embedded statement" -> "Put embedded statement on its own line" ([RCS0030](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0030)) + - "Add new line before statement" -> "Put statement on its own line" ([RCS0033](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0033)) ### Fixed diff --git a/src/VisualStudioCode/package/src/configurationFiles.generated.ts b/src/VisualStudioCode/package/src/configurationFiles.generated.ts index 3a2bea0a36..ab40d1b1ea 100644 --- a/src/VisualStudioCode/package/src/configurationFiles.generated.ts +++ b/src/VisualStudioCode/package/src/configurationFiles.generated.ts @@ -218,7 +218,7 @@ roslynator_analyzers.enabled_by_default = true|false # Put constructor initializer on its own line #dotnet_diagnostic.rcs0029.severity = none -# Add new line before embedded statement +# Put embedded statement on its own line #dotnet_diagnostic.rcs0030.severity = none # Put enum member on its own line @@ -228,7 +228,7 @@ roslynator_analyzers.enabled_by_default = true|false #dotnet_diagnostic.rcs0032.severity = none # Options: roslynator_arrow_token_new_line -# Add new line before statement +# Put statement on its own line #dotnet_diagnostic.rcs0033.severity = none # Put type parameter constraint on its own line