Skip to content

Commit 0469e16

Browse files
[Internal] Code Quality: Adds Exception Analyzers (#5082)
## Description In order to detect and prevent certain usages of exceptions within the codebase, analyzers have been added to show messages related to potentially incorrect usage. Added `Microsoft.Codex.Analyzers` v1.0.5 nuget package Added .globalconfig file as a baseline configuration ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) ## Closing issues Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
1 parent 1101959 commit 0469e16

6 files changed

Lines changed: 34 additions & 7 deletions

File tree

.globalconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# .NET code analysis rule set
2+
is_global = true
3+
4+
# Current
5+
dotnet_diagnostic.CDX1000.severity = suggestion # DontConvertExceptionToObject
6+
dotnet_diagnostic.CDX1001.severity = suggestion # DontUseExceptionInInterpolation
7+
dotnet_diagnostic.CDX1002.severity = suggestion # DontUseExceptionStackTrace
8+
dotnet_diagnostic.CDX1003.severity = suggestion # DontUseExceptionToString
9+
10+
# 📊 Experimental Analyzer Features
11+
dotnet_diagnostic.CDX1004.severity = suggestion # Experimental - DontCreateNestedExceptions
12+
dotnet_diagnostic.CDX1005.severity = suggestion # Experimental - DontThrowExceptions
13+
dotnet_diagnostic.CDX1006.severity = suggestion # Experimental - DontCatchGenericExceptions

Microsoft.Azure.Cosmos.Encryption.Custom/src/Microsoft.Azure.Cosmos.Encryption.Custom.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@
5959
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" NoWarn="NU1903" PrivateAssets="All" />
6060
</ItemGroup>
6161

62+
<!-- Code Analyzers -->
6263
<ItemGroup>
63-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
64+
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
6465
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
66+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
6567
</ItemGroup>
6668

6769
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

Microsoft.Azure.Cosmos.Encryption/src/Microsoft.Azure.Cosmos.Encryption.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" NoWarn="NU1903" PrivateAssets="All" />
5555
</ItemGroup>
5656

57+
<!-- Code Analyzers -->
5758
<ItemGroup>
58-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
59+
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
5960
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
61+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
6062
</ItemGroup>
6163

6264
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

Microsoft.Azure.Cosmos.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EndProject
2222
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{804C595B-D0DA-48F1-A40D-97BB014736CB}"
2323
ProjectSection(SolutionItems) = preProject
2424
.editorconfig = .editorconfig
25+
.globalconfig = .globalconfig
2526
EndProjectSection
2627
EndProject
2728
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Encryption.Custom", "Encryption.Custom", "{51F858D8-707E-4F21-BCC6-4D6123832E4F}"

Microsoft.Azure.Cosmos/FaultInjection/src/FaultInjection.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@
6666
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
6767
<PackageReference Include="System.Text.Json" Version="8.0.5" />
6868
</ItemGroup>
69-
70-
<PropertyGroup Condition=" '$(ProjectRef)' != 'True' ">
69+
70+
<!-- Code Analyzers -->
71+
<ItemGroup>
72+
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
73+
</ItemGroup>
74+
75+
<PropertyGroup Condition=" '$(ProjectRef)' != 'True' ">
7176
<SignAssembly>true</SignAssembly>
7277
<DelaySign>true</DelaySign>
7378
<AssemblyOriginatorKeyFile>..\..\..\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>

Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@
133133
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
134134
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
135135
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
136-
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
137136
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" NoWarn="NU1903" PrivateAssets="All" />
138137
<PackageReference Include="System.Net.Http" Version="4.3.4" />
139138
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
140-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
141139

142140
<!--Direct Dependencies-->
143141
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
@@ -150,7 +148,13 @@
150148
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
151149
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
152150
</ItemGroup>
153-
151+
152+
<!-- Code Analyzers -->
153+
<ItemGroup>
154+
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
155+
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
156+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
157+
</ItemGroup>
154158

155159
<ItemGroup Condition=" '$(ProjectRef)' != 'True' ">
156160
<None Include="$(OutputPath)\Cosmos.CRTCompat.dll" Pack="true" IsAssembly="true" PackagePath="runtimes\win-x64\native" />

0 commit comments

Comments
 (0)