From 3f758d49d741146eb80f40af4c5056e00c3b6492 Mon Sep 17 00:00:00 2001 From: Thomas GICQUEL Date: Tue, 19 May 2026 17:32:55 +0200 Subject: [PATCH 1/3] Add rcs1200 analyzer --- .claude/settings.local.json | 8 + .claude/worktrees/hardcore-almeida-75fedf | 1 + creedengo-csharp.slnx | 1 + .../GCI98.UseThenByInsteadOfOrderBy.Fixer.cs | 47 ++++ .../GCI98.UseThenByInsteadOfOrderBy.cs | 51 ++++ src/Creedengo.Core/Models/Rule.cs | 84 +++--- .../Creedengo.Sandbox.csproj | 14 + src/Creedengo.Sandbox/Program.cs | 1 + src/Creedengo.Sandbox/RCS1200Sandbox.cs | 23 ++ .../GCI98.UseThenByInsteadOfOrderBy.Tests.cs | 262 ++++++++++++++++++ 10 files changed, 451 insertions(+), 41 deletions(-) create mode 100644 .claude/settings.local.json create mode 160000 .claude/worktrees/hardcore-almeida-75fedf create mode 100644 src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs create mode 100644 src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.cs create mode 100644 src/Creedengo.Sandbox/Creedengo.Sandbox.csproj create mode 100644 src/Creedengo.Sandbox/Program.cs create mode 100644 src/Creedengo.Sandbox/RCS1200Sandbox.cs create mode 100644 src/Creedengo.Tests/Tests/GCI98.UseThenByInsteadOfOrderBy.Tests.cs diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 00000000..f9eb3d60 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,8 @@ +{ + "permissions": { + "allow": [ + "Bash(dotnet build *)", + "Bash(dotnet test *)" + ] + } +} diff --git a/.claude/worktrees/hardcore-almeida-75fedf b/.claude/worktrees/hardcore-almeida-75fedf new file mode 160000 index 00000000..2281aa51 --- /dev/null +++ b/.claude/worktrees/hardcore-almeida-75fedf @@ -0,0 +1 @@ +Subproject commit 2281aa515779d72913d03609272adba3d685c031 diff --git a/creedengo-csharp.slnx b/creedengo-csharp.slnx index bac26c87..5db9630e 100644 --- a/creedengo-csharp.slnx +++ b/creedengo-csharp.slnx @@ -32,6 +32,7 @@ + diff --git a/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs new file mode 100644 index 00000000..961a4b4f --- /dev/null +++ b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs @@ -0,0 +1,47 @@ +namespace Creedengo.Core.Analyzers; + +/// GCI98 fixer: Use 'ThenBy' instead of 'OrderBy'. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(UseThenByInsteadOfOrderByFixer)), Shared] +public sealed class UseThenByInsteadOfOrderByFixer : CodeFixProvider +{ + /// + public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; + private static readonly ImmutableArray _fixableDiagnosticIds = + ImmutableArray.Create(UseThenByInsteadOfOrderBy.Descriptor.Id); + + /// + public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; + + /// + public override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + if (await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false) is not { } root) + return; + + foreach (var diagnostic in context.Diagnostics) + { + if (root.FindToken(diagnostic.Location.SourceSpan.Start).Parent is not IdentifierNameSyntax nameSyntax) + continue; + if (nameSyntax.Parent is not MemberAccessExpressionSyntax memberAccess) + continue; + + context.RegisterCodeFix( + CodeAction.Create( + title: "Use 'ThenBy' instead of 'OrderBy'", + createChangedDocument: _ => FixAsync(context.Document, memberAccess, nameSyntax), + equivalenceKey: "UseThenByInsteadOfOrderBy"), + diagnostic); + } + } + + private static Task FixAsync( + Document document, + MemberAccessExpressionSyntax memberAccess, + IdentifierNameSyntax nameSyntax) + { + var newName = nameSyntax.Identifier.Text == "OrderBy" ? "ThenBy" : "ThenByDescending"; + var newMemberAccess = memberAccess.WithName( + SyntaxFactory.IdentifierName(newName).WithTriviaFrom(nameSyntax)); + return document.WithUpdatedRoot(memberAccess, newMemberAccess); + } +} diff --git a/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.cs b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.cs new file mode 100644 index 00000000..1c0a67a5 --- /dev/null +++ b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.cs @@ -0,0 +1,51 @@ +namespace Creedengo.Core.Analyzers; + +/// GCI98: Use 'ThenBy' instead of 'OrderBy' in a LINQ sort chain. +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class UseThenByInsteadOfOrderBy : DiagnosticAnalyzer +{ + private static readonly ImmutableArray InvocationExpressions = + ImmutableArray.Create(SyntaxKind.InvocationExpression); + + /// The diagnostic descriptor. + public static DiagnosticDescriptor Descriptor { get; } = Rule.CreateDescriptor( + id: Rule.Ids.GCI98_UseThenByInsteadOfOrderBy, + title: "Use 'ThenBy' instead of 'OrderBy'", + message: "Call 'ThenBy' or 'ThenByDescending' instead of 'OrderBy' or 'OrderByDescending' to preserve the primary sort order", + category: Rule.Categories.Usage, + severity: DiagnosticSeverity.Warning, + description: "Chaining 'OrderBy' or 'OrderByDescending' after another sort operation discards all previous sort keys. Use 'ThenBy' or 'ThenByDescending' to add a secondary sort key while preserving the primary sort."); + + /// + public override ImmutableArray SupportedDiagnostics => _supportedDiagnostics; + private static readonly ImmutableArray _supportedDiagnostics = + ImmutableArray.Create(Descriptor); + + /// + public override void Initialize(AnalysisContext context) + { + context.EnableConcurrentExecution(); + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.RegisterSyntaxNodeAction(static context => AnalyzeNode(context), InvocationExpressions); + } + + private static void AnalyzeNode(SyntaxNodeAnalysisContext context) + { + var invocation = (InvocationExpressionSyntax)context.Node; + + if (invocation.Expression is not MemberAccessExpressionSyntax + { Name.Identifier.Text: "OrderBy" or "OrderByDescending" } memberAccess) + return; + + if (memberAccess.Expression is not InvocationExpressionSyntax + { + Expression: MemberAccessExpressionSyntax + { + Name.Identifier.Text: "OrderBy" or "OrderByDescending" or "ThenBy" or "ThenByDescending" + } + }) + return; + + context.ReportDiagnostic(Diagnostic.Create(Descriptor, memberAccess.Name.GetLocation())); + } +} diff --git a/src/Creedengo.Core/Models/Rule.cs b/src/Creedengo.Core/Models/Rule.cs index 943d3e6a..af775a10 100644 --- a/src/Creedengo.Core/Models/Rule.cs +++ b/src/Creedengo.Core/Models/Rule.cs @@ -2,47 +2,49 @@ internal static class Rule { - public static class Categories - { - public const string Design = "Design"; - public const string Usage = "Usage"; - public const string Performance = "Performance"; - } + public static class Categories + { + public const string Design = "Design"; + public const string Usage = "Usage"; + public const string Performance = "Performance"; + } - public static class Ids - { - public const string GCI69_DontCallFunctionsInLoopConditions = "GCI69"; - public const string GCI72_DontExecuteSqlCommandsInLoops = "GCI72"; - public const string GCI75_DontConcatenateStringsInLoops = "GCI75"; - public const string GCI81_UseStructLayout = "GCI81"; - public const string GCI82_VariableCanBeMadeConstant = "GCI82"; - public const string GCI83_ReplaceEnumToStringWithNameOf = "GCI83"; - public const string GCI84_AvoidAsyncVoidMethods = "GCI84"; - public const string GCI85_MakeTypeSealed = "GCI85"; - public const string GCI86_GCCollectShouldNotBeCalled = "GCI86"; - public const string GCI87_UseCollectionIndexer = "GCI87"; - public const string GCI88_DisposeResourceAsynchronously = "GCI88"; - public const string GCI89_DoNotPassMutableStructAsRefReadonly = "GCI89"; - public const string GCI90_UseCastInsteadOfSelect = "GCI90"; - public const string GCI91_UseWhereBeforeOrderBy = "GCI91"; - public const string GCI92_UseStringEmptyLength = "GCI92"; - public const string GCI93_ReturnTaskDirectly = "GCI93"; - public const string GCIACV_NonReadOnlyStruct = "GCIACV"; - public const string GCI95_UseIsOperatorInsteadOfAsOperator = "GCI95"; - public const string GCIXX_UnnecessaryAssignment = "GCIXX"; - public const string GCI96_UseEventArgsDotEmpty = "GCI96"; - public const string GCI2333_RemoveRedundantToCharArrayCall = "GCI2333"; - } + public static class Ids + { + public const string GCI69_DontCallFunctionsInLoopConditions = "GCI69"; + public const string GCI72_DontExecuteSqlCommandsInLoops = "GCI72"; + public const string GCI75_DontConcatenateStringsInLoops = "GCI75"; + public const string GCI81_UseStructLayout = "GCI81"; + public const string GCI82_VariableCanBeMadeConstant = "GCI82"; + public const string GCI83_ReplaceEnumToStringWithNameOf = "GCI83"; + public const string GCI84_AvoidAsyncVoidMethods = "GCI84"; + public const string GCI85_MakeTypeSealed = "GCI85"; + public const string GCI86_GCCollectShouldNotBeCalled = "GCI86"; + public const string GCI87_UseCollectionIndexer = "GCI87"; + public const string GCI88_DisposeResourceAsynchronously = "GCI88"; + public const string GCI89_DoNotPassMutableStructAsRefReadonly = "GCI89"; + public const string GCI90_UseCastInsteadOfSelect = "GCI90"; + public const string GCI91_UseWhereBeforeOrderBy = "GCI91"; + public const string GCI92_UseStringEmptyLength = "GCI92"; + public const string GCI93_ReturnTaskDirectly = "GCI93"; + public const string GCIACV_NonReadOnlyStruct = "GCIACV"; + public const string GCI95_UseIsOperatorInsteadOfAsOperator = "GCI95"; + public const string GCIXX_UnnecessaryAssignment = "GCIXX"; + public const string GCI96_UseEventArgsDotEmpty = "GCI96"; + public const string GCI2333_RemoveRedundantToCharArrayCall = "GCI2333"; + public const string GCI98_UseThenByInsteadOfOrderBy = "GCI98"; - /// Creates a diagnostic descriptor. - /// The rule id. - /// The rule title. - /// The rule message. - /// The rule category. - /// The rule severity. - /// The rule description. - /// The diagnostic descriptor. - public static DiagnosticDescriptor CreateDescriptor(string id, string title, string message, string category, DiagnosticSeverity severity, string description) => - new(id, title, message, category, severity, isEnabledByDefault: true, description, helpLinkUri: - $"https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/src/main/rules/{id}/csharp/{id}.asciidoc"); + } + + /// Creates a diagnostic descriptor. + /// The rule id. + /// The rule title. + /// The rule message. + /// The rule category. + /// The rule severity. + /// The rule description. + /// The diagnostic descriptor. + public static DiagnosticDescriptor CreateDescriptor(string id, string title, string message, string category, DiagnosticSeverity severity, string description) => + new(id, title, message, category, severity, isEnabledByDefault: true, description, helpLinkUri: + $"https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/src/main/rules/{id}/csharp/{id}.asciidoc"); } diff --git a/src/Creedengo.Sandbox/Creedengo.Sandbox.csproj b/src/Creedengo.Sandbox/Creedengo.Sandbox.csproj new file mode 100644 index 00000000..5588302d --- /dev/null +++ b/src/Creedengo.Sandbox/Creedengo.Sandbox.csproj @@ -0,0 +1,14 @@ + + + + Exe + net10.0 + enable + enable + false + + + + + + diff --git a/src/Creedengo.Sandbox/Program.cs b/src/Creedengo.Sandbox/Program.cs new file mode 100644 index 00000000..dfb8f564 --- /dev/null +++ b/src/Creedengo.Sandbox/Program.cs @@ -0,0 +1 @@ +Console.WriteLine("Write your own class sandbox"); diff --git a/src/Creedengo.Sandbox/RCS1200Sandbox.cs b/src/Creedengo.Sandbox/RCS1200Sandbox.cs new file mode 100644 index 00000000..b4f9c906 --- /dev/null +++ b/src/Creedengo.Sandbox/RCS1200Sandbox.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Creedengo.Sandbox; + +internal class RCS1200Sandbox +{ + public static void Sort() + { + + var items = new (int a, int b)[] { + (1, 2), + (3, 4), + (5, 6) + }; + + var sorted = items.OrderBy(item => item.Item1) + .OrderBy(item => item.Item2); + + } + +} diff --git a/src/Creedengo.Tests/Tests/GCI98.UseThenByInsteadOfOrderBy.Tests.cs b/src/Creedengo.Tests/Tests/GCI98.UseThenByInsteadOfOrderBy.Tests.cs new file mode 100644 index 00000000..ece34a7a --- /dev/null +++ b/src/Creedengo.Tests/Tests/GCI98.UseThenByInsteadOfOrderBy.Tests.cs @@ -0,0 +1,262 @@ +namespace Creedengo.Tests.Tests; + +[TestClass] +public sealed class UseThenByInsteadOfOrderByTests +{ + private static readonly CodeFixerDlg VerifyAsync = + TestRunner.VerifyAsync; + + [TestMethod] + public Task EmptyCodeAsync() => VerifyAsync(""); + + #region No diagnostic + + [TestMethod] + public Task DontWarnOnSingleOrderByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderBy(x => x.A); + } + } + """); + + [TestMethod] + public Task DontWarnOnSingleOrderByDescendingAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A); + } + } + """); + + [TestMethod] + public Task DontWarnOnOrderByThenByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderBy(x => x.A).ThenBy(x => x.B); + } + } + """); + + [TestMethod] + public Task DontWarnOnOrderByDescendingThenByDescendingAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A).ThenByDescending(x => x.B); + } + } + """); + + [TestMethod] + public Task DontWarnOnOrderByFollowedBySelectAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderBy(x => x.A).Select(x => x.B); + } + } + """); + + #endregion + + #region Diagnostic + fix + + [TestMethod] + public Task WarnOnOrderByAfterOrderByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var query1 = items.OrderBy(x => x.A).[|OrderBy|](x => x.B); + var query2 = items + .OrderBy(x => x.A) + .[|OrderBy|](x => x.B); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var query1 = items.OrderBy(x => x.A).ThenBy(x => x.B); + var query2 = items + .OrderBy(x => x.A) + .ThenBy(x => x.B); + } + } + """); + + [TestMethod] + public Task WarnOnOrderByDescendingAfterOrderByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderBy(x => x.A).[|OrderByDescending|](x => x.B); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderBy(x => x.A).ThenByDescending(x => x.B); + } + } + """); + + [TestMethod] + public Task WarnOnOrderByAfterOrderByDescendingAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A).[|OrderBy|](x => x.B); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A).ThenBy(x => x.B); + } + } + """); + + [TestMethod] + public Task WarnOnOrderByDescendingAfterOrderByDescendingAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A).[|OrderByDescending|](x => x.B); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B)>(); + var result = items.OrderByDescending(x => x.A).ThenByDescending(x => x.B); + } + } + """); + + [TestMethod] + public Task WarnOnOrderByAfterThenByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B, int C)>(); + var result = items.OrderBy(x => x.A).ThenBy(x => x.B).[|OrderBy|](x => x.C); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B, int C)>(); + var result = items.OrderBy(x => x.A).ThenBy(x => x.B).ThenBy(x => x.C); + } + } + """); + + [TestMethod] + public Task WarnOnChainedOrderByAsync() => VerifyAsync(""" + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B, int C)>(); + var result = items.OrderBy(x => x.A).[|OrderBy|](x => x.B).[|OrderBy|](x => x.C); + } + } + """, """ + using System.Linq; + using System.Collections.Generic; + + public static class Test + { + public static void Run() + { + var items = new List<(int A, int B, int C)>(); + var result = items.OrderBy(x => x.A).ThenBy(x => x.B).ThenBy(x => x.C); + } + } + """); + + #endregion +} From 6d9ee82dc5e94202adf25e3bf9b4e85ebbb2f1df Mon Sep 17 00:00:00 2001 From: Thomas GICQUEL Date: Tue, 19 May 2026 17:49:45 +0200 Subject: [PATCH 2/3] Remove .claude/ from tracking and ignore it Co-Authored-By: Claude Sonnet 4.6 --- .claude/settings.local.json | 8 -------- .claude/worktrees/hardcore-almeida-75fedf | 1 - .gitignore | 3 +++ 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 .claude/settings.local.json delete mode 160000 .claude/worktrees/hardcore-almeida-75fedf diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100644 index f9eb3d60..00000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "permissions": { - "allow": [ - "Bash(dotnet build *)", - "Bash(dotnet test *)" - ] - } -} diff --git a/.claude/worktrees/hardcore-almeida-75fedf b/.claude/worktrees/hardcore-almeida-75fedf deleted file mode 160000 index 2281aa51..00000000 --- a/.claude/worktrees/hardcore-almeida-75fedf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2281aa515779d72913d03609272adba3d685c031 diff --git a/.gitignore b/.gitignore index e6d35f75..7bade528 100644 --- a/.gitignore +++ b/.gitignore @@ -486,3 +486,6 @@ $RECYCLE.BIN/ **/Container **/Publish + +# Claude Code local configuration +.claude/ From 29c200114dab9d9e8aa343cf6a8d38233cc95a89 Mon Sep 17 00:00:00 2001 From: Thomas GICQUEL Date: Tue, 19 May 2026 18:02:33 +0200 Subject: [PATCH 3/3] fix issues --- .../GCI98.UseThenByInsteadOfOrderBy.Fixer.cs | 12 +-- src/Creedengo.Core/Models/Rule.cs | 87 +++++++++---------- src/Creedengo.Sandbox/RCS1200Sandbox.cs | 6 +- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs index 961a4b4f..62d276e0 100644 --- a/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs +++ b/src/Creedengo.Core/Analyzers/GCI98.UseThenByInsteadOfOrderBy.Fixer.cs @@ -20,7 +20,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { - if (root.FindToken(diagnostic.Location.SourceSpan.Start).Parent is not IdentifierNameSyntax nameSyntax) + if (root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true) is not SimpleNameSyntax nameSyntax) continue; if (nameSyntax.Parent is not MemberAccessExpressionSyntax memberAccess) continue; @@ -37,11 +37,13 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) private static Task FixAsync( Document document, MemberAccessExpressionSyntax memberAccess, - IdentifierNameSyntax nameSyntax) + SimpleNameSyntax nameSyntax) { - var newName = nameSyntax.Identifier.Text == "OrderBy" ? "ThenBy" : "ThenByDescending"; - var newMemberAccess = memberAccess.WithName( - SyntaxFactory.IdentifierName(newName).WithTriviaFrom(nameSyntax)); + var newIdentifier = nameSyntax.Identifier.Text == "OrderBy" ? "ThenBy" : "ThenByDescending"; + SimpleNameSyntax newNameSyntax = nameSyntax is GenericNameSyntax generic + ? generic.WithIdentifier(SyntaxFactory.Identifier(newIdentifier)) + : SyntaxFactory.IdentifierName(newIdentifier); + var newMemberAccess = memberAccess.WithName(newNameSyntax.WithTriviaFrom(nameSyntax)); return document.WithUpdatedRoot(memberAccess, newMemberAccess); } } diff --git a/src/Creedengo.Core/Models/Rule.cs b/src/Creedengo.Core/Models/Rule.cs index af775a10..e55b3792 100644 --- a/src/Creedengo.Core/Models/Rule.cs +++ b/src/Creedengo.Core/Models/Rule.cs @@ -1,50 +1,49 @@ -namespace Creedengo.Core.Models; +namespace Creedengo.Core.Models; internal static class Rule { - public static class Categories - { - public const string Design = "Design"; - public const string Usage = "Usage"; - public const string Performance = "Performance"; - } + public static class Categories + { + public const string Design = "Design"; + public const string Usage = "Usage"; + public const string Performance = "Performance"; + } - public static class Ids - { - public const string GCI69_DontCallFunctionsInLoopConditions = "GCI69"; - public const string GCI72_DontExecuteSqlCommandsInLoops = "GCI72"; - public const string GCI75_DontConcatenateStringsInLoops = "GCI75"; - public const string GCI81_UseStructLayout = "GCI81"; - public const string GCI82_VariableCanBeMadeConstant = "GCI82"; - public const string GCI83_ReplaceEnumToStringWithNameOf = "GCI83"; - public const string GCI84_AvoidAsyncVoidMethods = "GCI84"; - public const string GCI85_MakeTypeSealed = "GCI85"; - public const string GCI86_GCCollectShouldNotBeCalled = "GCI86"; - public const string GCI87_UseCollectionIndexer = "GCI87"; - public const string GCI88_DisposeResourceAsynchronously = "GCI88"; - public const string GCI89_DoNotPassMutableStructAsRefReadonly = "GCI89"; - public const string GCI90_UseCastInsteadOfSelect = "GCI90"; - public const string GCI91_UseWhereBeforeOrderBy = "GCI91"; - public const string GCI92_UseStringEmptyLength = "GCI92"; - public const string GCI93_ReturnTaskDirectly = "GCI93"; - public const string GCIACV_NonReadOnlyStruct = "GCIACV"; - public const string GCI95_UseIsOperatorInsteadOfAsOperator = "GCI95"; - public const string GCIXX_UnnecessaryAssignment = "GCIXX"; - public const string GCI96_UseEventArgsDotEmpty = "GCI96"; - public const string GCI2333_RemoveRedundantToCharArrayCall = "GCI2333"; - public const string GCI98_UseThenByInsteadOfOrderBy = "GCI98"; + public static class Ids + { + public const string GCI69_DontCallFunctionsInLoopConditions = "GCI69"; + public const string GCI72_DontExecuteSqlCommandsInLoops = "GCI72"; + public const string GCI75_DontConcatenateStringsInLoops = "GCI75"; + public const string GCI81_UseStructLayout = "GCI81"; + public const string GCI82_VariableCanBeMadeConstant = "GCI82"; + public const string GCI83_ReplaceEnumToStringWithNameOf = "GCI83"; + public const string GCI84_AvoidAsyncVoidMethods = "GCI84"; + public const string GCI85_MakeTypeSealed = "GCI85"; + public const string GCI86_GCCollectShouldNotBeCalled = "GCI86"; + public const string GCI87_UseCollectionIndexer = "GCI87"; + public const string GCI88_DisposeResourceAsynchronously = "GCI88"; + public const string GCI89_DoNotPassMutableStructAsRefReadonly = "GCI89"; + public const string GCI90_UseCastInsteadOfSelect = "GCI90"; + public const string GCI91_UseWhereBeforeOrderBy = "GCI91"; + public const string GCI92_UseStringEmptyLength = "GCI92"; + public const string GCI93_ReturnTaskDirectly = "GCI93"; + public const string GCIACV_NonReadOnlyStruct = "GCIACV"; + public const string GCI95_UseIsOperatorInsteadOfAsOperator = "GCI95"; + public const string GCIXX_UnnecessaryAssignment = "GCIXX"; + public const string GCI96_UseEventArgsDotEmpty = "GCI96"; + public const string GCI2333_RemoveRedundantToCharArrayCall = "GCI2333"; + public const string GCI98_UseThenByInsteadOfOrderBy = "GCI98"; + } - } - - /// Creates a diagnostic descriptor. - /// The rule id. - /// The rule title. - /// The rule message. - /// The rule category. - /// The rule severity. - /// The rule description. - /// The diagnostic descriptor. - public static DiagnosticDescriptor CreateDescriptor(string id, string title, string message, string category, DiagnosticSeverity severity, string description) => - new(id, title, message, category, severity, isEnabledByDefault: true, description, helpLinkUri: - $"https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/src/main/rules/{id}/csharp/{id}.asciidoc"); + /// Creates a diagnostic descriptor. + /// The rule id. + /// The rule title. + /// The rule message. + /// The rule category. + /// The rule severity. + /// The rule description. + /// The diagnostic descriptor. + public static DiagnosticDescriptor CreateDescriptor(string id, string title, string message, string category, DiagnosticSeverity severity, string description) => + new(id, title, message, category, severity, isEnabledByDefault: true, description, helpLinkUri: + $"https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/src/main/rules/{id}/csharp/{id}.asciidoc"); } diff --git a/src/Creedengo.Sandbox/RCS1200Sandbox.cs b/src/Creedengo.Sandbox/RCS1200Sandbox.cs index b4f9c906..b5ff3169 100644 --- a/src/Creedengo.Sandbox/RCS1200Sandbox.cs +++ b/src/Creedengo.Sandbox/RCS1200Sandbox.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Creedengo.Sandbox; +namespace Creedengo.Sandbox; internal class RCS1200Sandbox {