From 15b2a7376567b26e4ca4aa0001f9a05346e6af08 Mon Sep 17 00:00:00 2001 From: Refringe Date: Sat, 3 May 2025 16:40:18 -0400 Subject: [PATCH] .NET Format Implements a commit workflow on every commit that runs `dotnet format` to format the source of the project via the rules configured within the editorConfig. This does nothing to assign any formatting, it just enforces the rules already present. --- .editorconfig | 24 ++++++++++--------- .github/workflows/dotnet-format.yml | 37 +++++++++++++++++++++++++++++ server-csharp.sln.DotSettings | 1 + 3 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/dotnet-format.yml diff --git a/.editorconfig b/.editorconfig index 8247b27b..6696ba18 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,11 +12,12 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true +[{*.yaml,*.yml}] +indent_size = 2 + [*.json] ij_formatter_enabled = true -indent_style = space indent_size = 2 -trim_trailing_whitespace = true # C# files [*.cs] @@ -29,9 +30,6 @@ csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_between_query_expression_clauses = true -# ReSharper properties -resharper_wrap_object_and_collection_initializer_style = chop_always - # Indentation preferences csharp_indent_block_contents = true csharp_indent_braces = false @@ -77,13 +75,14 @@ dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case csharp_using_directive_placement = outside_namespace:error dotnet_sort_system_directives_first = true csharp_prefer_braces = true:warning -csharp_preserve_single_line_blocks = false -csharp_preserve_single_line_statements = false csharp_prefer_static_local_function = true:suggestion csharp_prefer_simple_using_statement = false:none csharp_style_prefer_switch_expression = true:suggestion dotnet_style_readonly_field = true:suggestion +# csharp_preserve_single_line_blocks = false +# csharp_preserve_single_line_statements = false + # Expression-level preferences dotnet_style_object_initializer = true:suggestion dotnet_style_collection_initializer = true:suggestion @@ -105,13 +104,11 @@ csharp_style_expression_bodied_operators = false:warning csharp_style_expression_bodied_properties = false:warning csharp_style_expression_bodied_indexers = false:warning csharp_style_expression_bodied_accessors = false:warning -csharp_style_expression_bodied_lambdas = false:warning csharp_style_expression_bodied_local_functions = false:warning +csharp_style_expression_bodied_lambdas = true # Pattern matching -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_prefer_pattern_matching = false:warning # Null checking preferences csharp_style_throw_expression = true:suggestion @@ -121,6 +118,7 @@ csharp_style_conditional_delegate_call = true:suggestion csharp_style_prefer_index_operator = false:none csharp_style_prefer_range_operator = false:none csharp_style_pattern_local_over_anonymous_function = false:none +csharp_style_inlined_variable_declaration = true # Space preferences csharp_space_after_cast = true @@ -145,6 +143,10 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_square_brackets = false +# ReSharper properties +resharper_wrap_object_and_collection_initializer_style = chop_always +resharper_merge_into_pattern_highlighting = none + # Xml project files [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] indent_size = 2 diff --git a/.github/workflows/dotnet-format.yml b/.github/workflows/dotnet-format.yml new file mode 100644 index 00000000..17cd3b56 --- /dev/null +++ b/.github/workflows/dotnet-format.yml @@ -0,0 +1,37 @@ +name: .NET Format + +on: + push: + branches: + - develop + pull_request: + branches: ["*"] + branches-ignore: + - main + +jobs: + dotnet-format: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.BYPASS_WORKFLOW_PAT }} + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0 + + - name: Restore Tool Dependencies + run: dotnet tool install -g csharpier + + - name: CSharpier Format + run: csharpier format . + + - uses: stefanzweifel/git-auto-commit-action@v6 + with: + commit_message: .NET Format Style Fixes + commit_user_name: Format Bot diff --git a/server-csharp.sln.DotSettings b/server-csharp.sln.DotSettings index 34e0f2f3..4ea34dbf 100644 --- a/server-csharp.sln.DotSettings +++ b/server-csharp.sln.DotSettings @@ -2,6 +2,7 @@ True True True + True True True True \ No newline at end of file