Skip to content

Commit dfe3833

Browse files
committed
2 parents 9c22d71 + 85b9bd9 commit dfe3833

File tree

9 files changed

+50
-53
lines changed

9 files changed

+50
-53
lines changed

src/CustomCode-Analyzer.Vsix/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="CustomCode_Analyzer.Vsix.e1c79fe3-d19f-4bf9-9c0c-57ba1f95b494" Version="0.2.0" Language="en-US" Publisher="Jonathan Algar"/>
4+
<Identity Id="CustomCode_Analyzer.Vsix.e1c79fe3-d19f-4bf9-9c0c-57ba1f95b494" Version="0.2.1" Language="en-US" Publisher="Jonathan Algar"/>
55
<DisplayName>ODC Custom Code Analyzer</DisplayName>
66
<Description xml:space="preserve">Get feedback on your OutSytems Developer Cloud (ODC) custom C# code as you code.</Description>
77
<MoreInfo>https://github.com/jonathanalgar/CustomCode-Analyzer</MoreInfo>

src/CustomCode-Analyzer/Analyzer.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
using System.Collections.Generic;
44
using System.Collections.Immutable;
55
using System.Linq;
6+
using CustomCode_Analyzer.Helpers;
67
using Microsoft.CodeAnalysis;
78
using Microsoft.CodeAnalysis.CSharp.Syntax;
89
using Microsoft.CodeAnalysis.Diagnostics;
910
using Microsoft.CodeAnalysis.Text;
10-
using static CustomCode_Analyzer.AttributeNames;
11+
using static CustomCode_Analyzer.Helpers.AttributeNames;
1112

