Skip to content

Commit 31f21e8

Browse files
author
Bart Koelman
authored
Coding guidelines tweaks (#965)
1 parent 6e4ba03 commit 31f21e8

File tree

195 files changed

+2115
-1545
lines changed

Some content is hidden

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

195 files changed

+2115
-1545
lines changed

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function CheckLastExitCode {
1919

2020
function RunInspectCode {
2121
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
22-
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
22+
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
2323
CheckLastExitCode
2424

2525
[xml]$xml = Get-Content "$outputPath"

CSharpGuidelinesAnalyzer.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<cSharpGuidelinesAnalyzerSettings>
3+
<setting rule="AV1561" name="MaxParameterCount" value="6" />
4+
<setting rule="AV1561" name="MaxConstructorParameterCount" value="12" />
5+
</cSharpGuidelinesAnalyzerSettings>

CodingGuidelines.ruleset

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Coding Guidelines" Description=" " ToolsVersion="16.0">
3+
<Rules AnalyzerId="CSharpGuidelinesAnalyzer" RuleNamespace="CSharpGuidelinesAnalyzer">
4+
<Rule Id="AV1500" Action="None" />
5+
<Rule Id="AV1505" Action="Warning" />
6+
<Rule Id="AV1506" Action="Warning" />
7+
<Rule Id="AV1507" Action="Warning" />
8+
<Rule Id="AV1008" Action="Warning" />
9+
<Rule Id="AV1130" Action="Warning" />
10+
<Rule Id="AV1135" Action="Info" />
11+
<Rule Id="AV1536" Action="None" />
12+
<Rule Id="AV1537" Action="None" />
13+
<Rule Id="AV1551" Action="Info" />
14+
<Rule Id="AV1555" Action="Warning" />
15+
<Rule Id="AV1564" Action="Info" />
16+
<Rule Id="AV1568" Action="Warning" />
17+
<Rule Id="AV1706" Action="Warning" />
18+
<Rule Id="AV1710" Action="Info" />
19+
<Rule Id="AV1711" Action="Info" />
20+
<Rule Id="AV1738" Action="Warning" />
21+
<Rule Id="AV1739" Action="Warning" />
22+
<Rule Id="AV1745" Action="Warning" />
23+
<Rule Id="AV1755" Action="Warning" />
24+
<Rule Id="AV2210" Action="None" />
25+
<Rule Id="AV2220" Action="Warning" />
26+
<Rule Id="AV2230" Action="Info" />
27+
<Rule Id="AV2305" Action="None" />
28+
<Rule Id="AV2310" Action="Info" />
29+
<Rule Id="AV2318" Action="Info" />
30+
</Rules>
31+
</RuleSet>

Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
<AspNetCoreVersion>3.1.*</AspNetCoreVersion>
55
<EFCoreVersion>3.1.*</EFCoreVersion>
66
<NpgsqlPostgreSQLVersion>3.1.*</NpgsqlPostgreSQLVersion>
7+
<CodeAnalysisRuleSet>$(SolutionDir)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
78
</PropertyGroup>
89

10+
<ItemGroup>
11+
<AdditionalFiles Include="$(SolutionDir)CSharpGuidelinesAnalyzer.config">
12+
<Link>CSharpGuidelinesAnalyzer.config</Link>
13+
</AdditionalFiles>
14+
</ItemGroup>
15+
916
<PropertyGroup Condition="'$(Configuration)'=='Release'">
1017
<NoWarn>$(NoWarn);1591</NoWarn>
1118
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

JsonApiDotNetCore-WarningSeverities.DotSettings

Lines changed: 254 additions & 0 deletions
Large diffs are not rendered by default.

JsonApiDotNetCore.sln.DotSettings

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
7272
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SpecifyStringComparison/@EntryIndexedValue">WARNING</s:String>
7373
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringEndsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
7474
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringStartsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
75+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestDiscardDeclarationVarStyle/@EntryIndexedValue">WARNING</s:String>
7576
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TailRecursiveCall/@EntryIndexedValue">SUGGESTION</s:String>
7677
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TryCastAlwaysSucceeds/@EntryIndexedValue">WARNING</s:String>
7778
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnnecessaryWhitespace/@EntryIndexedValue">HINT</s:String>
@@ -554,7 +555,6 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
554555
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
555556
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
556557
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVarWhenEvident</s:String>
557-
<s:Boolean x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/PreferExplicitDiscardDeclaration/@EntryValue">True</s:Boolean>
558558
<s:Boolean x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/UseRoslynLogicForEvidentTypes/@EntryValue">False</s:Boolean>
559559
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue">False</s:Boolean>
560560
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/EnableEditorConfigSupport/@EntryValue">False</s:Boolean>
@@ -590,7 +590,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
590590
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/ReplacePattern/@EntryValue">JsonApiDotNetCore.ArgumentGuard.NotNull($argument$, nameof($argument$));&#xD;
591591
$left$ = $right$;</s:String>
592592
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/SearchPattern/@EntryValue">$left$ = $right$ ?? throw new ArgumentNullException(nameof($argument$));</s:String>
593-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/Severity/@EntryValue">SUGGESTION</s:String>
593+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/Severity/@EntryValue">WARNING</s:String>
594594
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/@KeyIndexDefined">True</s:Boolean>
595595
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Comment/@EntryValue">Replace classic argument null check with Guard clause</s:String>
596596
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/CustomPatternPlaceholder/=argument/@KeyIndexDefined">True</s:Boolean>
@@ -604,7 +604,7 @@ $left$ = $right$;</s:String>
604604
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/ReplaceComment/@EntryValue">Replace argument null check with Guard clause</s:String>
605605
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/ReplacePattern/@EntryValue">JsonApiDotNetCore.ArgumentGuard.NotNull($argument$, nameof($argument$));</s:String>
606606
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/SearchPattern/@EntryValue">if ($argument$ == null) throw new ArgumentNullException(nameof($argument$));</s:String>
607-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Severity/@EntryValue">SUGGESTION</s:String>
607+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Severity/@EntryValue">WARNING</s:String>
608608
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/@KeyIndexDefined">True</s:Boolean>
609609
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Comment/@EntryValue">Replace collection null/empty check with extension method</s:String>
610610
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/CustomPatternPlaceholder/=collection/@KeyIndexDefined">True</s:Boolean>
@@ -617,7 +617,7 @@ $left$ = $right$;</s:String>
617617
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/ReplaceComment/@EntryValue">Replace collection null/empty check with extension method</s:String>
618618
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/ReplacePattern/@EntryValue">$collection$.IsNullOrEmpty()</s:String>
619619
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/SearchPattern/@EntryValue">$collection$ == null || !$collection$.Any()</s:String>
620-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Severity/@EntryValue">SUGGESTION</s:String>
620+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Severity/@EntryValue">WARNING</s:String>
621621
<s:Boolean x:Key="/Default/UserDictionary/Words/=Assignee/@EntryIndexedValue">True</s:Boolean>
622622
<s:Boolean x:Key="/Default/UserDictionary/Words/=Injectables/@EntryIndexedValue">True</s:Boolean>
623623
<s:Boolean x:Key="/Default/UserDictionary/Words/=linebreaks/@EntryIndexedValue">True</s:Boolean>

benchmarks/BenchmarkResourcePublicNames.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma warning disable AV1008 // Class should not be static
2+
13
namespace Benchmarks
24
{
35
internal static class BenchmarkResourcePublicNames

benchmarks/DependencyFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Benchmarks
55
{
6-
internal static class DependencyFactory
6+
internal sealed class DependencyFactory
77
{
8-
public static IResourceGraph CreateResourceGraph(IJsonApiOptions options)
8+
public IResourceGraph CreateResourceGraph(IJsonApiOptions options)
99
{
1010
var builder = new ResourceGraphBuilder(options, NullLoggerFactory.Instance);
1111
builder.Add<BenchmarkResource>(BenchmarkResourcePublicNames.Type);

benchmarks/Query/QueryParserBenchmarks.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Benchmarks.Query
2020
[MemoryDiagnoser]
2121
public class QueryParserBenchmarks
2222
{
23+
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
2324
private readonly FakeRequestQueryStringAccessor _queryStringAccessor = new FakeRequestQueryStringAccessor();
2425
private readonly QueryStringReader _queryStringReaderForSort;
2526
private readonly QueryStringReader _queryStringReaderForAll;
@@ -31,7 +32,7 @@ public QueryParserBenchmarks()
3132
EnableLegacyFilterNotation = true
3233
};
3334

34-
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
35+
IResourceGraph resourceGraph = _dependencyFactory.CreateResourceGraph(options);
3536

3637
var request = new JsonApiRequest
3738
{
@@ -107,7 +108,7 @@ public void ComplexQuery()
107108

108109
private void Run(int iterations, Action action)
109110
{
110-
for (int i = 0; i < iterations; i++)
111+
for (int index = 0; index < iterations; index++)
111112
{
112113
action();
113114
}

benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ public class JsonApiDeserializerBenchmarks
2929
}
3030
});
3131

32+
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
3233
private readonly IJsonApiDeserializer _jsonApiDeserializer;
3334

3435
public JsonApiDeserializerBenchmarks()
3536
{
3637
var options = new JsonApiOptions();
37-
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
38+
IResourceGraph resourceGraph = _dependencyFactory.CreateResourceGraph(options);
3839
var targetedFields = new TargetedFields();
3940
var request = new JsonApiRequest();
4041
var resourceFactory = new ResourceFactory(new ServiceContainer());

0 commit comments

Comments
 (0)