[repo] Adding some guidance/requirements in CONTRIBUTING for nullable reference types and static analysis (#4284)

Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
Co-authored-by: Reiley Yang <reyang@microsoft.com>
This commit is contained in:
Mikel Blanchard 2023-03-08 15:54:41 -08:00 committed by GitHub
parent 990deee419
commit b200ceb86e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -214,3 +214,42 @@ only and does not affect the actual build of the project.
This repository also includes StyleCop ruleset files under the `./build` folder. This repository also includes StyleCop ruleset files under the `./build` folder.
These files are used to configure the _StyleCop.Analyzers_ which runs during These files are used to configure the _StyleCop.Analyzers_ which runs during
build. Breaking the rules will result in a build failure. build. Breaking the rules will result in a build failure.
## New projects
New projects are required to:
* Use [nullable reference
types](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/nullable-reference-types).
This should be enabled automatically via
[Common.props](https://github.com/open-telemetry/opentelemetry-dotnet/blob/990deee419ab4c1449efd628bed3df57a50963a6/build/Common.props#L9).
New project MUST NOT disable this.
* Pass [static
analysis](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/overview).
New projects MUST enable static analysis by specifying
`<AnalysisLevel>latest-all</AnalysisLevel>` in the project file (`.csproj`).
> **Note**
> There are other project-level features enabled automatically via
[Common.props](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/build/Common.props)
new projects must NOT manually override these settings.
## New code
New code files MUST enable [nullable reference
types](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/nullable-reference-types)
manually in projects where it is not automatically enabled project-wide. This is
done by specifying `#nullable enable` towards the top of the file (usually after
the copyright header). We are currently working towards enabling nullable
context in every project by updating code as it is worked on, this requirement
is to make sure the surface area of code needing updates is shrinking and not
expanding.
> **Note**
> The first time a project is updated to use nullable context in public APIs
some housekeeping needs to be done in public API definitions (`.publicApi`
folder). This can be done automatically via a code fix offered by the public API
analyzer.