1213
namespace CustomCode_Analyzer
1314
{
@@ -349,7 +350,7 @@ public static class Categories
349350
/// Returns the full set of DiagnosticDescriptors that this analyzer is capable of producing.
350351
/// </summary>
351352
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
352-
ImmutableArray.Create(
353+
[
353354
NonPublicInterfaceRule,
354355
NoSingleInterfaceRule,
355356
ManyInterfacesRule,
@@ -373,8 +374,8 @@ public static class Categories
373374
UnsupportedParameterTypeRule,
374375
UnsupportedDefaultValueRule,
375376
PotentialStatefulImplementationRule,
376-
InputSizeLimitRule
377-
);
377+
InputSizeLimitRule,
378+
];
378379

379380
/// <summary>
380381
/// Entry point for the analyzer. Initializes analysis by setting up compilation-level
@@ -1151,12 +1152,12 @@ is InterfaceDeclarationSyntax ifDecl
11511152
// Create a comma-separated list of interface names
11521153
var interfaceNames = string.Join(", ", osInterfaces.Keys.OrderBy(n => n));
11531154
// Report diagnostic indicating multiple OSInterfaces
1154-
foreach (var osInterface in osInterfaces.Values)
1155+
foreach (var (Syntax, Symbol) in osInterfaces.Values)
11551156
{
11561157
context.ReportDiagnostic(
11571158
Diagnostic.Create(
11581159
ManyInterfacesRule,
1159-
osInterface.Syntax.Identifier.GetLocation(),
1160+
Syntax.Identifier.GetLocation(),
11601161
interfaceNames
11611162
)
11621163
);
@@ -1216,9 +1217,7 @@ is InterfaceDeclarationSyntax ifDecl
12161217
t => t.TypeKind == TypeKind.Struct && HasAttribute(t, OSStructureAttributeNames)
12171218
);
12181219

1219-
#pragma warning disable RS1024
12201220
var duplicates = allStructures.GroupBy(x => x.Name).Where(g => g.Count() > 1);
1221-
#pragma warning restore RS1024
12221221

12231222
foreach (var duplicate in duplicates)
12241223
{
@@ -1296,16 +1295,16 @@ Func<INamedTypeSymbol, bool> predicate
12961295
/// Anything not in this set (and is not null for reference types) is considered invalid.
12971296
/// </summary>
12981297
private static readonly ImmutableHashSet<SpecialType> ValidParameterSpecialTypes =
1299-
ImmutableHashSet.Create(
1300-
SpecialType.System_String,
1301-
SpecialType.System_Int32,
1302-
SpecialType.System_Int64,
1303-
SpecialType.System_Single,
1304-
SpecialType.System_Double,
1305-
SpecialType.System_Decimal,
1306-
SpecialType.System_Boolean,
1307-
SpecialType.System_DateTime
1308-
);
1298+
[
1299+
SpecialType.System_String,
1300+
SpecialType.System_Int32,
1301+
SpecialType.System_Int64,
1302+
SpecialType.System_Single,
1303+
SpecialType.System_Double,
1304+
SpecialType.System_Decimal,
1305+
SpecialType.System_Boolean,
1306+
SpecialType.System_DateTime,
1307+
];
13091308

13101309
/// <summary>
13111310
/// Checks whether a parameter's default value is a compile-time constant of a supported type.

src/CustomCode-Analyzer/CodeFixProvider.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
using System.Linq;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using CustomCode_Analyzer.Helpers;
89
using Microsoft.CodeAnalysis;
910
using Microsoft.CodeAnalysis.CodeActions;
1011
using Microsoft.CodeAnalysis.CodeFixes;
1112
using Microsoft.CodeAnalysis.CSharp;
1213
using Microsoft.CodeAnalysis.CSharp.Syntax;
1314
using Microsoft.CodeAnalysis.Editing;
14-
using static CustomCode_Analyzer.AttributeNames;
15+
using static CustomCode_Analyzer.Helpers.AttributeNames;
1516

1617
namespace CustomCode_Analyzer
1718
{
@@ -29,15 +30,15 @@ public class Fixer : CodeFixProvider
2930
/// Code fixes will only be offered for diagnostics with these IDs.
3031
/// </summary>
3132
public override ImmutableArray<string> FixableDiagnosticIds =>
32-
ImmutableArray.Create(
33+
[
3334
Analyzer.DiagnosticIds.NameBeginsWithUnderscore,
3435
Analyzer.DiagnosticIds.NonPublicInterface,
3536
Analyzer.DiagnosticIds.UnsupportedTypeMapping,
3637
Analyzer.DiagnosticIds.NonPublicStruct,
3738
Analyzer.DiagnosticIds.NonPublicStructureField,
3839
Analyzer.DiagnosticIds.NonPublicIgnored,
39-
Analyzer.DiagnosticIds.MissingStructureDecoration
40-
);
40+
Analyzer.DiagnosticIds.MissingStructureDecoration,
41+
];
4142

4243
/// <summary>
4344
/// Returns a <see cref="FixAllProvider"/> that can handle applying fixes across an entire solution,
@@ -240,8 +241,10 @@ CancellationToken cancellationToken
240241
return document;
241242

242243
var typeInfo = semanticModel.GetTypeInfo(parameterSyntax.Type, cancellationToken);
243-
var structSymbol = typeInfo.Type as INamedTypeSymbol;
244-
if (structSymbol is null || structSymbol.DeclaringSyntaxReferences.Length == 0)
244+
if (
245+
typeInfo.Type is not INamedTypeSymbol structSymbol
246+
|| structSymbol.DeclaringSyntaxReferences.Length == 0
247+
)
245248
return document;
246249

247250
// Get the StructDeclarationSyntax for the referenced struct
@@ -276,7 +279,7 @@ CancellationToken cancellationToken
276279
{
277280
// Otherwise, prepend this attribute before the first existing list
278281
var firstList = structDecl.AttributeLists.First();
279-
newStructDecl = structDecl.InsertNodesBefore(firstList, new[] { attributeList });
282+
newStructDecl = structDecl.InsertNodesBefore(firstList, [attributeList]);
280283
}
281284

282285
// Use a DocumentEditor to replace the old struct node with the new one containing[OSStructure]

src/CustomCode-Analyzer/CustomCode-Analyzer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<LangVersion>latest</LangVersion>
99
<RootNamespace>CustomCode_Analyzer</RootNamespace>
1010
<PackageId>CustomCode.Analyzer</PackageId>
11-
<Version>0.2.0</Version>
12-
<AssemblyVersion>0.2.0</AssemblyVersion>
13-
<FileVersion>0.2.0</FileVersion>
11+
<Version>0.2.1</Version>
12+
<AssemblyVersion>0.2.1</AssemblyVersion>
13+
<FileVersion>0.2.1</FileVersion>
1414
<Authors>Jonathan Algar</Authors>
1515
<Product>OutSystems Developer Cloud (ODC) Custom Code Analyzer</Product>
1616
<Description>Get feedback on your OutSytems Developer Cloud (ODC) custom C# code as you code.</Description>
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
using System.Collections.Generic;
22

3-
namespace CustomCode_Analyzer
3+
namespace CustomCode_Analyzer.Helpers
44
{
55
public static class AttributeNames
66
{
77
/// <summary>
88
/// Valid names for the OSInterface attribute.
99
/// </summary>
10-
internal static readonly HashSet<string> OSInterfaceAttributeNames = new()
11-
{
10+
internal static readonly HashSet<string> OSInterfaceAttributeNames =
11+
[
1212
"OSInterfaceAttribute",
1313
"OSInterface",
14-
};
14+
];
1515

1616
/// <summary>
1717
/// Valid names for the OSStructure attribute.
1818
/// </summary>
19-
internal static readonly HashSet<string> OSStructureAttributeNames = new()
20-
{
19+
internal static readonly HashSet<string> OSStructureAttributeNames =
20+
[
2121
"OSStructureAttribute",
2222
"OSStructure",
23-
};
23+
];
2424

2525
/// <summary>
2626
/// Valid names for the OSStructureField attribute.
2727
/// </summary>
28-
internal static readonly HashSet<string> OSStructureFieldAttributeNames = new()
29-
{
28+
internal static readonly HashSet<string> OSStructureFieldAttributeNames =
29+
[
3030
"OSStructureFieldAttribute",
3131
"OSStructureField",
32-
};
32+
];
3333

3434
/// <summary>
3535
/// Valid names for the OSIgnore attribute.
3636
/// </summary>
37-
internal static readonly HashSet<string> OSIgnoreAttributeNames = new()
38-
{
37+
internal static readonly HashSet<string> OSIgnoreAttributeNames =
38+
[
3939
"OSIgnoreAttribute",
4040
"OSIgnore",
41-
};
41+
];
4242
}
4343
}

src/CustomCode-Analyzer/Helpers/TypeMappingHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace CustomCode_Analyzer
4+
namespace CustomCode_Analyzer.Helpers
55
{
66
/// <summary>
77
/// Provides a centralized mapping between OutSystems <c>OSDataType</c> enum names

tests/CustomCode-Analyzer.Tests/CSharpVerifierHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public static ImmutableDictionary<string, ReportDiagnostic> NullableWarnings
1212
get
1313
{
1414
return ImmutableDictionary.CreateRange(
15-
new[]
16-
{
15+
[
1716
// Configure specific nullable warning codes as errors
1817
new KeyValuePair<string, ReportDiagnostic>(
1918
"CS8632",
@@ -23,7 +22,7 @@ public static ImmutableDictionary<string, ReportDiagnostic> NullableWarnings
2322
"CS8669",
2423
ReportDiagnostic.Error
2524
),
26-
}
25+
]
2726
);
2827
}
2928
}

tests/CustomCode-Analyzer.Tests/CustomCode-Analyzer.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<IsPackable>false</IsPackable>
99
<LangVersion>latest</LangVersion>
1010
<RootNamespace>CustomCode_Analyzer.Tests</RootNamespace>
11+
<ParallelizeTestCollections>true</ParallelizeTestCollections>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

tests/CustomCode-Analyzer.Tests/DetailedTestLogger.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ namespace CustomCode_Analyzer.Tests
88
/// Provides detailed logging capabilities for analyzer tests.
99
/// Implements ITestOutputHelper to capture and display test execution details.
1010
/// </summary>
11-
public class DetailedTestLogger : ITestOutputHelper
11+
public class DetailedTestLogger(TestContext testContext) : ITestOutputHelper
1212
{
13-
private readonly TestContext TestContext;
13+
private readonly TestContext TestContext = testContext;
1414
private readonly StringBuilder _output = new();
1515

16-
public DetailedTestLogger(TestContext testContext)
17-
{
18-
TestContext = testContext;
19-
}
20-
2116
public void WriteLine(string message)
2217
{
2318
_output.AppendLine(message);

0 commit comments

Comments
 (0)