Skip to content

Commit 5ff61b6

Browse files
author
Bart Koelman
authored
Coding guidelines (#8)
1 parent 02d2a77 commit 5ff61b6

File tree

144 files changed

+4255
-2680
lines changed

Some content is hidden

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

144 files changed

+4255
-2680
lines changed

.config/dotnet-tools.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"jetbrains.resharper.globaltools": {
6+
"version": "2020.3.3",
7+
"commands": [
8+
"jb"
9+
]
10+
},
11+
"regitlint": {
12+
"version": "2.1.3",
13+
"commands": [
14+
"regitlint"
15+
]
16+
}
17+
}
18+
}

.editorconfig

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Remove the line below if you want to inherit .editorconfig settings from higher directories
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
end_of_line = lf
10+
insert_final_newline = true
11+
12+
[*.{csproj,json}]
13+
indent_size = 2
14+
15+
[*.{cs}]
16+
#### .NET Coding Conventions ####
17+
18+
# Organize usings
19+
dotnet_sort_system_directives_first = true
20+
21+
# this. preferences
22+
dotnet_style_qualification_for_field = false:suggestion
23+
dotnet_style_qualification_for_property = false:suggestion
24+
dotnet_style_qualification_for_method = false:suggestion
25+
dotnet_style_qualification_for_event = false:suggestion
26+
27+
# Language keywords vs BCL types preferences
28+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
29+
dotnet_style_predefined_type_for_member_access = true:suggestion
30+
31+
# Modifier preferences
32+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
33+
csharp_style_pattern_local_over_anonymous_function = false:silent
34+
35+
# Expression-level preferences
36+
dotnet_style_operator_placement_when_wrapping = end_of_line
37+
dotnet_style_prefer_auto_properties = true:suggestion
38+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
39+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
40+
41+
# Parameter preferences
42+
dotnet_code_quality_unused_parameters = non_public:suggestion
43+
44+
# Expression-bodied members
45+
csharp_style_expression_bodied_accessors = true:suggestion
46+
csharp_style_expression_bodied_constructors = false:suggestion
47+
csharp_style_expression_bodied_indexers = true:suggestion
48+
csharp_style_expression_bodied_lambdas = true:suggestion
49+
csharp_style_expression_bodied_local_functions = false:suggestion
50+
csharp_style_expression_bodied_methods = false:suggestion
51+
csharp_style_expression_bodied_operators = false:suggestion
52+
csharp_style_expression_bodied_properties = true:suggestion
53+
54+
# Code-block preferences
55+
csharp_prefer_braces = true:suggestion
56+
57+
# Expression-level preferences
58+
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
59+
60+
# 'using' directive preferences
61+
csharp_using_directive_placement = outside_namespace:suggestion
62+
63+
64+
#### C# Formatting Rules ####
65+
66+
# Indentation preferences
67+
csharp_indent_case_contents_when_block = false
68+
69+
# Wrapping preferences
70+
csharp_preserve_single_line_statements = false
71+
72+
73+
#### Naming styles ####
74+
75+
dotnet_diagnostic.IDE1006.severity = warning
76+
77+
# Naming rules
78+
dotnet_naming_rule.private_const_fields_should_be_pascal_case.symbols = private_const_fields
79+
dotnet_naming_rule.private_const_fields_should_be_pascal_case.style = pascal_case
80+
dotnet_naming_rule.private_const_fields_should_be_pascal_case.severity = warning
81+
82+
dotnet_naming_rule.private_static_readonly_fields_should_be_pascal_case.symbols = private_static_readonly_fields
83+
dotnet_naming_rule.private_static_readonly_fields_should_be_pascal_case.style = pascal_case
84+
dotnet_naming_rule.private_static_readonly_fields_should_be_pascal_case.severity = warning
85+
86+
dotnet_naming_rule.private_static_or_readonly_fields_should_start_with_underscore.symbols = private_static_or_readonly_fields
87+
dotnet_naming_rule.private_static_or_readonly_fields_should_start_with_underscore.style = camel_case_prefix_with_underscore
88+
dotnet_naming_rule.private_static_or_readonly_fields_should_start_with_underscore.severity = warning
89+
90+
dotnet_naming_rule.locals_and_parameters_should_be_camel_case.symbols = locals_and_parameters
91+
dotnet_naming_rule.locals_and_parameters_should_be_camel_case.style = camel_case
92+
dotnet_naming_rule.locals_and_parameters_should_be_camel_case.severity = warning
93+
94+
dotnet_naming_rule.types_and_members_should_be_pascal_case.symbols = types_and_members
95+
dotnet_naming_rule.types_and_members_should_be_pascal_case.style = pascal_case
96+
dotnet_naming_rule.types_and_members_should_be_pascal_case.severity = warning
97+
98+
# Symbol specifications
99+
dotnet_naming_symbols.private_const_fields.applicable_kinds = field
100+
dotnet_naming_symbols.private_const_fields.applicable_accessibilities = private
101+
dotnet_naming_symbols.private_const_fields.required_modifiers = const
102+
103+
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
104+
dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private
105+
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = static,readonly
106+
107+
dotnet_naming_symbols.private_static_or_readonly_fields.applicable_kinds = field
108+
dotnet_naming_symbols.private_static_or_readonly_fields.applicable_accessibilities = private
109+
dotnet_naming_symbols.private_static_or_readonly_fields.required_modifiers = static readonly
110+
111+
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = local,parameter
112+
dotnet_naming_symbols.locals_and_parameters.applicable_accessibilities = *
113+
114+
dotnet_naming_symbols.types_and_members.applicable_kinds = *
115+
dotnet_naming_symbols.types_and_members.applicable_accessibilities = *
116+
117+
# Naming styles
118+
dotnet_naming_style.pascal_case.capitalization = pascal_case
119+
120+
dotnet_naming_style.camel_case_prefix_with_underscore.required_prefix = _
121+
dotnet_naming_style.camel_case_prefix_with_underscore.capitalization = camel_case
122+
123+
dotnet_naming_style.camel_case.capitalization = camel_case

