diff --git a/src/CustomCode-Analyzer.Vsix/source.extension.vsixmanifest b/src/CustomCode-Analyzer.Vsix/source.extension.vsixmanifest index a01198d..19c1574 100644 --- a/src/CustomCode-Analyzer.Vsix/source.extension.vsixmanifest +++ b/src/CustomCode-Analyzer.Vsix/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + ODC Custom Code Analyzer Get feedback on your OutSytems Developer Cloud (ODC) custom C# code as you code. https://github.com/jonathanalgar/CustomCode-Analyzer diff --git a/src/CustomCode-Analyzer/Analyzer.cs b/src/CustomCode-Analyzer/Analyzer.cs index 0f88978..61ce4ca 100644 --- a/src/CustomCode-Analyzer/Analyzer.cs +++ b/src/CustomCode-Analyzer/Analyzer.cs @@ -3,11 +3,12 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using CustomCode_Analyzer.Helpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Text; -using static CustomCode_Analyzer.AttributeNames; +using static CustomCode_Analyzer.Helpers.AttributeNames; namespace CustomCode_Analyzer { @@ -349,7 +350,7 @@ public static class Categories /// Returns the full set of DiagnosticDescriptors that this analyzer is capable of producing. /// public override ImmutableArray SupportedDiagnostics => - ImmutableArray.Create( + [ NonPublicInterfaceRule, NoSingleInterfaceRule, ManyInterfacesRule, @@ -373,8 +374,8 @@ public static class Categories UnsupportedParameterTypeRule, UnsupportedDefaultValueRule, PotentialStatefulImplementationRule, - InputSizeLimitRule - ); + InputSizeLimitRule, + ]; /// /// Entry point for the analyzer. Initializes analysis by setting up compilation-level @@ -1151,12 +1152,12 @@ is InterfaceDeclarationSyntax ifDecl // Create a comma-separated list of interface names var interfaceNames = string.Join(", ", osInterfaces.Keys.OrderBy(n => n)); // Report diagnostic indicating multiple OSInterfaces - foreach (var osInterface in osInterfaces.Values) + foreach (var (Syntax, Symbol) in osInterfaces.Values) { context.ReportDiagnostic( Diagnostic.Create( ManyInterfacesRule, - osInterface.Syntax.Identifier.GetLocation(), + Syntax.Identifier.GetLocation(), interfaceNames ) ); @@ -1216,9 +1217,7 @@ is InterfaceDeclarationSyntax ifDecl t => t.TypeKind == TypeKind.Struct && HasAttribute(t, OSStructureAttributeNames) ); -#pragma warning disable RS1024 var duplicates = allStructures.GroupBy(x => x.Name).Where(g => g.Count() > 1); -#pragma warning restore RS1024 foreach (var duplicate in duplicates) { @@ -1296,16 +1295,16 @@ Func predicate /// Anything not in this set (and is not null for reference types) is considered invalid. /// private static readonly ImmutableHashSet ValidParameterSpecialTypes = - ImmutableHashSet.Create( - SpecialType.System_String, - SpecialType.System_Int32, - SpecialType.System_Int64, - SpecialType.System_Single, - SpecialType.System_Double, - SpecialType.System_Decimal, - SpecialType.System_Boolean, - SpecialType.System_DateTime - ); + [ + SpecialType.System_String, + SpecialType.System_Int32, + SpecialType.System_Int64, + SpecialType.System_Single, + SpecialType.System_Double, + SpecialType.System_Decimal, + SpecialType.System_Boolean, + SpecialType.System_DateTime, + ]; /// /// Checks whether a parameter's default value is a compile-time constant of a supported type. diff --git a/src/CustomCode-Analyzer/CodeFixProvider.cs b/src/CustomCode-Analyzer/CodeFixProvider.cs index ff8f81b..62bd31b 100644 --- a/src/CustomCode-Analyzer/CodeFixProvider.cs +++ b/src/CustomCode-Analyzer/CodeFixProvider.cs @@ -5,13 +5,14 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using CustomCode_Analyzer.Helpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; -using static CustomCode_Analyzer.AttributeNames; +using static CustomCode_Analyzer.Helpers.AttributeNames; namespace CustomCode_Analyzer { @@ -29,15 +30,15 @@ public class Fixer : CodeFixProvider /// Code fixes will only be offered for diagnostics with these IDs. /// public override ImmutableArray FixableDiagnosticIds => - ImmutableArray.Create( + [ Analyzer.DiagnosticIds.NameBeginsWithUnderscore, Analyzer.DiagnosticIds.NonPublicInterface, Analyzer.DiagnosticIds.UnsupportedTypeMapping, Analyzer.DiagnosticIds.NonPublicStruct, Analyzer.DiagnosticIds.NonPublicStructureField, Analyzer.DiagnosticIds.NonPublicIgnored, - Analyzer.DiagnosticIds.MissingStructureDecoration - ); + Analyzer.DiagnosticIds.MissingStructureDecoration, + ]; /// /// Returns a that can handle applying fixes across an entire solution, @@ -240,8 +241,10 @@ CancellationToken cancellationToken return document; var typeInfo = semanticModel.GetTypeInfo(parameterSyntax.Type, cancellationToken); - var structSymbol = typeInfo.Type as INamedTypeSymbol; - if (structSymbol is null || structSymbol.DeclaringSyntaxReferences.Length == 0) + if ( + typeInfo.Type is not INamedTypeSymbol structSymbol + || structSymbol.DeclaringSyntaxReferences.Length == 0 + ) return document; // Get the StructDeclarationSyntax for the referenced struct @@ -276,7 +279,7 @@ CancellationToken cancellationToken { // Otherwise, prepend this attribute before the first existing list var firstList = structDecl.AttributeLists.First(); - newStructDecl = structDecl.InsertNodesBefore(firstList, new[] { attributeList }); + newStructDecl = structDecl.InsertNodesBefore(firstList, [attributeList]); } // Use a DocumentEditor to replace the old struct node with the new one containing[OSStructure] diff --git a/src/CustomCode-Analyzer/CustomCode-Analyzer.csproj b/src/CustomCode-Analyzer/CustomCode-Analyzer.csproj index 39178e1..d5a3c75 100644 --- a/src/CustomCode-Analyzer/CustomCode-Analyzer.csproj +++ b/src/CustomCode-Analyzer/CustomCode-Analyzer.csproj @@ -8,9 +8,9 @@ latest CustomCode_Analyzer CustomCode.Analyzer - 0.2.0 - 0.2.0 - 0.2.0 + 0.2.1 + 0.2.1 + 0.2.1 Jonathan Algar OutSystems Developer Cloud (ODC) Custom Code Analyzer Get feedback on your OutSytems Developer Cloud (ODC) custom C# code as you code. diff --git a/src/CustomCode-Analyzer/Helpers/AttributeNames.cs b/src/CustomCode-Analyzer/Helpers/AttributeNames.cs index f01e71c..96390bd 100644 --- a/src/CustomCode-Analyzer/Helpers/AttributeNames.cs +++ b/src/CustomCode-Analyzer/Helpers/AttributeNames.cs @@ -1,43 +1,43 @@ using System.Collections.Generic; -namespace CustomCode_Analyzer +namespace CustomCode_Analyzer.Helpers { public static class AttributeNames { /// /// Valid names for the OSInterface attribute. /// - internal static readonly HashSet OSInterfaceAttributeNames = new() - { + internal static readonly HashSet OSInterfaceAttributeNames = + [ "OSInterfaceAttribute", "OSInterface", - }; + ]; /// /// Valid names for the OSStructure attribute. /// - internal static readonly HashSet OSStructureAttributeNames = new() - { + internal static readonly HashSet OSStructureAttributeNames = + [ "OSStructureAttribute", "OSStructure", - }; + ]; /// /// Valid names for the OSStructureField attribute. /// - internal static readonly HashSet OSStructureFieldAttributeNames = new() - { + internal static readonly HashSet OSStructureFieldAttributeNames = + [ "OSStructureFieldAttribute", "OSStructureField", - }; + ]; /// /// Valid names for the OSIgnore attribute. /// - internal static readonly HashSet OSIgnoreAttributeNames = new() - { + internal static readonly HashSet OSIgnoreAttributeNames = + [ "OSIgnoreAttribute", "OSIgnore", - }; + ]; } } diff --git a/src/CustomCode-Analyzer/Helpers/TypeMappingHelper.cs b/src/CustomCode-Analyzer/Helpers/TypeMappingHelper.cs index 288a0a4..d616d1e 100644 --- a/src/CustomCode-Analyzer/Helpers/TypeMappingHelper.cs +++ b/src/CustomCode-Analyzer/Helpers/TypeMappingHelper.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace CustomCode_Analyzer +namespace CustomCode_Analyzer.Helpers { /// /// Provides a centralized mapping between OutSystems OSDataType enum names diff --git a/tests/CustomCode-Analyzer.Tests/CSharpVerifierHelper.cs b/tests/CustomCode-Analyzer.Tests/CSharpVerifierHelper.cs index fd9cc3c..1954391 100644 --- a/tests/CustomCode-Analyzer.Tests/CSharpVerifierHelper.cs +++ b/tests/CustomCode-Analyzer.Tests/CSharpVerifierHelper.cs @@ -12,8 +12,7 @@ public static ImmutableDictionary NullableWarnings get { return ImmutableDictionary.CreateRange( - new[] - { + [ // Configure specific nullable warning codes as errors new KeyValuePair( "CS8632", @@ -23,7 +22,7 @@ public static ImmutableDictionary NullableWarnings "CS8669", ReportDiagnostic.Error ), - } + ] ); } } diff --git a/tests/CustomCode-Analyzer.Tests/CustomCode-Analyzer.Tests.csproj b/tests/CustomCode-Analyzer.Tests/CustomCode-Analyzer.Tests.csproj index 31ca30b..875c698 100644 --- a/tests/CustomCode-Analyzer.Tests/CustomCode-Analyzer.Tests.csproj +++ b/tests/CustomCode-Analyzer.Tests/CustomCode-Analyzer.Tests.csproj @@ -8,6 +8,7 @@ false latest CustomCode_Analyzer.Tests + true diff --git a/tests/CustomCode-Analyzer.Tests/DetailedTestLogger.cs b/tests/CustomCode-Analyzer.Tests/DetailedTestLogger.cs index e2895ab..8cee41b 100644 --- a/tests/CustomCode-Analyzer.Tests/DetailedTestLogger.cs +++ b/tests/CustomCode-Analyzer.Tests/DetailedTestLogger.cs @@ -8,16 +8,11 @@ namespace CustomCode_Analyzer.Tests /// Provides detailed logging capabilities for analyzer tests. /// Implements ITestOutputHelper to capture and display test execution details. /// - public class DetailedTestLogger : ITestOutputHelper + public class DetailedTestLogger(TestContext testContext) : ITestOutputHelper { - private readonly TestContext TestContext; + private readonly TestContext TestContext = testContext; private readonly StringBuilder _output = new(); - public DetailedTestLogger(TestContext testContext) - { - TestContext = testContext; - } - public void WriteLine(string message) { _output.AppendLine(message);