Skip to content

Commit 45897c6

Browse files
committed
Improved compiler warning message.
1 parent bd74247 commit 45897c6

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ private static void MemberDisallowingDefaultValuesMustBeRequired(
127127
context.ReportDiagnostic(Diagnostic.Create(
128128
DiagnosticsDescriptors.MembersDisallowingDefaultValuesMustBeRequired,
129129
context.Node.GetLocation(),
130-
memberKind,
131-
memberName));
130+
memberKind, memberName, BuildTypeName(memberType)));
132131
}
133132

134133
private static void AnalyzeMethodWithUseDelegateFromConstructor(OperationAnalysisContext context)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/DiagnosticsDescriptors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ internal static class DiagnosticsDescriptors
4848
public static readonly DiagnosticDescriptor StaticPropertiesAreNotConsideredItems = new("TTRESG101", "Static properties are not considered enumeration items, use a field instead", "The static property '{0}' is not considered a enumeration item, use a field instead", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Warning, true);
4949
public static readonly DiagnosticDescriptor ExplicitComparerWithoutEqualityComparer = new("TTRESG102", "The type has a comparer defined but no equality comparer", "The type '{0}' has a comparer defined but no equality comparer", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Warning, true);
5050
public static readonly DiagnosticDescriptor ExplicitEqualityComparerWithoutComparer = new("TTRESG103", "The type has an equality comparer defined but no comparer", "The type '{0}' has an equality comparer defined but no comparer", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Warning, true);
51-
public static readonly DiagnosticDescriptor MembersDisallowingDefaultValuesMustBeRequired = new("TTRESG104", "The member must be marked as 'required' to ensure proper initialization", "The {0} '{1}' must be marked as 'required' to ensure proper initialization", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Warning, true);
51+
public static readonly DiagnosticDescriptor MembersDisallowingDefaultValuesMustBeRequired = new("TTRESG104", "The member must be marked as 'required' to ensure proper initialization", "The {0} '{1}' of type '{2}' must be marked as 'required' to ensure proper initialization", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Warning, true);
5252
}

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ public class TTRESG104_MembersDisallowingDefaultValuesMustBeRequired
1010
private const string _DIAGNOSTIC_ID = "TTRESG104";
1111

1212
[Theory]
13-
[InlineData("field", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member;")] // field: non-readonly VO
14-
[InlineData("field", "StructStringEnum Member;")] // field: non-readonly SE
15-
[InlineData("field", "TestUnion_struct_string_int Member;")] // field: non-readonly DU
16-
[InlineData("property", "StructStringEnum Member { get; set; }")] // property: non-readonly SE
17-
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; set; }")] // property: non-readonly VO
18-
[InlineData("property", "TestUnion_struct_string_int Member { get; set; }")] // property: non-readonly VO
19-
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; init; }")] // property: non-readonly with init
20-
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { set { } }")] // property: setter only
21-
[InlineData("property", "abstract IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; set; }")] // property: setter only
22-
public async Task Should_trigger_on_members(string memberKind, string member)
13+
[InlineData("field", "IntBasedStructValueObjectDoesNotAllowDefaultStructs", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member;")] // field: non-readonly VO
14+
[InlineData("field", "StructStringEnum", "StructStringEnum Member;")] // field: non-readonly SE
15+
[InlineData("field", "TestUnion_struct_string_int", "TestUnion_struct_string_int Member;")] // field: non-readonly DU
16+
[InlineData("property", "StructStringEnum", "StructStringEnum Member { get; set; }")] // property: non-readonly SE
17+
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; set; }")] // property: non-readonly VO
18+
[InlineData("property", "TestUnion_struct_string_int", "TestUnion_struct_string_int Member { get; set; }")] // property: non-readonly VO
19+
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; init; }")] // property: non-readonly with init
20+
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs", "IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { set { } }")] // property: setter only
21+
[InlineData("property", "IntBasedStructValueObjectDoesNotAllowDefaultStructs", "abstract IntBasedStructValueObjectDoesNotAllowDefaultStructs Member { get; set; }")] // property: abstract
22+
public async Task Should_trigger_on_members(
23+
string memberKind,
24+
string memberType,
25+
string member)
2326
{
2427
var typeModifer = member.Contains("abstract") ? "abstract " : null;
2528

@@ -61,7 +64,7 @@ namespace TestNamespace
6164
}
6265
""";
6366

64-
var expected = Verifier.Diagnostic(_DIAGNOSTIC_ID).WithLocation(0).WithArguments(memberKind, "Member");
67+
var expected = Verifier.Diagnostic(_DIAGNOSTIC_ID).WithLocation(0).WithArguments(memberKind, "Member", memberType);
6568
await Verifier.VerifyCodeFixAsync(code, expectedCode, [typeof(ValueObjectAttribute<>).Assembly, typeof(IntBasedStructValueObjectDoesNotAllowDefaultStructs).Assembly], expected);
6669
}
6770

0 commit comments

Comments
 (0)