Skip to content

Commit

Permalink
fixed various warnings and updated test snapshots (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored Nov 11, 2023
1 parent 368c08c commit fd13724
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 81 deletions.
5 changes: 3 additions & 2 deletions sample/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#### .NET Coding Conventions ####
dotnet_diagnostic.CA1019.severity = none
dotnet_diagnostic.CA1050.severity = none
dotnet_diagnostic.CA1303.severity = none
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.CA1822.severity = none
dotnet_diagnostic.CA1848.severity = none
dotnet_diagnostic.CA2254.severity = none
dotnet_diagnostic.CA1822.severity = none
dotnet_diagnostic.CA5394.severity = none
dotnet_diagnostic.CA1707.severity = none
resharper_virtual_member_call_in_constructor_highlighting = none
resharper_nullable_warning_suppression_is_used_highlighting = none
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Sample.Classic.Restful.Controllers;

[Route("[controller]")]
public class WeatherForecastController(ILogger<WeatherForecastController> logger) : RestfulApiController
public class WeatherForecastController : RestfulApiController
{
private static readonly string[] Summaries =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Sample.Restful.Controllers;

[Route("[controller]")]
public class WeatherForecastController(ILogger<WeatherForecastController> logger) : RestfulApiController
public class WeatherForecastController : RestfulApiController
{
private static readonly string[] Summaries =
{
Expand Down
8 changes: 2 additions & 6 deletions src/Analyzers/ControllerActionBodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,8 @@ private void GenerateMethods(
"Rocket.Surgery.LaunchPad.AspNetCore.Validation"
};

var usings = syntax.SyntaxTree.GetCompilationUnitRoot().Usings;
foreach (var additionalUsing in additionalUsings)
{
if (usings.Any(z => z.Name.ToString() == additionalUsing)) continue;
usings = usings.Add(UsingDirective(ParseName(additionalUsing)));
}
var usings = syntax.SyntaxTree.GetCompilationUnitRoot().Usings
.AddDistinctUsingStatements(additionalUsings.Where(z => !string.IsNullOrWhiteSpace(z)));

var cu = CompilationUnit(
List<ExternAliasDirectiveSyntax>(),
Expand Down
8 changes: 2 additions & 6 deletions src/Analyzers/GraphqlMutationActionBodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,8 @@ private void GenerateMethods(

var additionalUsings = new[] { "MediatR" };

var usings = syntax.SyntaxTree.GetCompilationUnitRoot().Usings;
foreach (var additionalUsing in additionalUsings)
{
if (usings.Any(z => z.Name.ToString() == additionalUsing)) continue;
usings = usings.Add(UsingDirective(ParseName(additionalUsing)));
}
var usings = syntax.SyntaxTree.GetCompilationUnitRoot().Usings
.AddDistinctUsingStatements(additionalUsings.Where(z => !string.IsNullOrWhiteSpace(z)));

var cu = CompilationUnit(
List<ExternAliasDirectiveSyntax>(),
Expand Down
10 changes: 3 additions & 7 deletions src/Analyzers/GraphqlOptionalPropertyTrackingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,12 @@ static void AddNamespacesFromPropertyType(HashSet<string> namespaces, ITypeSymbo
);

classToInherit = classToInherit.AddMembers(createMethod);
var usings = declaration.SyntaxTree.GetCompilationUnitRoot().Usings
.AddDistinctUsingStatements(namespaces.Where(z => !string.IsNullOrWhiteSpace(z)));

var cu = CompilationUnit(
List<ExternAliasDirectiveSyntax>(),
List(
declaration.SyntaxTree.GetCompilationUnitRoot().Usings.AddRange(
namespaces
.Where(z => !string.IsNullOrWhiteSpace(z))
.Select(z => UsingDirective(ParseName(z)))
)
),
List(usings),
List<AttributeListSyntax>(),
SingletonList<MemberDeclarationSyntax>(
symbol.ContainingNamespace.IsGlobalNamespace
Expand Down
30 changes: 17 additions & 13 deletions src/Analyzers/PropertyTrackingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;


namespace Rocket.Surgery.LaunchPad.Analyzers;

/// <summary>
Expand Down Expand Up @@ -69,7 +70,13 @@ INamedTypeSymbol targetSymbol
.WithModifiers(SyntaxTokenList.Create(Token(SyntaxKind.PublicKeyword)))
.WithOpenBraceToken(Token(SyntaxKind.OpenBraceToken))
.WithCloseBraceToken(Token(SyntaxKind.CloseBraceToken))
;
.WithLeadingTrivia(
Trivia(
PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)
.WithErrorCodes(SingletonSeparatedList<ExpressionSyntax>(IdentifierName("CA1034")))
)
);

var getChangedStateMethodInitializer = InitializerExpression(SyntaxKind.ObjectInitializerExpression);
var applyChangesBody = Block();
var resetChangesBody = Block();
Expand Down Expand Up @@ -125,7 +132,7 @@ static void AddNamespacesFromPropertyType(HashSet<string> namespaces, ITypeSymbo
)
);
applyChangesBody = applyChangesBody.AddStatements(
GenerateApplyChangesBodyPart(propertySymbol, IdentifierName("value"), isRecord)
GenerateApplyChangesBodyPart(propertySymbol, IdentifierName("state"), isRecord)
);
resetChangesBody = resetChangesBody.AddStatements(
ExpressionStatement(
Expand Down Expand Up @@ -176,7 +183,7 @@ static void AddNamespacesFromPropertyType(HashSet<string> namespaces, ITypeSymbo
.WithParameterList(
ParameterList(
SingletonSeparatedList(
Parameter(Identifier("value")).WithType(
Parameter(Identifier("state")).WithType(
IdentifierName(targetSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))
)
)
Expand All @@ -185,7 +192,7 @@ static void AddNamespacesFromPropertyType(HashSet<string> namespaces, ITypeSymbo
.WithBody(
applyChangesBody.AddStatements(
ExpressionStatement(InvocationExpression(IdentifierName("ResetChanges"))),
ReturnStatement(IdentifierName("value"))
ReturnStatement(IdentifierName("state"))
)
);
var resetChangesMethod = MethodDeclaration(IdentifierName(symbol.Name), "ResetChanges")
Expand Down Expand Up @@ -215,15 +222,12 @@ static void AddNamespacesFromPropertyType(HashSet<string> namespaces, ITypeSymbo
resetChangesImplementation
);

var usings = declaration.SyntaxTree.GetCompilationUnitRoot().Usings
.AddDistinctUsingStatements(namespaces.Where(z => !string.IsNullOrWhiteSpace(z)));

var cu = CompilationUnit(
List<ExternAliasDirectiveSyntax>(),
List(
declaration.SyntaxTree.GetCompilationUnitRoot().Usings.AddRange(
namespaces
.Where(z => !string.IsNullOrWhiteSpace(z))
.Select(z => UsingDirective(ParseName(z)))
)
),
List(usings),
List<AttributeListSyntax>(),
SingletonList<MemberDeclarationSyntax>(
symbol.ContainingNamespace.IsGlobalNamespace
Expand Down Expand Up @@ -270,7 +274,7 @@ private static StatementSyntax GenerateApplyChangesBodyPart(
AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
IdentifierName(propertySymbol.Name),
IdentifierName(propertySymbol.Name)
PostfixUnaryExpression(SyntaxKind.SuppressNullableWarningExpression, IdentifierName(propertySymbol.Name))
)
)
)
Expand All @@ -279,7 +283,7 @@ private static StatementSyntax GenerateApplyChangesBodyPart(
: AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, valueIdentifier, IdentifierName(propertySymbol.Name)),
IdentifierName(propertySymbol.Name)
PostfixUnaryExpression(SyntaxKind.SuppressNullableWarningExpression, IdentifierName(propertySymbol.Name))
)
)
)
Expand Down
13 changes: 13 additions & 0 deletions src/Analyzers/SymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Rocket.Surgery.LaunchPad.Analyzers;

Expand All @@ -8,4 +10,15 @@ internal static class SymbolExtensions
{
return symbol.GetAttributes().FirstOrDefault(z => z.AttributeClass?.Name == attributeClassName);
}

public static SyntaxList<UsingDirectiveSyntax> AddDistinctUsingStatements(this SyntaxList<UsingDirectiveSyntax> usingDirectiveSyntax, IEnumerable<string> namespaces)
{
foreach (var additionalUsing in namespaces.Where(z => !string.IsNullOrWhiteSpace(z)))
{
if (usingDirectiveSyntax.Any(z => z.Name.ToString() == additionalUsing)) continue;
usingDirectiveSyntax = usingDirectiveSyntax.Add(UsingDirective(ParseName(additionalUsing)));
}

return usingDirectiveSyntax;
}
}
6 changes: 3 additions & 3 deletions src/AspNetCore.Testing/LaunchPadExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Rocket.Surgery.LaunchPad.AspNetCore.Testing;

/// <summary>
/// An <see cref="IAlbaExtension"/> that is used for launchpad <see cref="TTestAssembly"/> is used to get the assembly to test
/// An <see cref="IAlbaExtension"/> that is used for launchpad <typeparamref name="TTestAssembly"/> is used to get the assembly to test
/// </summary>
/// <typeparam name="TTestAssembly"></typeparam>
public class LaunchPadExtension<TTestAssembly> : LaunchPadExtension
Expand Down Expand Up @@ -94,5 +94,5 @@ public virtual IHostBuilder Configure(IHostBuilder builder)
return builder;
}
}
#pragma warning enable CA1816
#pragma warning enable CA1063
#pragma warning restore CA1816
#pragma warning restore CA1063
3 changes: 1 addition & 2 deletions src/Foundation/Assigned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public static implicit operator Assigned<T>(T value)
/// <summary>
/// Implicitly gets the Assigned value.
/// </summary>
[return: MaybeNull]
public static implicit operator T(Assigned<T> assigned)
public static implicit operator T?(Assigned<T> assigned)
{
return assigned.Value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Spatial.NewtonsoftJson/WktGeometryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WktGeometryConverter : GeometryConverter
private readonly WKTReader _wktReader;

/// <summary>
/// Creates an instance of this class using <see cref="GeoJsonSerializer.Wgs84Factory" /> to create geometries.
/// Creates an instance of this class using <see cref="WktGeometryConverter.Wgs84Factory" /> to create geometries.
/// </summary>
public WktGeometryConverter() : this(Wgs84Factory)
{
Expand Down
1 change: 1 addition & 0 deletions test/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dotnet_diagnostic.CA1720.severity = none
dotnet_diagnostic.CA1812.severity = none
dotnet_diagnostic.CA1848.severity = none
dotnet_diagnostic.CA1851.severity = none
dotnet_diagnostic.CA1852.severity = none
dotnet_diagnostic.CA2000.severity = none
dotnet_diagnostic.CA2225.severity = none
dotnet_diagnostic.CA2227.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class PatchRocket
{
public Rocket.Surgery.LaunchPad.Foundation.Assigned<string> SerialNumber { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<string>.Empty(default);
public Rocket.Surgery.LaunchPad.Foundation.Assigned<int> Type { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<int>.Empty(default);
#pragma warning disable CA1034
public record Changes
{
public bool SerialNumber { get; init; }
Expand All @@ -20,20 +21,20 @@ public partial class PatchRocket
{SerialNumber = SerialNumber.HasBeenSet(), Type = Type.HasBeenSet()};
}

public global::Request ApplyChanges(global::Request value)
public global::Request ApplyChanges(global::Request state)
{
if (SerialNumber.HasBeenSet())
{
value.SerialNumber = SerialNumber;
state.SerialNumber = SerialNumber!;
}

if (Type.HasBeenSet())
{
value.Type = Type;
state.Type = Type!;
}

ResetChanges();
return value;
return state;
}

public PatchRocket ResetChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class PatchRocket
{
public Rocket.Surgery.LaunchPad.Foundation.Assigned<string> SerialNumber { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<string>.Empty(default);
public Rocket.Surgery.LaunchPad.Foundation.Assigned<int> Type { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<int>.Empty(default);
#pragma warning disable CA1034
public record Changes
{
public bool SerialNumber { get; init; }
Expand All @@ -20,20 +21,20 @@ public partial class PatchRocket
{SerialNumber = SerialNumber.HasBeenSet(), Type = Type.HasBeenSet()};
}

public global::Request ApplyChanges(global::Request value)
public global::Request ApplyChanges(global::Request state)
{
if (SerialNumber.HasBeenSet())
{
value.SerialNumber = SerialNumber;
state.SerialNumber = SerialNumber!;
}

if (Type.HasBeenSet())
{
value.Type = Type;
state.Type = Type!;
}

ResetChanges();
return value;
return state;
}

public PatchRocket ResetChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class PatchRocket
{
public Rocket.Surgery.LaunchPad.Foundation.Assigned<string> SerialNumber { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<string>.Empty(default);
public Rocket.Surgery.LaunchPad.Foundation.Assigned<int> Type { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<int>.Empty(default);
#pragma warning disable CA1034
public record Changes
{
public bool SerialNumber { get; init; }
Expand All @@ -20,20 +21,20 @@ public partial class PatchRocket
{SerialNumber = SerialNumber.HasBeenSet(), Type = Type.HasBeenSet()};
}

public global::Request ApplyChanges(global::Request value)
public global::Request ApplyChanges(global::Request state)
{
if (SerialNumber.HasBeenSet())
{
value.SerialNumber = SerialNumber;
state.SerialNumber = SerialNumber!;
}

if (Type.HasBeenSet())
{
value.Type = Type;
state.Type = Type!;
}

ResetChanges();
return value;
return state;
}

public PatchRocket ResetChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial record PatchRocket
public Rocket.Surgery.LaunchPad.Foundation.Assigned<Guid> Id { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<Guid>.Empty(default);
public Rocket.Surgery.LaunchPad.Foundation.Assigned<string> SerialNumber { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<string>.Empty(default);
public Rocket.Surgery.LaunchPad.Foundation.Assigned<int> Type { get; set; } = Rocket.Surgery.LaunchPad.Foundation.Assigned<int>.Empty(default);
#pragma warning disable CA1034
public record Changes
{
public bool Id { get; init; }
Expand All @@ -23,25 +24,25 @@ public partial record PatchRocket
{Id = Id.HasBeenSet(), SerialNumber = SerialNumber.HasBeenSet(), Type = Type.HasBeenSet()};
}

public global::Request ApplyChanges(global::Request value)
public global::Request ApplyChanges(global::Request state)
{
if (Id.HasBeenSet())
{
value = value with {Id = Id};
state = state with {Id = Id!};
}

if (SerialNumber.HasBeenSet())
{
value = value with {SerialNumber = SerialNumber};
state = state with {SerialNumber = SerialNumber!};
}

if (Type.HasBeenSet())
{
value = value with {Type = Type};
state = state with {Type = Type!};
}

ResetChanges();
return value;
return state;
}

public PatchRocket ResetChanges()
Expand Down
Loading

0 comments on commit fd13724

Please sign in to comment.