codemaid
codemaid copied to clipboard
[Question] Does CodeMaid respect .editorconfig ?
Hello,
i just wanted to know if CodeMaid does respect the editorconfig settings or rulesets from analyzers ?
Thanks for asking the question. We don't explicitly go out of our way to refer to those external sources, but we do read in to some of Visual Studio's settings and respect those. Do you have a specific setting/example in mind?
I came here wondering the same thing. I think editorconfig files are poised to be the standard for this kind of coding standard information. If possible, I'd transition from CodeMaid.config to putting everything inside an editorconfig if you can. Visual Studio supports a ton of extensions to the basic editorconfig format for controlling just about everything, and it seems you can control a lot of R# settings from editorconfig as well. It seems to me like a consensus is building, and it seems to be that formatting information belongs in the editorconfig file.
Cool, I'm open to the concept. A couple thoughts:
-
Does EditorConfig have the concept of user level settings vs. solution level settings? I didn't see it in a quick search of their site. We would have to figure out a compatible strategy as we currently store a CodeMaid.config within the user profile and that's what people default to using unless there are solution-specific settings.
-
Transitioning CodeMaid settings into EditorConfig would be a breaking change for users. Teams with solution-specific settings would need to migrate their configuration and coordinate all users upgrading CodeMaid at the same time. We could offset that by supporting both the old and new formats, people including 2 configuration files in their repo, and the team eventually cleaning the old file once they knew it was no longer needed by manually confirming with all team members. It's all doable, but a bit of a headache I'm not sure how many people would want to undergo.
I second that, actually the CodeMaid project itself uses different formatting settings than some other projects I work on, forcing me to change settings manually when switching projects. I often forget and only find out when viewing diffs before committing to source control.
editorconfig files do not have any kind of user vs project settings. That's kind of the idea. I believe the consensus is that editorconfig settings take precedence over whatever else you had set as a personal default. When a lead developer on a project says "This is how we're doing it", then that's how we're doing it. Of course, if the editorconfig file doesn't have a setting for something, then your own preference would take effect. I guess that would mean that you'd still need a mechanism for storing the user's personal settings though. That probably makes this impractical, unless the user's settings were also stored in the same format, maybe somewhere in AppData?
Yep, I agree that solution-specific settings take precedence over user settings and CodeMaid does follow that convention. The user settings really step in for having your own defaults that you don't have to embed in every separate project/spike/experiment that you start up. I look at it as the same as .gitignore files.
The format for .editorconfig looks pretty simple so I'm not concerned about that for our basic settings (e.g. yes/no).. but I'll add to the list above:
- Some of our settings can get complex (e.g. file exclusion patterns) and span multiple lines, so we might have to change the way some of them are encoded as well. Certainly doable, just making notes while things come to mind.
Reference: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
Been thinking about it, and actually .editorconfig
would make it possible to store the more complicated comment formatting settings in a reasonable way since it can dynamically add keys.
Since support is built into VS2017, I assume there is a way to access the current config values too? So far the only thing I found is Supporting EditorConfig for your language service.
More searching leads me to believe the built-in .editorconfig
support is part of Roslyn:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.formatting?view=roslyn-dotnet https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/Formatting/FormattingOptions.cs (and others in that folder)
Ok, the code in the Microsoft.CodeAnalysis.Options
namespace is where the work is done (can't link to namespace, so choose a random file instead).
This file CSharpCodeStyleOptions.cs
is a nice example of how it's used, and even how to support reading options from both .editorconfig
and user profile.
+1
@MelGrubb writes
editorconfig files do not have any kind of user vs project settings. That's kind of the idea. I believe the consensus is that editorconfig settings take precedence over whatever else you had set as a personal default. When a lead developer on a project says "This is how we're doing it", then that's how we're doing it.
.editorconfig file placement is key in EditorConfig: See https://editorconfig.org/#file-location... it basically has cascading overrides, with the .editorconfig closest to the file in the file hierarchy overriding configuration settings lower in the file/folder hierarchy. Would be nice to see CodeMaid support something similar eventually...
PS I am creating a coding standards nuget package for our team. As of NuGet 3, solution-level packages are no longer supported, so trying to get a CodeMaid.config file in to the solution requires some init.ps1 gymnastics... do-able, but lacks the flexibility of project-level configs or a configuration hierarchy like .editorconfig has.
I may enter a feature request for a config hierarchy like editorconfig, but I suspect it is a big undertaking and would break backward config compatibility as previously discussed. :-(
+1
+1 would like to see codemaid respect my editor config settings as well
Specific example: would love for CodeMaid to respect my projects' dotnet_style_require_accessibility_modifiers
unless overridden by Cleaning_InsertExplicitAccessModifiersOn*
in a solution CodeMaid.config
.
Also worth noting that Resharper has started storing its config in EditorConfig: https://www.jetbrains.com/help/resharper/Using_EditorConfig.html. CodeMaid supporting the same seems natural.
Code must always format and layout the same way for all developers, hence no user settings are required for code style and formatting options.
Perhaps start by shifting such settings to EditorConfig, leaving only the user (developer) experience/UI settings in the CodeMaid specific configuration files.
+1