.github/ISSUE_TEMPLATE.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _Describe your bug or feature request here._
44

55
#### STEPS TO REPRODUCE
66

7-
_Consider to include your code here, such as models, controllers, resource services, repositories, resource definitions etc._
7+
_Consider to include your code here, such as models, DbContext, controllers, resource services, repositories, resource definitions etc. Please also include the request URL with body (if applicable) and the full exception stack trace (set `options.IncludeExceptionStackTraceInErrors` to `true`) in case of errors._
88

99
1.
1010
2.
@@ -15,6 +15,7 @@ _Consider to include your code here, such as models, controllers, resource servi
1515
#### ACTUAL BEHAVIOR
1616

1717
#### VERSIONS USED
18-
- JsonApiDotNetCore.MongoDB version:
18+
- JsonApiDotNetCore.MongoDb version:
19+
- JsonApiDotNetCore version:
1920
- ASP.NET Core version:
2021
- MongoDB version:

.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Closes #{ISSUE_NUMBER}
44

55
#### QUALITY CHECKLIST
66
- [ ] Changes implemented in code
7+
- [ ] Complies with our [contributing guidelines](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/.github/CONTRIBUTING.md)
78
- [ ] Adapted tests
89
- [ ] Documentation updated

Build.ps1

+50-1
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,64 @@ function CheckLastExitCode {
1717
}
1818
}
1919

20+
function RunInspectCode {
21+
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
22+
dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
23+
CheckLastExitCode
24+
25+
[xml]$xml = Get-Content "$outputPath"
26+
if ($xml.report.Issues -and $xml.report.Issues.Project) {
27+
foreach ($project in $xml.report.Issues.Project) {
28+
if ($project.Issue.Count -gt 0) {
29+
$project.ForEach({
30+
Write-Output "`nProject $($project.Name)"
31+
$failed = $true
32+
33+
$_.Issue.ForEach({
34+
$issueType = $xml.report.IssueTypes.SelectSingleNode("IssueType[@Id='$($_.TypeId)']")
35+
$severity = $_.Severity ?? $issueType.Severity
36+
37+
Write-Output "[$severity] $($_.File):$($_.Line) $($_.Message)"
38+
})
39+
})
40+
}
41+
}
42+
43+
if ($failed) {
44+
throw "One or more projects failed code inspection.";
45+
}
46+
}
47+
}
48+
49+
function RunCleanupCode {
50+
# When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
51+
52+
if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) {
53+
Write-Output "Running code cleanup in cibuild for pull request"
54+
55+
$sourceCommitHash = $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT
56+
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
57+
58+
Write-Output "Source commit hash = $sourceCommitHash"
59+
Write-Output "Target commit hash = $targetCommitHash"
60+
61+
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --jb --profile --jb --profile='\"JADNC Full Cleanup\"' --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $sourceCommitHash -b $targetCommitHash --fail-on-diff --print-diff
62+
CheckLastExitCode
63+
}
64+
}
65+
2066
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
2167
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
2268

