Skip to content

Commit 08e0938

Browse files
committed
adding code analysis tools, fixing reported issues
1 parent 39e8aa3 commit 08e0938

Some content is hidden

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

46 files changed

+4336
-4063
lines changed

.editorconfig

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Suppress: EC112
2+
# (The property name is unknown and might be the result of a typo)
3+
#
4+
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs and http://editorconfig.org/
5+
#
6+
###############################
7+
# Core EditorConfig Options #
8+
###############################
9+
# All files
10+
[*]
11+
charset = utf-8
12+
end_of_line = lf
13+
indent_size = 2
14+
indent_style = space
15+
insert_final_newline = true
16+
trim_trailing_whitespace = true
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
insert_final_newline = false
20+
# Code files
21+
[*.{cs,csx,vb,vbx}]
22+
indent_size = 4
23+
insert_final_newline = true
24+
charset = utf-8
25+
###############################
26+
# .NET Coding Conventions #
27+
###############################
28+
[*.{cs,vb}]
29+
# Organize usings
30+
dotnet_sort_system_directives_first = true
31+
# this. preferences
32+
dotnet_style_qualification_for_field = false:silent
33+
dotnet_style_qualification_for_property = false:silent
34+
dotnet_style_qualification_for_method = false:silent
35+
dotnet_style_qualification_for_event = false:silent
36+
# Language keywords vs BCL types preferences
37+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
38+
dotnet_style_predefined_type_for_member_access = true:silent
39+
# Parentheses preferences
40+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
41+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
42+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
43+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
44+
# Modifier preferences
45+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
46+
dotnet_style_readonly_field = true:suggestion
47+
# Expression-level preferences
48+
dotnet_style_object_initializer = true:suggestion
49+
dotnet_style_collection_initializer = true:suggestion
50+
dotnet_style_explicit_tuple_names = true:suggestion
51+
dotnet_style_null_propagation = true:suggestion
52+
dotnet_style_coalesce_expression = true:suggestion
53+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
54+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
55+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
56+
dotnet_style_prefer_auto_properties = true:silent
57+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
58+
dotnet_style_prefer_conditional_expression_over_return = true:silent
59+
###############################
60+
# Naming Conventions #
61+
###############################
62+
# Style Definitions
63+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
64+
# Use PascalCase for constant fields
65+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
66+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
67+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
68+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
69+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
70+
dotnet_naming_symbols.constant_fields.required_modifiers = const
71+
###############################
72+
# C# Coding Conventions #
73+
###############################
74+
[*.cs]
75+
csharp_indent_case_contents_when_block = true
76+
csharp_using_directive_placement = outside_namespace:silent
77+
# var preferences
78+
csharp_style_var_for_built_in_types = true:silent
79+
csharp_style_var_when_type_is_apparent = true:silent
80+
csharp_style_var_elsewhere = true:silent
81+
# Expression-bodied members
82+
csharp_style_expression_bodied_methods = false:silent
83+
csharp_style_expression_bodied_constructors = false:silent
84+
csharp_style_expression_bodied_operators = false:silent
85+
csharp_style_expression_bodied_properties = true:silent
86+
csharp_style_expression_bodied_indexers = true:silent
87+
csharp_style_expression_bodied_accessors = true:silent
88+
# Pattern matching preferences
89+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
90+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
91+
# Null-checking preferences
92+
csharp_style_throw_expression = true:suggestion
93+
csharp_style_conditional_delegate_call = true:suggestion
94+
# Modifier preferences
95+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
96+
# Expression-level preferences
97+
csharp_prefer_braces = true:silent
98+
csharp_style_deconstructed_variable_declaration = true:suggestion
99+
csharp_prefer_simple_default_expression = true:suggestion
100+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
101+
csharp_style_inlined_variable_declaration = true:suggestion
102+
###############################
103+
# C# Formatting Rules #
104+
###############################
105+
# New line preferences
106+
csharp_new_line_before_open_brace = all
107+
csharp_new_line_before_else = true
108+
csharp_new_line_before_catch = true
109+
csharp_new_line_before_finally = true
110+
csharp_new_line_before_members_in_object_initializers = true
111+
csharp_new_line_before_members_in_anonymous_types = true
112+
csharp_new_line_between_query_expression_clauses = true
113+
# Indentation preferences
114+
csharp_indent_case_contents = true
115+
csharp_indent_switch_labels = true
116+
csharp_indent_labels = flush_left
117+
# Space preferences
118+
csharp_space_after_cast = false
119+
csharp_space_after_keywords_in_control_flow_statements = true
120+
csharp_space_between_method_call_parameter_list_parentheses = false
121+
csharp_space_between_method_declaration_parameter_list_parentheses = false
122+
csharp_space_between_parentheses = false
123+
csharp_space_before_colon_in_inheritance_clause = true
124+
csharp_space_after_colon_in_inheritance_clause = true
125+
csharp_space_around_binary_operators = before_and_after
126+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
127+
csharp_space_between_method_call_name_and_opening_parenthesis = false
128+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
129+
# Wrapping preferences
130+
csharp_preserve_single_line_statements = true
131+
csharp_preserve_single_line_blocks = true
132+
###############################
133+
# C# diagnostics overrides #
134+
###############################
135+
# CA1303: Do not pass literals as localized parameters
136+
dotnet_diagnostic.CA1303.severity = none
137+
# CA1724: Type names should not match namespaces
138+
dotnet_diagnostic.CA1724.severity = none
139+
# CA2007: Consider calling ConfigureAwait on the awaited task
140+
dotnet_diagnostic.CA2007.severity = suggestion
141+
# CC0022: Should dispose object
142+
# as of Apr 2020 CodeCracker doesn't support C# 8.0, so inline using statemates are not "seen" by it
143+
dotnet_diagnostic.CC0022.severity = none
144+
# SA1101: Prefix local calls with this
145+
dotnet_diagnostic.SA1101.severity = none
146+
# S3241: Methods should not return values that are never used
147+
dotnet_diagnostic.S3241.severity = none
148+
# SA1616: Element return value documentation should have text
149+
dotnet_diagnostic.SA1616.severity = suggestion
150+
# SA1200: Using directives should be placed correctly
151+
dotnet_diagnostic.SA1200.severity = none
152+
# SA1124: Do not use regions
153+
dotnet_diagnostic.SA1124.severity = suggestion
154+
155+
# SA1615: Element return value should be documented
156+
dotnet_diagnostic.SA1615.severity = suggestion
157+
158+
# SA1633: File should have header
159+
dotnet_diagnostic.SA1633.severity = none

