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.cs
matches 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.md
as there may be removed diagnostics which are not present inDiagnosticDescriptors
anymore but which should still not be used for new diagnostics. - Add the new diagnostic to
AnalyzerReleases.Shipped.md
(Mapperly does not use theUnshipped
file). - 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.AllowDiagnostics
andShould().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_versions
inbuild/package.sh
. - Create a new file
Riok.Mapperly.Roslyn$(Version).props
insrc/Riok.Mapperly
similar to the existing ones and define constants and include dependencies as needed. - Update the default
ROSLYN_VERSION
insrc/Riok.Mapperly/Riok.Mapperly.csproj
. - Update the
Microsoft.CodeAnalysis.CSharp
dependency version. - Adjust the .NET version matrix of the
integration-test
GitHub 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.json
file as needed. - Add the new version in
Riok.Mapperly.IntegrationTests.Helpers.Versions
andRiok.Mapperly.IntegrationTests.BaseMapperTest.GetCurrentVersion
. - If generated code changes based on the new Roslyn version,
adjust the
VersionedSnapshotAttribute
s 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.