Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit ffa43de

Browse files
authored
feat: use global property file for generic code analyzers and project configuration (#332)
* open telemetry library nullable * xml comment note required ruleset
1 parent 13eb62d commit ffa43de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+401
-291
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,12 @@ ASALocalRun/
329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331331

332-
# Visual studio code
333-
.vscode
332+
# Visual Studio Code
333+
**/.vscode/*
334+
!.vscode/settings.json
334335

335336
# Ignore HealthCheckdb
336337
*healthchecksdb*
337338

338339
# Test Results
339-
/tests-results
340+
/tests-results

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.rulers": [
3+
80,
4+
120
5+
]
6+
}

build/dotnet/Common.props

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project>
2+
<PropertyGroup>
3+
<LangVersion>9.0</LangVersion>
4+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
5+
6+
<Nullable>enable</Nullable>
7+
8+
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)/eSchool.ruleset</CodeAnalysisRuleSet>
9+
</PropertyGroup>
10+
11+
<!-- <PropertyGroup Condition="'$(Configuration)'=='Release'">
12+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
13+
</PropertyGroup> -->
14+
15+
<PropertyGroup Label="Package versions used in this repository">
16+
<!--
17+
Please sort alphabetically.
18+
Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax.
19+
-->
20+
<MicrosoftCodeAnalysisFxCopAnalyzersPkgVer>[3.3.0,4.0)</MicrosoftCodeAnalysisFxCopAnalyzersPkgVer>
21+
<MicrosoftCodeCoveragePkgVer>[16.9.1]</MicrosoftCodeCoveragePkgVer>
22+
<StyleCopAnalyzersPkgVer>[1.2.0-*,2.0)</StyleCopAnalyzersPkgVer>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/stylecop.json" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersPkgVer)" Condition="'$(SkipAnalysis)'!='true'">
31+
<PrivateAssets>All</PrivateAssets>
32+
</PackageReference>
33+
<PackageReference Include="Microsoft.CodeCoverage" Version="$(MicrosoftCodeCoveragePkgVer)" Condition="'$(Configuration)'=='Release'"/>
34+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(MicrosoftCodeAnalysisFxCopAnalyzersPkgVer)" Condition="'$(SkipAnalysis)'!='true'">
35+
<PrivateAssets>all</PrivateAssets>
36+
</PackageReference>
37+
</ItemGroup>
38+
</Project>

eSchool.ruleset renamed to build/dotnet/eSchool.ruleset

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,12 @@
2424
<Rule Id="SX1309" Action="Warning" />
2525
<!-- Do Not Prefix Local Members With This -->
2626
<Rule Id="SX1101" Action="Warning" />
27+
<!-- File May Only Contain A Single Type -->
28+
<Rule Id="SA1402" Action="None" />
29+
30+
</Rules>
31+
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp" RuleNamespace="Microsoft.CodeAnalysis.CSharp">
32+
<!-- Missing XML comment for publicly visible type or member -->
33+
<Rule Id="CS1591" Action="None" />
2734
</Rules>
2835
</RuleSet>
File renamed without changes.

src/ApiGateways/eSchool.GraphQL/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL
1111
{
12-
public class Program
12+
public static class Program
1313
{
1414
public static readonly string Namespace = typeof(Program).Namespace!;
1515
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
1616

17+
[System.Diagnostics.CodeAnalysis.SuppressMessage(
18+
"Design",
19+
"CA1031:Do not catch general exception types",
20+
Justification = "Top level all exception catcher")]
1721
public static int Main(string[] args)
1822
{
1923
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
@@ -52,7 +56,6 @@ public static IHostBuilder CreateHostBuilder(IConfiguration configuration, strin
5256
webBuilder.UseSerilog();
5357
});
5458

55-
5659
private static ILogger CreateSerilogLogger(IConfiguration configuration)
5760
{
5861
return new LoggerConfiguration()

src/ApiGateways/eSchool.GraphQL/Startup.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using HotChocolate.Configuration;
32
using Microsoft.AspNetCore.Builder;
43
using Microsoft.AspNetCore.Hosting;
54
using Microsoft.Extensions.DependencyInjection;
@@ -9,6 +8,10 @@
98

109
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL
1110
{
11+
[System.Diagnostics.CodeAnalysis.SuppressMessage(
12+
"Performance",
13+
"CA1822:Mark members as static",
14+
Justification = "Can not mark this class static. We can remove it when we read configuration")]
1215
public class Startup
1316
{
1417
public const string Enrolling = "enrolling";

src/Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'eSchool.sln'))\build\dotnet\Common.props" />
3+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace OpenCodeFoundation.OpenTelemetry
4+
{
5+
public class JaegerOptions
6+
{
7+
[MemberNotNullWhen(true, nameof(ServiceName), nameof(Host))]
8+
public bool Enabled { get; set; }
9+
10+
public string? ServiceName { get; set; }
11+
12+
public string? Host { get; set; }
13+
14+
public int? Port { get; set; }
15+
}
16+
}

src/Libraries/OpenTelemetry/OpenTelemetry.csproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>OpenCodeFoundation.OpenTelemetry</AssemblyName>
66
<RootNamespace>OpenCodeFoundation.OpenTelemetry</RootNamespace>
7-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8-
9-
<CodeAnalysisRuleSet>..\..\..\eSchool.ruleset</CodeAnalysisRuleSet>
107
</PropertyGroup>
118

129
<ItemGroup>
@@ -21,13 +18,6 @@
2118
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc2" />
2219
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.0.1" />
2320

24-
<!-- Analyzers -->
25-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
26-
27-
</ItemGroup>
28-
29-
<ItemGroup>
30-
<AdditionalFiles Include="..\..\stylecop.json" />
3121
</ItemGroup>
3222

3323
</Project>

0 commit comments

Comments
 (0)