From b200ceb86ecbfb4711c796025a75aa5bc97f0550 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 8 Mar 2023 15:54:41 -0800 Subject: [PATCH] [repo] Adding some guidance/requirements in CONTRIBUTING for nullable reference types and static analysis (#4284) Co-authored-by: Cijo Thomas Co-authored-by: Reiley Yang --- CONTRIBUTING.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9aec1d40d..c3ed947ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. These files are used to configure the _StyleCop.Analyzers_ which runs during 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 + `latest-all` 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.