Skip to content

Commit

Permalink
chore: symbol naming enforcement across all csprojects (#3053)
Browse files Browse the repository at this point in the history
* chore: symbol naming enforcement across all csprojects

* Commented editorconfig

* fix: Minor updates to.props file

Propagate warningAsErrors from inputs
Enforce codestyle on build always

* fix(dui): Do not warn about DUI2 in CI

* feat: Bump min sdk to >8.0

* bump: Use 8.0 on ci too

* Revert "bump: Use 8.0 on ci too"

This reverts commit 55e8784.

* Revert "feat: Bump min sdk to >8.0"

This reverts commit 9ae9da5.

---------

Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
JR-Morgan and AlanRynne authored Nov 22, 2023
1 parent 09e877b commit 0e04abe
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 90 deletions.
176 changes: 98 additions & 78 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,6 @@ dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:n
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none

# ReSharper properties
resharper_align_linq_query = false
resharper_align_multiline_calls_chain = true
resharper_align_multiline_extends_list = true
resharper_align_multiline_for_stmt = true
resharper_align_multiline_parameter = true
resharper_align_multiple_declaration = true
resharper_align_multline_type_parameter_constrains = true
resharper_align_multline_type_parameter_list = true
resharper_braces_for_dowhile = not_required
resharper_braces_for_fixed = not_required
resharper_braces_for_lock = not_required
resharper_braces_for_using = not_required
resharper_csharp_align_multiline_calls_chain = false
resharper_csharp_align_multiline_extends_list = false
resharper_csharp_align_multiline_parameter = false
resharper_csharp_int_align_comments = false
resharper_csharp_outdent_commas = true
resharper_csharp_outdent_dots = false
resharper_csharp_wrap_after_declaration_lpar = true
resharper_csharp_wrap_after_invocation_lpar = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_declaration_rpar = true
resharper_csharp_wrap_before_invocation_rpar = false
resharper_csharp_wrap_extends_list_style = chop_if_long
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_force_attribute_style = join
resharper_indent_nested_fixed_stmt = false
resharper_indent_nested_foreach_stmt = true
resharper_indent_nested_for_stmt = true
resharper_indent_nested_lock_stmt = false
resharper_indent_nested_usings_stmt = false
resharper_indent_nested_while_stmt = true
resharper_int_align = false
resharper_int_align_nested_ternary = false
resharper_int_align_switch_expressions = false
resharper_keep_existing_declaration_block_arrangement = true
resharper_keep_existing_declaration_parens_arrangement = false
resharper_keep_existing_embedded_block_arrangement = true
resharper_keep_existing_enum_arrangement = true
resharper_keep_existing_expr_member_arrangement = true
resharper_keep_existing_initializer_arrangement = false
resharper_local_function_body = expression_body
resharper_max_attribute_length_for_same_line = 20
resharper_max_formal_parameters_on_line = 5
resharper_max_initializer_elements_on_line = 0
resharper_max_invocation_arguments_on_line = 5
resharper_outdent_binary_ops = true
resharper_outdent_dots = false
resharper_place_constructor_initializer_on_same_line = false
resharper_place_simple_initializer_on_single_line = true
resharper_prefer_explicit_discard_declaration = false
resharper_wrap_after_declaration_lpar = false
resharper_wrap_before_invocation_rpar = false
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_chained_binary_patterns = chop_if_long
resharper_wrap_chained_method_calls = chop_if_long
resharper_xmldoc_indent_text = ZeroIndent

# Standard properties
insert_final_newline = true
Expand Down Expand Up @@ -107,7 +49,6 @@ dotnet_style_qualification_for_event = false:suggestion
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent
Expand Down Expand Up @@ -155,6 +96,7 @@ csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_namespace_declarations = file_scoped

# Newline settings
csharp_new_line_before_open_brace = all
Expand All @@ -181,36 +123,114 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true



# SYMBOL NAMING RULES
# Copied from https://github.com/dotnet/roslyn/blob/main/.editorconfig
# Adapted rules:
# - Constants are ALL_UPPER
# - Non-private fields are PascalCase

# Non-private fields are PascalCase
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style

dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected

dotnet_naming_style.non_private_readonly_field_style.capitalization = pascal_case

# Constants are ALL_UPPER
dotnet_naming_rule.constants_should_be_pascal_case.severity = warning
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style

dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const

dotnet_naming_style.constant_style.capitalization = all_upper

# Private static fields are camelCase and start with s_
dotnet_naming_rule.static_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style

dotnet_naming_symbols.static_fields.applicable_accessibilities = private
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix = s_


# Instance fields are camelCase and start with _
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style

dotnet_naming_symbols.instance_fields.applicable_kinds = field

dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _

# Locals and parameters are camelCase
dotnet_naming_rule.locals_should_be_camel_case.severity = warning
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style

dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local

dotnet_naming_style.camel_case_style.capitalization = camel_case

# Local functions are PascalCase
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = warning
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style

dotnet_naming_symbols.local_functions.applicable_kinds = local_function

dotnet_naming_style.local_function_style.capitalization = pascal_case

# By default, name items with PascalCase
dotnet_naming_rule.members_should_be_pascal_case.severity = warning
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.all_members.applicable_kinds = *

dotnet_naming_style.pascal_case_style.capitalization = pascal_case


# Analyzer settings
dotnet_diagnostic.ide0055.severity = none
dotnet_analyzer_diagnostic.category-Style.severity = warning # All rules will use this severity unless overriden
dotnet_diagnostic.ide0055.severity = none # Formatting rule: Incompatible with CSharpier
dotnet_diagnostic.ide0007.severity = none # Use var instead of explicit type: Preference
dotnet_diagnostic.ide0009.severity = none # Add this or Me qualification: Preference
dotnet_diagnostic.ide0046.severity = suggestion # Use conditional expression for return: Preference
dotnet_diagnostic.ide0078.severity = suggestion # Use pattern matching: Subjective
dotnet_diagnostic.ide0260.severity = suggestion # Use pattern matching: Subjective


# Maintainability rules
dotnet_diagnostic.ca1501.severity = warning
dotnet_diagnostic.ca1502.severity = warning
dotnet_diagnostic.ca1505.severity = warning
dotnet_diagnostic.ca1506.severity = warning
dotnet_diagnostic.ca1507.severity = warning
dotnet_diagnostic.ca1508.severity = warning
dotnet_diagnostic.ca1509.severity = warning
dotnet_diagnostic.ca1501.severity = warning # Avoid excessive inheritance
dotnet_diagnostic.ca1502.severity = warning # Avoid excessive complexity
dotnet_diagnostic.ca1505.severity = warning # Avoid unmaintainable code
dotnet_diagnostic.ca1506.severity = warning # Avoid excessive class coupling
dotnet_diagnostic.ca1507.severity = warning # Use nameof in place of string
dotnet_diagnostic.ca1508.severity = warning # Avoid dead conditional code
dotnet_diagnostic.ca1509.severity = warning # Invalid entry in code metrics configuration file

dotnet_diagnostic.ca1002.severity = suggestion
dotnet_diagnostic.ca1002.severity = suggestion # Do not expose generic lists

# Misc
dotnet_diagnostic.ca1051.severity = none # Do not declare visible instance fields
dotnet_diagnostic.ca1056.severity = suggestion
dotnet_diagnostic.ca1051.severity = warning # Do not declare visible instance fields
dotnet_diagnostic.ca1056.severity = suggestion # URI properties should not be strings
dotnet_diagnostic.ca1062.severity = none # Public method must check all parameters for null
dotnet_diagnostic.ca1707.severity = none # Remove underscores in names
dotnet_diagnostic.ca1822.severity = suggestion # Mark member as static

dotnet_diagnostic.ca2211.severity = suggestion # Non constant fields should not be visible
dotnet_diagnostic.ca2227.severity = suggestion # Collection props should be read-only


dotnet_analyzer_diagnostic.category-Globalization.severity = none
dotnet_analyzer_diagnostic.category-Security.severity = none
dotnet_analyzer_diagnostic.category-Interoperability.severity = none
dotnet_analyzer_diagnostic.category-SingleFile.severity = none

[*.{appxmanifest,asax,ascx,aspx,axaml,build,c,c++,cc,cginc,compute,cp,cpp,cs,cshtml,cu,cuh,cxx,dtd,fs,fsi,fsscript,fsx,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,hxx,inc,inl,ino,ipp,ixx,master,ml,mli,mpp,mq4,mq5,mqh,nuspec,paml,razor,resw,resx,shader,skin,tpp,usf,ush,vb,xaml,xamlx,xoml,xsd}]
indent_style = space
indent_size = 2
Expand Down
1 change: 1 addition & 0 deletions All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQ/@EntryIndexedValue">SQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CustomTools/CustomToolsData/@EntryValue">ExternalToolData|CSharpier|csharpier||csharpier|$FILE$</s:String>
<s:String x:Key="/Default/Environment/StructuredLogging/PropertyNamingType/@EntryValue">CamelCase</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=spandrel/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
10 changes: 10 additions & 0 deletions Core/Core/Api/GraphQL/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

[*.{cs,vb}]

# Name properties with camelCase
dotnet_naming_rule.properties_should_be_camel_case.severity = none
dotnet_naming_rule.properties_should_be_camel_case.symbols = properties
dotnet_naming_rule.properties_should_be_camel_case.style = property_style

dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_style.property_style.capitalization = pascal_case
7 changes: 7 additions & 0 deletions DesktopUI2/DesktopUI2/DesktopUI2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<PackageId>Speckle.DesktopUI</PackageId>
<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup Label="Legacy Code Exceptions" Condition="$(IsDesktopBuild) == 'false'">
<WarningLevel>0</WarningLevel>
<EnableNetAnalyzers>false</EnableNetAnalyzers>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
Expand Down
29 changes: 17 additions & 12 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,43 @@
<PropertyGroup Label="General Config">
<LangVersion>11</LangVersion>
<DebugSymbols>true</DebugSymbols>

<DebugSymbols>true</DebugSymbols>

<!-- False if running on CI, will prevent copying of files to local folders -->
<IsDesktopBuild Condition="'$(IsDesktopBuild)' == ''">true</IsDesktopBuild>

<!-- Code quality -->
<EnableNetAnalyzers>true</EnableNetAnalyzers>
<AnalysisLevel>latest-AllEnabledByDefault</AnalysisLevel>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>


<!-- Ignore some warnings for now -->

<!-- Ingored warnings, most aspirational but too noisy for now, some by design. -->
<NoWarn>
<!--Dissabled by design-->
CA5399;
<!--XML comment-->
CS1591;CS1573;CS1572;CS1570;CS1587;CS1574;
CS1711;CS1734;
<!--Others we don't want-->
CA1815;CA1054;CA5399;
<!--Nullability-->
CS8618;CS8602;CS8600;
CS1998; IDE0007; CS0618;
<!-- Globalization rules disabled -->
CS8618;
<!-- Globalization rules -->
CA1303;CA1304;CA1305;CA1307;CA1308;CA1309;CA1310;CA1311;CA2101;
NU1701;
$(NoWarn)
<!--Others we don't want-->
CA1815;CA1054;$(NoWarn)
</NoWarn>

<WarningsAsErrors>
$(WarningsAsErrors);
<!--Net6 default enabled analysers-->
CA1416; CA1417; CA1418; CA1831; CA2013; CA2014; CA2015; CA2017;
CA2018; CA2200; CA2252; CA2247; CA2255; CA2256; CA2257; CA2258;
<!--Net7 default enabled analysers-->
CA1420; CA1422; CA2259; CA2260;
<!--Net8 default enabled analysers-->
CA1856; CA1857; CA2021; CA2261;
<!--Security analysers -->
CA2100; CA2119; CA2153; CA2300; CA2301; CA2302; CA2305;
CA2310; CA2311; CA2312; CA2315; CA2321; CA2322; CA2326; CA2327;
Expand All @@ -66,9 +73,7 @@
<!--"CA5369: Use XmlReader for Deserialize" - we assume loaded XML is trusted-->
<!--"CA5399: Enable HttpClient certificate revocation list check" - causes issues with corporate networks that use SSL decryption. HTTPClientHandler does check for invalid SSL certs without this property set true-->
</WarningsAsErrors>

<!-- False if running on CI, will prevent copying of files to local folders -->
<IsDesktopBuild Condition="'$(IsDesktopBuild)' == ''">true</IsDesktopBuild>

<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
10 changes: 10 additions & 0 deletions Objects/Objects/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

[*.{cs,vb}]

# Name properties with camelCase
dotnet_naming_rule.properties_should_be_camel_case.severity = none
dotnet_naming_rule.properties_should_be_camel_case.symbols = properties
dotnet_naming_rule.properties_should_be_camel_case.style = property_style

dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_style.property_style.capitalization = camel_case

0 comments on commit 0e04abe

Please sign in to comment.