CodeAnalyzers.targets

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<Project>
2+
3+
<!--
4+
IDEALLY THIS IS ALWAYS ENABLED, BUT THAT TENDS TO HURT DEVELOPER PRODUCTIVITY
5+
=============================================================================
6+
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
</PropertyGroup>
9+
-->
10+
11+
<PropertyGroup>
12+
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
13+
</PropertyGroup>
14+
15+
<!-- Documentation-related settings -->
16+
<PropertyGroup>
17+
<!--
18+
Make sure any documentation comments which are included in code get checked for syntax during the build, but do
19+
not report warnings for missing comments.
20+
21+
CS1573: Parameter 'parameter' has no matching param tag in the XML comment for 'parameter' (but other parameters do)
22+
CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member'
23+
-->
24+
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
25+
</PropertyGroup>
26+
27+
<!-- Analyzers-related configuration -->
28+
<PropertyGroup>
29+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
30+
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
31+
<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
32+
<CodeAnalysisRuleSet Condition="Exists('$(SolutionDir)\stylecop.ruleset')">$(SolutionDir)\stylecop.ruleset</CodeAnalysisRuleSet>
33+
</PropertyGroup>
34+
35+
<ItemGroup>
36+
<!-- StyleCop Analyzer-related configuration -->
37+
<AdditionalFiles Include="$(SolutionDir)\stylecop.json" Condition="Exists('$(SolutionDir)\stylecop.json')" />
38+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.*">
39+
<PrivateAssets>all</PrivateAssets>
40+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
41+
</PackageReference>
42+
<None Remove="**\*.Cache" />
43+
44+
<!-- FxCop Analyzer-related configuration -->
45+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.*">
46+
<PrivateAssets>all</PrivateAssets>
47+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
48+
</PackageReference>
49+
50+
<!-- CodeCracker Analyzer-related configuration -->
51+
<PackageReference Include="codecracker.CSharp" Version="1.1.*">
52+
<PrivateAssets>all</PrivateAssets>
53+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
54+
</PackageReference>
55+
56+
<!-- Sonar Analyzer-related configuration -->
57+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.*">
58+
<PrivateAssets>all</PrivateAssets>
59+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
60+
</PackageReference>
61+
</ItemGroup>
62+
63+
<!--
64+
Disable analyzers when building a project inside Visual Studio.
65+
Note that analyzer behavior for IntelliSense purposes is not altered by this.
66+
-->
67+
<Target Name="DisableAnalyzersForVisualStudioBuild" BeforeTargets="CoreCompile"
68+
Condition="'$(BuildingInsideVisualStudio)' == 'true' And '$(BuildingProject)' == 'true' And '$(Configuration)' == 'Debug'">
69+
<ItemGroup>
70+
<Analyzer Remove="@(Analyzer)"/>
71+
</ItemGroup>
72+
</Target>
73+
74+
</Project>