23-
dotnet restore
69+
dotnet tool restore
2470
CheckLastExitCode
2571

2672
dotnet build -c Release
2773
CheckLastExitCode
2874

75+
RunInspectCode
76+
RunCleanupCode
77+
2978
dotnet test -c Release --no-build
3079
CheckLastExitCode
3180

CSharpGuidelinesAnalyzer.config

+5
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

+31
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
<PropertyGroup>
33
<NetCoreAppVersion>netcoreapp3.1</NetCoreAppVersion>
44
<AspNetCoreVersion>3.1.*</AspNetCoreVersion>
5-
<JsonApiDotNetCoreVersion>4.0.2</JsonApiDotNetCoreVersion>
5+
<JsonApiDotNetCoreVersion>4.*</JsonApiDotNetCoreVersion>
66
<MongoDBDriverVersion>2.11.*</MongoDBDriverVersion>
7+
<CodeAnalysisRuleSet>$(SolutionDir)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
78
</PropertyGroup>
89

10+
<ItemGroup>
11+
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" PrivateAssets="All" />
12+
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.6.0" PrivateAssets="All" />
13+
<AdditionalFiles Include="$(SolutionDir)CSharpGuidelinesAnalyzer.config" Visible="False" />
14+
</ItemGroup>
15+
916
<PropertyGroup Condition="'$(Configuration)'=='Release'">
1017
<NoWarn>$(NoWarn);1591</NoWarn>
1118
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -16,7 +23,7 @@
1623
<PropertyGroup>
1724
<XUnitVersion>2.4.1</XUnitVersion>
1825
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
19-
<BogusVersion>31.0.3</BogusVersion>
20-
<MoqVersion>4.14.6</MoqVersion>
26+
<BogusVersion>33.0.2</BogusVersion>
27+
<MoqVersion>4.16.1</MoqVersion>
2128
</PropertyGroup>
2229
</Project>

JetBrainsInspectCodeTransform.xslt

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
3+
<xsl:key name="ISSUETYPES" match="/Report/Issues/Project/Issue" use="@TypeId"/>
4+
<xsl:output method="html" indent="yes"/>
5+
6+
<xsl:template match="/" name="TopLevelReport">
7+
<html>
8+
<head>
9+
<title>JetBrains Inspect Code Report</title>
10+
11+
<style>
12+
body { font-family: Arial; }
13+
th, td { text-align: left; }
14+
.severity { font-weight: bold; }
15+
</style>
16+
</head>
17+
<body>
18+
<h1>JetBrains InspectCode Report</h1>
19+
20+
<xsl:for-each select="/Report/IssueTypes/IssueType">
21+
<h2>
22+
<span class="severity"><xsl:value-of select="@Severity"/></span>: <xsl:value-of select="@Description"/>
23+
</h2>
24+
<table style="width:100%">
25+
<tr>
26+
<th>File</th>
27+
<th>Line Number</th>
28+
<th>Message</th>
29+
</tr>
30+
<xsl:for-each select="key('ISSUETYPES',@Id)">
31+
<tr>
32+
<td>
33+
<xsl:value-of select="@File"/>
34+
</td>
35+
<td>
36+
<xsl:value-of select="@Line"/>
37+
</td>
38+
<td>
39+
<xsl:value-of select="@Message"/>
40+
</td>
41+
</tr>
42+
</xsl:for-each>
43+
</table>
44+
<br />
45+
<hr />
46+
<br />
47+
</xsl:for-each>
48+
</body>
49+
</html>
50+
</xsl:template>
51+
</xsl:stylesheet>

0 commit comments

Comments
 (0)