Skip to content

Commit

Permalink
Add banned API analyzers
Browse files Browse the repository at this point in the history
Add  to detect usage of problematic code patterns.
  • Loading branch information
martincostello committed Sep 28, 2023
1 parent cf84069 commit c4eaa68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsVersion)" />
Expand Down
2 changes: 2 additions & 0 deletions eng/Analyzers.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project>
<ItemGroup Label="Analyzers">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)analyzers\BannedSymbols.txt" Condition=" '$(IsTestProject)' != 'true' " Visible="false" />
<AdditionalFiles Include="$(MsBuildThisFileDirectory)analyzers\Stylecop.json" Visible="false" />
<EditorConfigFiles Include="$(MsBuildThisFileDirectory)analyzers\Stylecop.globalconfig" />
<EditorConfigFiles Include="$(MsBuildThisFileDirectory)analyzers\$(ProjectType).globalconfig" />
Expand Down
5 changes: 5 additions & 0 deletions eng/analyzers/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
P:System.DateTime.Now; Use TimeProvider.GetLocalNow().DateTime instead.
P:System.DateTime.Today; Use TimeProvider.GetLocalNow().DateTime.Date instead.
P:System.DateTimeOffset.Now; Use TimeProvider.GetLocalNow() instead.
P:System.DateTimeOffset.Today; Use TimeProvider.GetLocalNow().Date instead.
M:System.DateTimeOffset.op_Implicit(System.DateTime); Do not implicitly cast DateTime to DateTimeOffset.

0 comments on commit c4eaa68

Please sign in to comment.