Directory.Build.props

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<NetStandardVersion>netstandard2.1</NetStandardVersion>
5+
<NetCoreAppVersion>net5.0</NetCoreAppVersion>
6+
<NetCorePackageVersion>5.0.0</NetCorePackageVersion>
7+
<EFCorePackageVersion>5.0.0</EFCorePackageVersion>
8+
<LangVersion>8.0</LangVersion>
9+
<Configurations>Debug;Release</Configurations>
10+
<ResolveNuGetPackages>true</ResolveNuGetPackages>
11+
</PropertyGroup>
12+
13+
<!-- NuGet packaging-related stuff -->
14+
<PropertyGroup>
15+
<IsPackable>false</IsPackable>
16+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
17+
<Company>CODECAVE LLC</Company>
18+
<Authors>CODECAVE LLC</Authors>
19+
<Copyright>Copyright © $([System.DateTime]::Now.ToString(yyyy)) CODECAVE LLC - All Rights Reserved</Copyright>
20+
<NeutralLanguage>en</NeutralLanguage>
21+
</PropertyGroup>
22+
23+
<!-- Output-related settings -->
24+
<PropertyGroup>
25+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
26+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFrameworks)' == ''">false</AppendTargetFrameworkToOutputPath>
27+
<AppendRuntimeIdentifierToOutputPath>true</AppendRuntimeIdentifierToOutputPath>
28+
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
29+
<OutputPath>$(SolutionDir)\bin\$(Configuration)\</OutputPath>
30+
</PropertyGroup>
31+
32+
<!-- Some tweaks for Unit Test projects, e.g. xUnit -->
33+
<PropertyGroup>
34+
<IsTestProject Condition="'$(IsTestProject)' == ''">$(MSBuildProjectName.Contains('.Test'))</IsTestProject>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
37+
<!-- Changing output path for xUnit tests, so it won't break actual compiled code by shipping its Newtonsoft.Json v9.0.0 -->
38+
<OutputPath>bin\$(Configuration)\</OutputPath>
39+
<!-- Mark the project as being a test project -->
40+
<SonarQubeTestProject>true</SonarQubeTestProject>
41+
</PropertyGroup>
42+
43+
<!-- Coverage-related settings -->
44+
<PropertyGroup>
45+
<CollectCoverage>true</CollectCoverage>
46+
<CoverletOutputFormat>opencover</CoverletOutputFormat>
47+
<CoverletOutput>$(SolutionDir)/tests/coverage/</CoverletOutput>
48+
</PropertyGroup>
49+
50+
<!-- Docker-related settings -->
51+
<PropertyGroup Condition="Exists('$(SolutionDir)\docker-compose.dcproj') And '$(IsTestProject)' != 'true'">
52+
<Configurations>$(Configurations);DebugDocker</Configurations>
53+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
54+
<DockerfileContext>..\..</DockerfileContext>
55+
<DockerComposeProjectPath>$(DockerfileContext)\docker-compose.dcproj</DockerComposeProjectPath>
56+
</PropertyGroup>
57+
<PropertyGroup Condition="$(Configuration.Contains('Docker'))">
58+
<OutputPath>bin\Debug\</OutputPath>
59+
</PropertyGroup>
60+
61+
<!-- Debug-related settings -->
62+
<PropertyGroup>
63+
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
64+
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
65+
</PropertyGroup>
66+
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
67+
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
68+
<DebugSymbols>true</DebugSymbols>
69+
<DebugType>portable</DebugType>
70+
</PropertyGroup>
71+
<PropertyGroup Condition="'$(OS)' == 'Windows_NT' And $(TargetFramework.Contains('net4'))">
72+
<DebugType>full</DebugType>
73+
</PropertyGroup>
74+
75+
<Import Project="$(SolutionDir)\CodeAnalyzers.targets" Condition="Exists('$(SolutionDir)\CodeAnalyzers.targets')" />
76+
77+
</Project>

Directory.Build.targets

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
3+
<Target Name="CleanNuGetFiles" AfterTargets="Clean">
4+
<ItemGroup>
5+
<NuGetFilesBin Include="$(OutputPath)\..\*.nupkg" />
6+
</ItemGroup>
7+
<Message Text="Deleting NuGet files from $(OutputPath)\..\*.nupkg" Importance="high" />
8+
<Delete Files="@(NuGetFilesBin)" />
9+
<Delete Files="@(NuGetFilesProject)" />
10+
</Target>
11+
12+
</Project>

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016 CodeCave, PUE
1+
Copyright (c) 2016 CODECAVE
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Revit.Toolkit.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeCave.Revit.Toolkit", "s
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7386BB7C-2319-4E84-B2CA-4E737F27B44D}"
99
ProjectSection(SolutionItems) = preProject
10+
.editorconfig = .editorconfig
1011
.gitattributes = .gitattributes
1112
.gitignore = .gitignore
1213
appveyor.yml = appveyor.yml
14+
CodeAnalyzers.targets = CodeAnalyzers.targets
15+
Directory.Build.props = Directory.Build.props
16+
Directory.Build.targets = Directory.Build.targets
1317
global.json = global.json
1418
LICENSE.txt = LICENSE.txt
1519
README.md = README.md
20+
stylecop.json = stylecop.json
21+
stylecop.ruleset = stylecop.ruleset
1622
EndProjectSection
1723
EndProject
1824
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeCave.Revit.Toolkit.Tests", "tests\CodeCave.Revit.Toolkit.Tests.csproj", "{261A32CF-23EE-4873-9EF0-3F899A879FD8}"

0 commit comments

Comments
 (0)