Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Code Quality: Enforce code style in EditorConfig #16431

Open
Lamparter opened this issue Nov 3, 2024 · 8 comments · May be fixed by #16441
Open

Code Quality: Enforce code style in EditorConfig #16431

Lamparter opened this issue Nov 3, 2024 · 8 comments · May be fixed by #16441

Comments

@Lamparter
Copy link
Contributor

Description

Currently, there is a code style, Website:"docs/contributing/code-style". However, this would be better if it was enforced throughout the codebase through the editorconfig file in the root directory.

Concerned code

Files/.editorconfig

Lines 3 to 6 in e7d00f3

[**/*.cs]
indent_style = tab
indent_size = 4
tab_width = 4

Gains

  • Code style is automatically enforced
  • Less need for review to check if new contributors have used the code style

Requirements

Comments

I did a first draft here, I'll create a PR for it when this issue is marked ready to build.
root = true

[**/*.xaml]
indent_style = tab
indent_size = 4
tab_width = 4

[**/*.cs]
indent_style = tab
indent_size = 4
tab_width = 4

# https://files.community/docs/contributing/code-style

dotnet_naming_rule.pascal_case_for_classes.symbols = classes
dotnet_naming_symbols.classes.applicable_kinds = class
dotnet_naming_symbols.classes.applicable_accessibilities = *
dotnet_naming_symbols.classes.required_prefix = 
dotnet_naming_symbols.classes.required_suffix = 

dotnet_naming_rule.pascal_case_for_interfaces.symbols = interfaces
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = *
dotnet_naming_symbols.interfaces.required_prefix = I
dotnet_naming_symbols.interfaces.required_suffix = 

dotnet_naming_rule.pascal_case_for_structs.symbols = structs
dotnet_naming_symbols.structs.applicable_kinds = struct
dotnet_naming_symbols.structs.applicable_accessibilities = *
dotnet_naming_symbols.structs.required_prefix = 
dotnet_naming_symbols.structs.required_suffix = 

dotnet_naming_rule.pascal_case_for_methods.symbols = methods
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = *
dotnet_naming_symbols.methods.required_prefix = 
dotnet_naming_symbols.methods.required_suffix = Async

dotnet_naming_rule.camel_case_for_variables.symbols = variables
dotnet_naming_symbols.variables.applicable_kinds = field
dotnet_naming_symbols.variables.applicable_accessibilities = private
dotnet_naming_symbols.variables.required_prefix = _
dotnet_naming_symbols.variables.required_suffix = 

dotnet_naming_rule.camel_case_for_parameters.symbols = parameters
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.required_prefix = 
dotnet_naming_symbols.parameters.required_suffix = 

dotnet_naming_rule.pascal_case_for_properties.symbols = properties
dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_symbols.properties.applicable_accessibilities = *
dotnet_naming_symbols.properties.required_prefix = 
dotnet_naming_symbols.properties.required_suffix = 

dotnet_naming_rule.upper_case_for_constants.symbols = constants
dotnet_naming_symbols.constants.applicable_kinds = field
dotnet_naming_symbols.constants.applicable_accessibilities = *
dotnet_naming_symbols.constants.required_prefix = 
dotnet_naming_symbols.constants.required_suffix = 
dotnet_naming_symbols.constants.required_capitalization = all_upper

dotnet_style_require_accessibility_modifiers = always:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_qualify_field_access = false
dotnet_style_qualify_property_access = false
dotnet_style_qualify_method_access = false
dotnet_style_qualify_event_access = false
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion

csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
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

csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

csharp_style_namespace_declarations = file_scoped

dotnet_naming_rule.pascal_case_for_classes.style = pascal_case
dotnet_naming_rule.pascal_case_for_interfaces.style = pascal_case
dotnet_naming_rule.pascal_case_for_structs.style = pascal_case
dotnet_naming_rule.pascal_case_for_methods.style = pascal_case
dotnet_naming_rule.camel_case_for_variables.style = camel_case
dotnet_naming_rule.camel_case_for_parameters.style = camel_case
dotnet_naming_rule.pascal_case_for_properties.style = pascal_case
dotnet_naming_rule.upper_case_for_constants.style = all_upper

dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_style.all_upper.capitalization = all_upper
@yaira2
Copy link
Member

yaira2 commented Nov 3, 2024

I thought we had this at one point. @lukeblevins do you have any recollection?

@0x5bfa
Copy link
Member

0x5bfa commented Nov 3, 2024

I think it's good idea but some values are default so can be deducted.
@yaira2 i guess that's this #2781?

@lukeblevins
Copy link
Contributor

Visual Studio might have not supported editorconfig preferences for XAML. I don't recall whether that's changed

@Lamparter
Copy link
Contributor Author

@yaira2 would you like to move forward with this?

@0x5bfa
Copy link
Member

0x5bfa commented Nov 4, 2024

Once you made a PR, I'll shortly review it out.

@Lamparter Lamparter linked a pull request Nov 6, 2024 that will close this issue
@yaira2
Copy link
Member

yaira2 commented Nov 21, 2024

If I remember correctly, the last time this was discussed, we concluded that it would be better to add a check before merging PRs, similar to what we do for XAML.

@0x5bfa
Copy link
Member

0x5bfa commented Nov 21, 2024

Did we? but it's a great idea. We should use "dotnet format" and specify changed files for each.
Ctrl+S doesn't format automatically like XamlStyler so we can do that any time before or after

@Lamparter
Copy link
Contributor Author

Yes exactly. Visual Studio's code cleanup feature is also based on this file.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

4 participants