Common tasks
This page provides todo lists for some common tasks one may encounter while contributing to Mapperly.
New diagnostic
To introduce a new diagnostic follow these steps:
- Ensure no existing diagnostic in
Riok.Mapperly.Diagnostics.DiagnosticDescriptors.csmatches the new use case. - Create a new public static readonly entry following the existing naming and formatting style,
as ID use
RMG<NUMBER>with<NUMBER>being the highest already used number plus one. The highest used number can be found inAnalyzerReleases.Shipped.mdas there may be removed diagnostics which are not present inDiagnosticDescriptorsanymore but which should still not be used for new diagnostics. - Add the new diagnostic to
AnalyzerReleases.Shipped.md(Mapperly does not use theUnshippedfile). - Add a new documentation file at
docs/docs/configuration/analyzer-diagnostics/{id}.mdx(as needed) - Add a unit test generating and asserting the added diagnostic (use
TestHelperOptions.AllowDiagnosticsandShould().HaveDiagnostic(...).HaveAssertedAllDiagnostics().
It is not necessary to update the analyzer-diagnostics/index.mdx documentation file manually,
as it is generated automatically on the basis of the AnalyzerReleases.Shipped.md file.
New public API
If new public API surface is introduced in Riok.Mapperly.Abstractions or existing API surface is modified,
the PublicApiTest snapshot test needs to be updated.
See also VerifyTests.
Add support for a new roslyn version
To support a new roslyn version via multi targeting follow these steps (see also architecture/roslyn multi targeting):
- Include the new version in
roslyn_versionsinbuild/package.sh. - Create a new file
Riok.Mapperly.Roslyn$(Version).propsinsrc/Riok.Mapperlysimilar to the existing ones and define constants and include dependencies as needed. - Update the default
ROSLYN_VERSIONinsrc/Riok.Mapperly/Riok.Mapperly.csproj. - Update the
Microsoft.CodeAnalysis.CSharpdependency version. - Adjust the .NET version matrix of the
integration-testGitHub Actions job (defined in.github/workflows/test.yml) to include a dotnet version which is based on the added Roslyn version. - Adjust the .NET version in the
global.jsonfile as needed. - Add the new version in
Riok.Mapperly.IntegrationTests.Helpers.VersionsandRiok.Mapperly.IntegrationTests.BaseMapperTest.GetCurrentVersion. - If generated code changes based on the new Roslyn version,
adjust the
VersionedSnapshotAttributes as needed. - Adjust the documentation as needed.
- Add new preprocessor constants to
.csharpierrc.yaml. - Add new GitHub required checks as needed (needs to be done by a maintainer).
Mapping syntax
Mapperly Mappings use Roslyn syntax trees.
RoslynQuoter and SharpLab
are fantastic tools to understand and work with Roslyn syntax trees.
The Riok.Mapperly.Emit.Syntax.SyntaxFactoryHelper and Microsoft.CodeAnalysis.CSharp.SyntaxFactory classes help building these syntax trees.