Skip to content

Commit 58f7180

Browse files
committed
refactor: Added indicator for auto-generated code and nullability+
1 parent 3adb978 commit 58f7180

5 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public InterceptsLocationAttribute(string filePath, int line, int column)
124124
""";
125125

126126
// Generate the interceptor
127-
var interceptorSource = new StringBuilder();
127+
var interceptorSource = new StringBuilder(1000);
128+
interceptorSource.AppendLine(HeaderProvider.Header);
128129
interceptorSource.AppendLine(attribute);
129130
interceptorSource.AppendLine();
130131
interceptorSource.AppendLine("namespace Bunit");

src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/StubComponentBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public static bool GenerateStubComponent(AddStubClassInfo classInfo, SourceProdu
1313
{
1414
var hasSomethingToStub = false;
1515
var targetTypeSymbol = (INamedTypeSymbol)classInfo!.TargetType;
16-
var sourceBuilder = new StringBuilder();
16+
var sourceBuilder = new StringBuilder(1000);
1717

18+
sourceBuilder.AppendLine(HeaderProvider.Header);
1819
sourceBuilder.AppendLine($"namespace {classInfo.TargetTypeNamespace};");
1920
sourceBuilder.AppendLine();
2021
sourceBuilder.AppendLine($"internal partial class {classInfo.StubClassName} : global::Microsoft.AspNetCore.Components.ComponentBase");
@@ -39,7 +40,7 @@ public static bool GenerateStubComponent(AddStubClassInfo classInfo, SourceProdu
3940
var attributeLine = GetAttributeLine(member);
4041
sourceBuilder.AppendLine(attributeLine);
4142

42-
sourceBuilder.AppendLine($"\tpublic {propertyType} {propertyName} {{ get; set; }}");
43+
sourceBuilder.AppendLine($"\tpublic {propertyType} {propertyName} {{ get; set; }} = default!;");
4344
}
4445

4546
sourceBuilder.AppendLine("}");

src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ namespace Bunit.Web.Stubs.AttributeStubGenerator;
22

33
internal static class ComponentStubAttribute
44
{
5-
public static string ComponentStubAttributeSource = """
5+
public static string ComponentStubAttributeSource = $$"""
6+
{{HeaderProvider.Header}}
7+
68
#if NET5_0_OR_GREATER
79
namespace Bunit;
810

src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ private static void Execute(StubClassInfo classInfo, SourceProductionContext con
7373
{
7474
var hasSomethingToStub = false;
7575
var targetTypeSymbol = (INamedTypeSymbol)classInfo!.TargetType;
76-
var sourceBuilder = new StringBuilder();
76+
var sourceBuilder = new StringBuilder(1000);
7777

78+
sourceBuilder.AppendLine(HeaderProvider.Header);
7879
sourceBuilder.AppendLine($"namespace {classInfo.Namespace};");
7980

8081
sourceBuilder.AppendLine(
@@ -104,7 +105,7 @@ private static void Execute(StubClassInfo classInfo, SourceProductionContext con
104105
: "\t[global::Microsoft.AspNetCore.Components.CascadingParameter]";
105106

106107
sourceBuilder.AppendLine(attributeLine);
107-
sourceBuilder.AppendLine($"\tpublic {propertyType} {propertyName} {{ get; set; }}");
108+
sourceBuilder.AppendLine($"\tpublic {propertyType} {propertyName} {{ get; set; }} = default!;");
108109
}
109110

110111
sourceBuilder.AppendLine("}");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Bunit.Web.Stubs;
2+
3+
internal static class HeaderProvider
4+
{
5+
public const string Header = """
6+
// <auto-generated>
7+
// This code was generated by bunit.generators.
8+
// Changes to this file may cause incorrect behavior and will be lost if
9+
// the code is regenerated.
10+
// </auto-generated>
11+
#nullable enable
12+
""";
13+
}

0 commit comments

Comments
 (0)