Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a basic Editorconfig to help standardize formatting and code style.#41

Merged
tesar-tech merged 2 commits into
BlazorStatic:masterfrom
patricktcoakley:editorconfig
Oct 16, 2024
Merged

Add a basic Editorconfig to help standardize formatting and code style.#41
tesar-tech merged 2 commits into
BlazorStatic:masterfrom
patricktcoakley:editorconfig

Conversation

@patricktcoakley

@patricktcoakley patricktcoakley commented Oct 15, 2024

Copy link
Copy Markdown
Contributor

#39

So this is a pretty simple .editorconfig with the changes applied. Feel free to modify/change however you see fit, but I didn't want to bring in too many rules and keep it mostly about spacing. I tend to use rules from MS OSS projects like Roslyn or ASP.NET, but it looks like the code in this project differs from that style. I can also update my branch if there's an .editorconfig out there you had in mind as it's relatively easy for me to just reformat and push my changes.

@netlify

netlify Bot commented Oct 15, 2024

Copy link
Copy Markdown

Deploy Preview for blazorstatic failed. Why did it fail? →

Name Link
🔨 Latest commit e76c327
🔍 Latest deploy log https://app.netlify.com/sites/blazorstatic/deploys/670fe9ea8892f0000899e48e

@tesar-tech

Copy link
Copy Markdown
Collaborator

Hmm. I am having trouble to understand how rider sync the editorconfig with its own "mind".

this is my current settings
image
As I understand, the editorconfig should have the highest priority...

Now let's focus on Progam.cs of BlazorStaticWebsite project.. I guess you "applied" the formatter when you went around..
So for example you changed this

builder.Services.AddBlazorStaticService(opt => {

into

builder.Services.AddBlazorStaticService(opt =>
        {

But which settings form editorconfig instruct the rider to do so?

Because when I do Reformat code (Ctrl+Alt+Enter or Ctrl+k,d (from vs bindings) ) it jumps back to one line..

My understanding is that you have your own settings in rider for Lambda and Delegate (anonymous method declaration), I have in my rider the At the end of line (K&R style), while you probably At next line...

So we will override each others Lambda and Delegate settings, unless it's saved in editorconfig?

So I guess we need to export everything to keep the formatting the same on all machines and IDEs?

@patricktcoakley

Copy link
Copy Markdown
Contributor Author

So you can actually "auto-detect" code styles and dump them into the editor config. I ran this on the project and it's mostly Resharper-specific:

[*]

# Microsoft .NET properties
csharp_indent_braces = false
csharp_new_line_before_open_brace = accessors,anonymous_types,control_blocks,local_functions,methods,object_collection_array_initializers
csharp_preferred_modifier_order = public, protected, internal, override, file, new, private, abstract, virtual, sealed, required, async, extern, unsafe, volatile, static, readonly:suggestion
csharp_style_var_for_built_in_types = false:suggestion
csharp_using_directive_placement = inside_namespace:silent
dotnet_sort_system_directives_first = true

# ReSharper properties
resharper_align_multiline_binary_expressions_chain = false
resharper_arguments_anonymous_function = named
resharper_arguments_skip_single = true
resharper_blank_lines_after_block_statements = 0
resharper_blank_lines_after_multiline_statements = 0
resharper_blank_lines_after_start_comment = 0
resharper_blank_lines_around_single_line_type = 0
resharper_braces_for_ifelse = required_for_multiline
resharper_csharp_allow_comment_after_lbrace = true
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_blank_lines_around_invocable = 0
resharper_csharp_empty_block_style = together_same_line
resharper_csharp_indent_invocation_pars = none
resharper_csharp_indent_method_decl_pars = outside
resharper_csharp_keep_blank_lines_in_declarations = 100
resharper_csharp_max_line_length = 3472
resharper_csharp_other_braces = end_of_line_no_space
resharper_csharp_remove_blank_lines_near_braces_in_code = false
resharper_csharp_remove_blank_lines_near_braces_in_declarations = false
resharper_csharp_space_around_alias_eq = false
resharper_csharp_space_before_trailing_comment = false
resharper_for_other_types = use_var_when_evident
resharper_indent_inside_namespace = false
resharper_indent_pars = outside
resharper_indent_preprocessor_other = do_not_change
resharper_indent_primary_constructor_decl_pars = inside
resharper_max_attribute_length_for_same_line = 10000
resharper_object_creation_when_type_not_evident = target_typed
resharper_place_accessorholder_attribute_on_same_line = if_owner_is_single_line
resharper_place_expr_method_on_single_line = true
resharper_place_method_attribute_on_same_line = true
resharper_space_within_empty_braces = false
resharper_wrap_after_primary_constructor_declaration_lpar = false
resharper_wrap_list_pattern = chop_if_long

You can also export your Rider-specific settings into the .editorconfig

Screenshot 2024-10-15 at 3 54 52 PM

The exported .editorconfig has a lot more C#-specific things but still a lot of Resharper-specific ones.

I think it would be best to avoid adding these as other contributors might be using VS, VSCode, NeoVim, etc, so in my mind unless you want to drill down into every style choice your best bet is to standardize on a popular project's .editorconfig and go from there.

Some examples:

Otherwise, another way is to just continue with what I have here, start tweaking it as you go using your local exported .editorconfig, and build it up over time.

- reformat based on editorconfig
@tesar-tech

Copy link
Copy Markdown
Collaborator

ok. I used the aspire editcofig.. Also changed something...
I guess when you now run Format and Clean Up -> **Reformat code it will respect the changes that are in editorconfig, but will override these that are not set there.

Let me know if you have something against my decisions, otherwise we can merge it.

@patricktcoakley

Copy link
Copy Markdown
Contributor Author

LGTM. I think just getting it in is important and we can always tweak it as we go.

@tesar-tech tesar-tech merged commit dabdf69 into BlazorStatic:master Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants