Skip to content

Commit

Permalink
fix: add target type to the RMG012 diagnostic
Browse files Browse the repository at this point in the history
RMG023 was also updated to include the target type, due to the way
the message is invoked alongside RMG012. The message format of RMG012
was updated to follow the format of RMG020.
  • Loading branch information
toddlucas committed Apr 1, 2023
1 parent ad35feb commit 4df144f
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Riok.Mapperly/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RMG008 | Mapper | Error | Could not create mapping.
RMG009 | Mapper | Info | Cannot map to read only property.
RMG010 | Mapper | Info | Cannot map from write only property.
RMG011 | Mapper | Info | Cannot map to write only property path.
RMG012 | Mapper | Info | Mapping source property not found.
RMG012 | Mapper | Info | Source property was not found for target property
RMG013 | Mapper | Error | No accessible constructor with mappable arguments found
RMG014 | Mapper | Warning | Cannot map to the configured constructor to be used by Mapperly
RMG015 | Mapper | Info | Cannot map to init only property path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private static void BuildInitOnlyPropertyMappings(INewInstanceBuilderContext<IMa
? DiagnosticDescriptors.RequiredPropertyNotMapped
: DiagnosticDescriptors.SourcePropertyNotFound,
targetProperty.Name,
ctx.Mapping.TargetType,
ctx.Mapping.SourceType);
continue;
}
Expand Down Expand Up @@ -97,6 +98,7 @@ private static void BuildInitPropertyMapping(
ctx.BuilderContext.ReportDiagnostic(
DiagnosticDescriptors.SourcePropertyNotFound,
targetProperty.Name,
ctx.Mapping.TargetType,
ctx.Mapping.SourceType);
return;
}
Expand Down Expand Up @@ -314,6 +316,7 @@ out sourcePath
ctx.BuilderContext.ReportDiagnostic(
DiagnosticDescriptors.SourcePropertyNotFound,
propertyConfig.Source,
ctx.Mapping.TargetType,
ctx.Mapping.SourceType);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void BuildMappingBody(IPropertiesContainerBuilderContext<IProperty
ctx.BuilderContext.ReportDiagnostic(
DiagnosticDescriptors.SourcePropertyNotFound,
targetProperty.Name,
ctx.Mapping.TargetType,
ctx.Mapping.SourceType);
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ internal static class DiagnosticDescriptors

public static readonly DiagnosticDescriptor SourcePropertyNotFound = new DiagnosticDescriptor(
"RMG012",
"Mapping source property not found",
"Property {0} on source type {1} was not found",
"Source property was not found for target property",
"The property {0} on the mapping target type {1} was not found on the mapping source type {2}",
DiagnosticCategories.Mapper,
DiagnosticSeverity.Info,
true);
Expand Down Expand Up @@ -185,7 +185,7 @@ internal static class DiagnosticDescriptors
public static readonly DiagnosticDescriptor RequiredPropertyNotMapped = new DiagnosticDescriptor(
"RMG023",
"Source property was not found for required target property",
"Required property {0} on mapping target type was not found on the mapping source type {1}",
"Required property {0} on mapping target type {1} was not found on the mapping source type {2}",
DiagnosticCategories.Mapper,
DiagnosticSeverity.Error,
true);
Expand Down
4 changes: 2 additions & 2 deletions test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ExistingTargetWithIgnoredSourceAndTargetPropertyShouldIgnore()
TestHelper.GenerateMapper(source, TestHelperOptions.AllowDiagnostics)
.Should()
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotMapped, "The property StringValue2 on the mapping source type A is not mapped to any property on the mapping target type B"))
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "Property StringValue on source type A was not found"))
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "The property StringValue on the mapping target type B was not found on the mapping source type A"))
.HaveSingleMethodBody("target.IntValue = source.IntValue;");
}

Expand All @@ -48,7 +48,7 @@ public void WithIgnoredSourcePropertyShouldIgnoreAndGenerateDiagnostics()

TestHelper.GenerateMapper(source, TestHelperOptions.AllowDiagnostics)
.Should()
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "Property IntValue on source type A was not found"))
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "The property IntValue on the mapping target type B was not found on the mapping source type A"))
.HaveSingleMethodBody(
"""
var target = new B();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void InitOnlyPropertySourceNotFoundShouldDiagnostic()

TestHelper.GenerateMapper(source, TestHelperOptions.AllowDiagnostics)
.Should()
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "Property StringValue on source type A was not found"))
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotFound, "The property StringValue on the mapping target type B was not found on the mapping source type A"))
.HaveDiagnostic(new(DiagnosticDescriptors.SourcePropertyNotMapped, "The property StringValue2 on the mapping source type A is not mapped to any property on the mapping target type B"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Diagnostics: [
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,4)-(11,74),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property StringValue on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property StringValue on the mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
Location: : (11,4)-(11,28),
Description: ,
HelpLink: ,
MessageFormat: Required property {0} on mapping target type was not found on the mapping source type {1},
Message: Required property StringValue on mapping target type was not found on the mapping source type A,
MessageFormat: Required property {0} on mapping target type {1} was not found on the mapping source type {2},
Message: Required property StringValue on mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Diagnostics: [
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,4)-(11,88),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property StringValue2 on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property StringValue2 on the mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Diagnostics: [
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,4)-(11,28),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property stringvalue on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property stringvalue on the mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Diagnostics: [
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,4)-(11,28),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property StringValueB on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property StringValueB on the mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
Diagnostics: [
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,4)-(11,65),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property MyValue2 on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property MyValue2 on the mapping target type B was not found on the mapping source type A,
Category: Mapper
},
{
Id: RMG012,
Title: Mapping source property not found,
Title: Source property was not found for target property,
Severity: Info,
WarningLevel: 1,
Location: : (11,65)-(11,128),
Description: ,
HelpLink: ,
MessageFormat: Property {0} on source type {1} was not found,
Message: Property MyValue on source type A was not found,
MessageFormat: The property {0} on the mapping target type {1} was not found on the mapping source type {2},
Message: The property MyValue on the mapping target type B was not found on the mapping source type A,
Category: Mapper
}
]
Expand Down

0 comments on commit 4df144f

Please # to comment.