Skip to content

Commit 914c6c2

Browse files
authored
docs: add contributor docs (#233)
1 parent 8f0c08d commit 914c6c2

16 files changed

+482
-63
lines changed

CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Contributing
2+
3+
We would love for you to contribute to Mapperly and help make it even better than it is today!
4+
Find information on how to contribute [in the docs](https://mapperly.riok.app/docs/contributing/).

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ dto.NumberOfSeats.Should().Be(10);
4747

4848
[Read the docs](https://mapperly.riok.app/docs/getting-started/installation) for any further information.
4949

50+
## How To Contribute
51+
52+
We would love for you to contribute to Mapperly and help make it even better than it is today!
53+
Find information on how to contribute [in the docs](https://mapperly.riok.app/docs/contributing/).
54+
5055
## License
5156

5257
Mapperly is [Apache 2.0](https://github.com/riok/mapperly/blob/main/LICENSE) licensed.

docs/README.md

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Architecture
2+
3+
Mapperly is an incremental .NET source generator implementation.
4+
Source generators are explained [here](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md)
5+
and [here](https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md).
6+
However, the incremental source generator of Mapperly is not yet optimal (see [#72](https://github.com/riok/mapperly/issues/72)).
7+
8+
## Projects
9+
10+
Mapperly is structured in two projects.
11+
`Riok.Mapperly.Abstractions` includes abstractions and attributes to be used by the application code,
12+
this is referenced by the source generator.
13+
`Riok.Mapperly` includes the implementation of the source generator.
14+
15+
## Flow
16+
17+
This describes the process implemented by Mapperly on a higher level.
18+
For each discovered `MapperAttribute` a new `DescriptorBuilder` is created.
19+
The `DescriptorBuilder` is responsible to build a `MapperDescriptor` which holds all the mappings.
20+
The `DescriptorBuilder` does this by following this process:
21+
1. Extracting the configuration from the attribute
22+
2. Extracting user implemented object factories
23+
3. Extracting user implemented and user defined mapping methods.
24+
It instantiates a `User*Mapping` (eg. `UserDefinedNewInstanceMethodMapping`) for each discovered mapping method and adds it to the queue of mappings to work on.
25+
4. For each mapping in the queue the `DescriptorBuilder` tries to build its implementation bodies.
26+
This is done by a so called `*MappingBodyBuilder`.
27+
A mapping body builder tries to map each property from the source to the target.
28+
To do this, it asks the `DescriptorBuilder` to create mappings for the according types.
29+
To create a mapping from one type to another, the `DescriptorBuilder` loops through a set of `*MappingBuilder`s.
30+
Each of the mapping builders try to create a mapping (an `ITypeMapping` implementation) for the asked type mapping by using
31+
one approach on how to map types (eg. an explicit cast is implemented by the `ExplicitCastMappingBuilder`).
32+
These mappings are queued in the queue of mappings which need the body to be built (currently body builders are only used for object to object (property-based) mappings).
33+
5. The `SourceEmitter` emits the code described by the `MapperDescriptor` and all its mappings.
34+
35+
## Roslyn multi targeting
36+
37+
Mapperly targets multiple Roslyn versions by building multiple NuGet packages
38+
and merging them together into a single one.
39+
Multi-targeting is needed to support new language features,
40+
such as required members introduced in C# 11,
41+
while still supporting older compiler versions.
42+
43+
See `build/package.sh` for details.
44+
45+
### Support a new roslyn version
46+
47+
1. Include the new version in `roslyn_versions` in `build/package.sh`.
48+
2. Create a new file `Riok.Mapperly.Roslyn$(Version).props` in `src/Riok.Mapperly` similar to the existing ones
49+
and define constants as needed.
50+
3. Update the default `ROSLYN_VERSION` in `src/Riok.Mapperly/Riok.Mapperly.csproj`.
51+
4. Adjust the .NET version matrix of the `integration-test` GitHub Actions job (defined in `.github/workflows/test.yml`)
52+
to include a dotnet version which is based on the added Roslyn version.
53+
5. Adjust the .NET version in the `global.json` file as needed.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Tests and linting
2+
3+
Mapperly is continuously tested by GitHub Actions.
4+
Tests are separated into integration and unit tests located in the `test` directory
5+
and use [xUnit](https://xunit.net/) and [VerifyTests](https://github.com/VerifyTests/Verify).
6+
You can run the tests by running
7+
```bash
8+
dotnet test
9+
```
10+
or by running the discovered tests in your IDE.
11+
12+
## Unit tests
13+
14+
The unit tests are located in the `tests/Riok.Mapperly.*.Tests` projects.
15+
These unit tests usually test exactly one unit of code or one type of mapping by isolating its code
16+
and verifying the reported diagnostics and the emitted code.
17+
Unit tests are easy to debug (you can debug them like any other code),
18+
but be reminded that these kind of tests only run on the latest supported target framework.
19+
20+
## Integration tests
21+
22+
The integration tests are located in `tests/Riok.Mapperly.IntegrationTests`.
23+
Integration tests are "a bit of everything" mappers.
24+
These tests run locally by referencing the source generator as an analyzer.
25+
In the CI pipeline, the integration tests reference the built NuGet package and
26+
are run on several supported target frameworks (including .NET 7.0 but also .NET Framework).
27+
28+
Debugging integration tests is a lot harder than debugging unit tests.
29+
Therefore if an integration test needs to be debugged,
30+
it is often easier to implement an unit test for the to be tested behaviour
31+
and debug the unit test instead of the integration test.
32+
See also the [debugging documentation](./debugging) topic on how to debug Mapperly.
33+
34+
## VerifyTests
35+
36+
Several tests use [VerifyTests/Verify](https://github.com/VerifyTests/Verify)
37+
and [VerifyTests/Verify.SourceGenerators](https://github.com/VerifyTests/Verify.SourceGenerators)
38+
to verify reported diagnostics and snapshot emitted code.
39+
To work with the tests of Mapperly you may find it helpful to read the documentation of it.
40+
41+
## Linting
42+
43+
The source of Mapperly is linted with multiple dotnet analyzers.
44+
The format is checked with `dotnet format`.
45+
To fix issues locally run
46+
```bash
47+
dotnet format
48+
```
49+
50+
and to verify there are no issues run
51+
```bash
52+
dotnet format --verify-no-changes
53+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Debugging
2+
3+
To debug the code generated by Mapperly just set a breakpoint in the generated code and you are ready to go.
4+
Check [here](../configuration/generated-source) on how to inspect the generated code.
5+
6+
To debug the Mapperly in unit tests set a breakpoint
7+
in the code of Mappery which you want to debug and run the tests in debug mode.
8+
9+
Since Mapperly runs integrated into the build pipeline,
10+
debugging integration tests and other applications needs some more effort.
11+
Mapperly uses a compile constant `DEBUG_SOURCE_GENERATOR` to determine whether to attach a debugger.
12+
If it is set, it tries to attach a debugger
13+
(it uses `Debugger.Launch()` on windows, on other operating systems it tries to launch JetBrains Rider)
14+
and waits for the connection of the debugger (for up to 30 seconds).
15+
If the automatic debugger attachment fails you can use these 30 seconds to attach the debugger manually
16+
(for vs 2022 see [attach to running processes](https://docs.microsoft.com/en-us/visualstudio/debugger/attach-to-running-processes-with-the-visual-studio-debugger?view=vs-2022)).
17+
You can use the `DefineConstants` dontet build or csproj parameter to define the `DEBUG_SOURCE_GENERATOR` constant
18+
or temporary comment the conditional attribute on `DebuggerUtil.AttachDebugger()`.
19+
20+
For the debugger attachment with JetBrains Rider to work correctly,
21+
`Generate Shell Scripts` needs to be enabled in the JetBrains ToolBox
22+
and the generated shell scripts need to be on the path (Mapperly calls `rider attach-to-process {pid} {Mapperly-Sln-File}`).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Documentation
2+
3+
The Mapperly documentation is built using [Docusaurus 2](https://docusaurus.io/)
4+
and is located in the `docs` directory.
5+
6+
### Dependencies
7+
8+
Docusaurus is based on the node ecosystem.
9+
A `.node-version` file provides the node version number to be used.
10+
This file can be interpreted by several node version managers (eg. [fnm](https://github.com/Schniz/fnm) or [nvm](https://github.com/nvm-sh/nvm)).
11+
Make sure you use a node version matching the version in `.node-version` for all following commands.
12+
13+
To install documentation dependencies run:
14+
```bash
15+
npm i
16+
```
17+
18+
### Update generated documentation
19+
20+
To build the generated parts of the documentation
21+
(eg. the API documentation (located in `docs/99-api`), the table of analyzer rules, the samples, ...)
22+
ensure the dotnet solution is built or run `dontet build` in the solutions root directory.
23+
Then run the prebuild script:
24+
25+
```bash
26+
npm run prebuild
27+
```
28+
29+
To reflect changes, this command needs to be re-run each time the source of the generated output changes.
30+
31+
### Local Development
32+
33+
```bash
34+
npm run start
35+
```
36+
37+
This command starts a local development server and opens up a browser window.
38+
Most changes are reflected live without having to restart the server.
39+
The documentation search does not work when using the local development server,
40+
as it depends on the statically built content (see [build](#build)).
41+
42+
### Build
43+
44+
```bash
45+
npm run build
46+
```
47+
48+
This command generates static content into the `build` directory
49+
and can be served using any static contents hosting service or locally using `npm run serve`.

0 commit comments

Comments
 (0)