Add initial ruleset

This commit is contained in:
Sören Schmincke 2026-03-22 12:38:04 +01:00
commit 8d036fddd3
5 changed files with 3404 additions and 2 deletions

3248
.NET/.editorconfig Normal file

File diff suppressed because it is too large Load diff

41
.NET/README.md Normal file
View file

@ -0,0 +1,41 @@
# .NET
These are the configuration files for .NET projects and solutions.
You can copy these files into the root of your .NET solution in order to activate the conventions.
### directory.build.props
The "directory.build.props" contains important project configuration, that need to be set for all .net projects in your solution. Some global compiler configuration will be set and the static analyzers get importet via NuGet.
### .editorconfig
The ".editorconfig" contains configuration for your code editor and the ruleset of the static analyzers. Copy this file into the root of you repository so that it is active for all files and folders.
#### Analyzers
| Name | Version | NuGet |
|--------------------------------------------|----------------|--------------------------------------------------------------------------------------------|
| Microsoft.CodeAnalysis.NetAnalyzers | 8.0.0 | [NuGet](https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers/8.0.0) |
| Microsoft.VisualStudio.Threading.Analyzers | 17.8.14 | [NuGet](https://www.nuget.org/packages/Microsoft.VisualStudio.Threading.Analyzers/17.8.14) |
| Roslynator.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.Analyzers/4.6.2) |
| Roslynator.CodeAnalysis.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers/4.6.2) |
| Roslynator.Formatting.Analyzers | 4.6.2 | [NuGet](https://www.nuget.org/packages/Roslynator.Formatting.Analyzers/4.6.2) |
| StyleCop.Analyzers | 1.2.0-beta.556 | [NuGet](https://www.nuget.org/packages/StyleCop.Analyzers/1.2.0-beta.556) |
#### Priority
The analyzers are handled with priority. That means, that a violation of a rule from a analyzer with a higher priority overrides a violation of a lower priority analyzer. In case of conflicting rules from different analyzers, the rule from analyzer with the lower gets changed or deactivated.
Priority of analyzers:
1. Microsoft.CodeAnalysis.NetAnalyzers
2. Microsoft.VisualStudio.Threading.Analyzers
3. StyleCop.Analyzers
4. Roslynator.Analyzers
5. Roslynator.CodeAnalysis.Analyzers
6. Roslynator.Formatting.Analyzers
### stylecop.json
The "stylecop.json" contains the configuration for "StyleCop.Analyzers", that cannot be set via the ".editorconfig". This file must be copied into the root of your repository as it gets imported from there into all .NET projects by the "directory.build.props"

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- General compiler configuration. -->
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>
<PropertyGroup>
<!--
Workaround for changing severity of rules with Location.None - e.g. CA1014
- see https://github.com/dotnet/roslyn/issues/37876#issuecomment-738042719
Needed until those types of rules can be disabled in a Global Analyzer Config
- when https://github.com/dotnet/roslyn/issues/48634 is implemented.
# CA1014: Mark assemblies with CLSCompliantAttribute
-->
<NoWarn>$(NoWarn);CA1014</NoWarn>
</PropertyGroup>
<ItemGroup>
<!--
These two options are necessary for IDE0130 to work:
- see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0130
# IDE0130: Namespace does not match folder structure
-->
<CompilerVisibleProperty Include="RootNamespace" />
<CompilerVisibleProperty Include="ProjectDir" />
</ItemGroup>
<!-- Include StyleCop Configuration from repository root. -->
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
<!-- Include static code analyzers. -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

35
.NET/stylecop.json Normal file
View file

@ -0,0 +1,35 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"fileNamingConvention": "metadata"
},
"indentation": {
"indentationSize": 4,
"tabSize": 4,
"useTabs": false
},
"layoutRules": {
"allowConsecutiveUsings": false,
"newlineAtEndOfFile": "require"
},
"maintainabilityRules": {
"topLevelTypes": [
"class",
"interface",
"struct",
"enum"
]
},
"namingRules": {
"includeInferredTupleElementNames": true
},
"orderingRules": {
"blankLinesBetweenUsingGroups": "omit",
"usingDirectivesPlacement": "outsideNamespace"
},
"readabilityRules": {
"allowBuiltInTypeAliases": false
}
}
}