Removing explicit default access modifiers in Visual Studio using EditorConfig
Almost five years ago I wrote post Removing explicit default access modifiers (Roslyn analyzer and codefix) and it was a great exercise and I still prefer to have code without all the private
, etc. noise. But also nowadays Visual Studio supports all sorts of code style rules via EditorConfig file. Can I teach Visual Studio to actually suggest removing explicit default access modifiers?
I was expecting it to require bit of persuasion, but instead it was smooth sailing. The key for EditorConfig is called dotnet_style_require_accessibility_modifiers
and simply setting it to omit_if_default
(probably omit_if_default:suggestion
) does all the magic.
Although it works fine, it’s clear that using this setting is not exactly expected in terms of what Visual Studio tells you you should do. 😃
First, in hint, it tells you “Accessibility modifiers required”.
And then, when you invoke the code fix, it calls the action “Add accessibility modifiers”. Which is actually exactly the opposite of what is going to happen.
But I take it. Similar to the preference between spaces and tabs, not using the explicit default access modifiers is niche choice in .NET world, as far as I can tell. And this is easier than introducing the analyzer into the project(s) (and potentially maintaining it).
Probably Miguel de Icaza and I should start a gang.