Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support more .editorconfig code styles #40

Closed
Zonnex opened this issue Mar 4, 2019 · 17 comments
Closed

Support more .editorconfig code styles #40

Zonnex opened this issue Mar 4, 2019 · 17 comments
Labels
Feature Request This issue is requesting an enhancement or new feature

Comments

@Zonnex
Copy link

Zonnex commented Mar 4, 2019

I was quite happy when I stumbled across this article by Scott Hanselman, I installed dotnet-format globally and ran it. However it does not apply all rules, and I can't figure out if I'm missing something or if it's not intended to do so.

For example, it cleaned out some trailing whitespace which was great and moved curly braces to new lines.
It did not apply any rules regarding var vs types. Is this intended to be skipped, and if so is it planned to be supported?

@dotnetgeek
Copy link

Hi,

thank you so much for building this tool. It is really helpful. But I see the same behavior.

In the .editorconfig I have the settings:

dotnet_style_require_accessibility_modifiers = always
csharp_preserve_single_line_statements = true

and it works if I use the code format option in Visual Studio (CTRL+E, D).
When I ran this tool it will not be applied.

@jmarolf jmarolf added the Bug This issue describes behavior that is not working as expected label Mar 4, 2019
@jmarolf
Copy link
Contributor

jmarolf commented Mar 4, 2019

@Zonnex or @dotnetgeek could you post a link to your projects or at least the entire .editorconfig file that you are using?

@Zonnex
Copy link
Author

Zonnex commented Mar 4, 2019

This branch took this editorconfig and changed it to use these settings to try enforce types, but no files are changed when I run dotnet-format on the solution.

csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_elsewhere = false:warning

@jmarolf
Copy link
Contributor

jmarolf commented Mar 4, 2019

@Zonnex can you point me to the actual code you are trying to format?

@Zonnex
Copy link
Author

Zonnex commented Mar 4, 2019

For instance, with those options set to false, I would expect line 44 and 45 in this document to have types instead of 'var' keyword.

I was digging around in roslyn code, and my guess why this isn't working is because these options are internal and not used here

@dotnetgeek
Copy link

Here is my current editorconfig

https://gist.github.com/dotnetgeek/f175091779c9a9552fe9046f16457568

@Zonnex
Copy link
Author

Zonnex commented Mar 4, 2019

For @dotnetgeek's issue, I found that this class contains "dotnet_style_require_accessibility_modifiers", but that specific option is internal and as such is not exposed.

However I'd expect that csharp_preserve_single_line_statements which is public here named WrappingKeepStatementsOnSingleLine to work

@JoeRobich
Copy link
Member

Hi everyone, Thanks for the enthusiasm!

Currently dotnet format is the equivalent of running the 'Format Document' command in Visual Studio, which supports whitespace formatting. Our goal is to support more of the code cleanup scenarios in the future.

@JoeRobich JoeRobich added Feature Request This issue is requesting an enhancement or new feature and removed Bug This issue describes behavior that is not working as expected labels Mar 4, 2019
@JoeRobich
Copy link
Member

I have added a wiki page that lists the currently supported .editorconfig options https://github.com/dotnet/format/wiki/Supported-.editorconfig-options

@ErikSchierboom
Copy link

It would be great if more scenarios were supported!

@ghost
Copy link

ghost commented Mar 21, 2019

@JoeRobich is the development to support more scenarios open to contributions here on GitHub?

@tannergooding
Copy link
Member

Sorting or grouping using statements also doesn't appear to work. They are controllable via:

dotnet_separate_import_directive_groups
dotnet_sort_system_directives_first

@JoeRobich
Copy link
Member

@challen0 Supporting the Roslyn analyzers and fixes for the other code styles is work that we want to do ourselves. Thanks for the offer =)

@JoeRobich JoeRobich changed the title format not applying all rules Support more .editorconfig code styles Mar 27, 2019
@ghost
Copy link

ghost commented Apr 8, 2019

Would love this feature

@runehalfdan
Copy link

Would love to see support for these as well:

charset=utf-8
insert_final_newline=true

We have a ton of code from before .editorconfig was a thing, and when we do changes there we frequently get noise in the diffs when final newline is added, or UTF-8 BOM is removed. Fixing all those in one go would be really nice.

@JoeRobich
Copy link
Member

@runehalfdan Support for end_of_line and insert_final_newline are in the latest builds on NuGet. Also, I may have some time to look into charset in the coming weeks.

Thanks for reminding me to update the supported options wiki page. =)

@JoeRobich
Copy link
Member

Closing this issue now that the core .editorconfig properties are supported. CodeStyle analyzer support is being tracked at #416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is requesting an enhancement or new feature
Projects
None yet
Development

No branches or pull requests

7 participants