Skip to content

Commit

Permalink
Include code analyzers as part of build (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar authored Sep 1, 2024
1 parent 6a08e0a commit 1893d71
Show file tree
Hide file tree
Showing 35 changed files with 459 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void SetLastRun(ICronJob cronJob, DateTime lastRun)

private CronJobDataRow GetOrCreateCronJobDataRow(ICronJob cronJob)
{
CronJobDataRow cronJobDataRow = _cronJobSettings.Select(cj => cj.JobId.Equals(cronJob.JobId) && cj.Name.Equals(cronJob.Name)).FirstOrDefault();
CronJobDataRow cronJobDataRow = _cronJobSettings.Select().FirstOrDefault(cj => cj.JobId.Equals(cronJob.JobId) && cj.Name.Equals(cronJob.Name));

if (cronJobDataRow == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void BeforeUpdate(ProductDataRow newRecord, ProductDataRow oldRecord)
// from interface but unused in this context
}

private void ValidateData(ProductDataRow row)
private static void ValidateData(ProductDataRow row)
{
if (String.IsNullOrEmpty(row.Name))
throw new InvalidDataRowException(nameof(ProductDataRow), nameof(row.Name), "Can not be null or empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void BeforeUpdate(ProductGroupDataRow newRecord, ProductGroupDataRow oldR
// from interface but unused in this context
}

private void ValidateData(ProductGroupDataRow row)
private static void ValidateData(ProductGroupDataRow row)
{
if (String.IsNullOrEmpty(row.Description))
throw new InvalidDataRowException(nameof(ProductGroupDataRow), nameof(row.Description), "Can not be null or empty");
Expand Down
1 change: 1 addition & 0 deletions Demo/DemoApiPlugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>", Scope = "member", Target = "~M:DemoApiPlugin.Controllers.DemoApiController.TestApi(System.String,System.String,System.String)~Microsoft.AspNetCore.Mvc.IActionResult")]
[assembly: SuppressMessage("Major Code Smell", "S6962:You should pool HTTP connections with HttpClientFactory", Justification = "Used as part of a demo app in this context", Scope = "member", Target = "~M:DemoApiPlugin.Controllers.DemoApiController.TestApi(System.String,System.String,System.String)~Microsoft.AspNetCore.Mvc.IActionResult")]
[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "Part of original c# generated code", Scope = "member", Target = "~M:DemoApiPlugin.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder)")]
9 changes: 9 additions & 0 deletions Demo/DemoRazorWebsitePlugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "Part of original c# generated code", Scope = "member", Target = "~M:DemoWebsitePlugin.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "Part of original c# generated code", Scope = "member", Target = "~M:DemoWebsitePlugin.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder)")]
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions Demo/NetCorePluginDemoWebsite/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
[assembly: SuppressMessage("Major Code Smell", "S4144:Methods should not have identical implementations", Justification = "Required for demo only", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockProductProvider.ProductDelete(System.Int32@,System.String@)~System.Boolean")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Startup class, good as is", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Startup class, good as is", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder)")]
[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "Part of original c# generated code", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder)")]
[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "Part of original c# generated code", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
17 changes: 12 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
<Copyright>Copyright (c) 2018 - 2024. Simon Carter. All rights reserved.</Copyright>
<Description>Plugin Manager</Description>
</PropertyGroup>

<!-- Warning disabled whilst net 6 supported -->
<PropertyGroup Condition="'$(NET_8_0)'=='1'">
<NoWarn>$(NoWarn);CA1510;CA1512;CA1513</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
Expand Down Expand Up @@ -111,10 +123,5 @@
<DebugType>$(DebugType)</DebugType>
<DebugSymbols>%(DebugSymbols)</DebugSymbols>
</PropertyGroup>

<!-- Warning disabled whilst net 6 supported -->
<PropertyGroup Condition="'$(NET_6_0)'=='1'">
<NoWarn>$(NoWarn);CA1510;CA1512;CA1513</NoWarn>
</PropertyGroup>

</Project>
Loading

0 comments on commit 1893d71

Please sign in to comment.