codemaid
codemaid copied to clipboard
CodeMaid reorganize conflicts with csharp_preferred_modifier_order preference within .editconfig file
Environment
- Visual Studio version: 2019
- CodeMaid version: 11.0
- Code language: C#
Description
I have the following setting in my .editorconfig file:
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
I also have configured CodeMaid so that it reorganizes the code automatically on save. However, it seems like CodeMaid has its own way of reorganizing modifiers and I've not seen anything within its UI to change it.
Steps to recreate
- Create a solution with the configuration described above for both .editconfig file and CodeMaid.
- Add a C# project
- Add an C# file to the project
abstract class Foo
{
protected abstract string Property { get; }
}
class Bar : Foo
{
protected sealed override string Property
{
get { return "dummy value"; }
}
}
- Save the file
Current behavior
The overriden property modifiers in Bar
will switch from sealed override
to override sealed
.
Expected behavior
The code should remain the same, as it follows what's dictated inside the .editorconfig file.
Thanks for reporting the issue. Yes CodeMaid does have its own configuration (predates .editorconfig) which you can find at Extensions->CodeMaid->Options->Reorganizing and by default largely follows StyleCop conventions. We do not explicitly re-order modifiers though such as sealed
and override
.
There is a separate issue that talks about moving to .editorconfig conventions #638
We do not explicitly re-order modifiers though such as sealed and override.
So you're saying you can't reproduce the issue as described above? Because right now it sure does look like CodeMaid do reorders sealed
and override
. :/
My comment was intended only to say that we do not intentionally (explicitly) re-order modifiers, that's not to say there can't be an unintentional effect or a combination of settings/extensions that is causing the behavior. However no, I have not been able to reproduce it.
A few things you can try:
- As part of CodeMaid's cleanup, we invoke Visual Studio's cleanup. Can you please invoke Edit->Advanced->Format Document to see if the issue occurs independent of CodeMaid?
- If you modify your .editorconfig settings in other ways do you see it getting respected by the editor or does it seem like the file is being ignored or potentially overridden by another configuration file?
- If you want to send me a minimal solution that exhibits the issue I can try that one as well.
This is an old issue but I'm seeing the same thing in Visual Studio 2019. CodeMaid is overriding my .editorconfig's modifier order every time I save.
The issue does not occur if I go to Edit -> Advanced -> Format Document, or if I use Visual Studio 2019's built-in code cleanup. This never happened before installing CodeMaid.
Thanks for the information. While it wouldn't explain the original report, since then there is a new issue introduced with the SDK releases at the launch of VS2022 that has caused a number of side effects including access modifiers getting mangled. See #879 for more details and a link back to the Roslyn issue.
Thanks for the information and follow-up! I'll be watching those other issues.
Hi there! My team and I are having the same issue, exactly as described.
My comment was intended only to say that we do not intentionally (explicitly) re-order modifiers, that's not to say there can't be an unintentional effect or a combination of settings/extensions that is causing the behavior. However no, I have not been able to reproduce it.
A few things you can try:
- As part of CodeMaid's cleanup, we invoke Visual Studio's cleanup. Can you please invoke Edit->Advanced->Format Document to see if the issue occurs independent of CodeMaid?
I've tried just that, but the issue does not occurs, so it seems that it's CodeMaid-related.
We'd appreciate a follow up on the matter :)
Before Cleanup Active Document
After Cleanup Active Document
By the way, I also use Resharper.