When formatting and auto fixing "linting" errors in C# files in VSCode it seems to discard my unused variables. Basically it puts _ =
in front of everything.
It does this because csharp_style_unused_value_assignment_preference = discard_variable
is the default.
https://learn.microsoft.com/da-dk/dotnet/fundamentals/code-analysis/style-rules/ide0059#csharp_style_unused_value_assignment_preference
// csharp_style_unused_value_assignment_preference = discard_variable
int GetCount(Dictionary<string, int> wordCount, string searchWord)
{
_ = wordCount.TryGetValue(searchWord, out var count);
return count;
}
// csharp_style_unused_value_assignment_preference = unused_local_variable
int GetCount(Dictionary<string, int> wordCount, string searchWord)
{
var unused = wordCount.TryGetValue(searchWord, out var count);
return count;
}
That's neat. But how do I turn it off? So when I apply formatting to my C# files in VSCode it doesn't add _ =
.
My VSCode settings:
{
"settings": {
"[csharp]": {
"editor.defaultFormatter": "csharpier.csharpier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.csharp": true
}
},
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true,
}
}