Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable "Name can be simplified" IDE0003 fix hint

Visual Studio 2017 shows a hint for unnecessary this qualifiers even when the inspection is disabled in the options.

This is how it looks:

(First line is the culprit, second line is how I want this to always look like.)

Hovering over the grayed out this and clicking on the light bulb shows this suggested fix: enter image description here

I can't find a way of disabling this completely. Sometimes I want to have "unnecessary" this qualifiers and sometimes I don't, so I don't want VS to comment about this at all.

"None" is the least severe option yet it still shows this annoying, different color.
enter image description here


Is there any possibility of complete disabling this inspection?

like image 277
Acidic Avatar asked Feb 19 '18 00:02

Acidic


2 Answers

You can use a ruleset file to disable any analysis if you know its diagnostic id (in this case 'IDE0003')

  1. On the References node of you project right click on Analyzers and select Open Active Rule Set image

  2. Once the ruleset editor is open just search for IDE0003 and uncheck the checkbox. Then save the ruleset file. Then save the project.

image

image

  1. The following XML will be added to you project file. You can add this ruleset file to any project where you want this rule disabled.

<CodeAnalysisRuleSet>ConsoleApp9.ruleset</CodeAnalysisRuleSet>

like image 162
Jonathon Marolf Avatar answered Nov 18 '22 15:11

Jonathon Marolf


Looks like the current process is more complicated for .NET Core and .NET Standard projects.

From MS VS Docs:

If you have a .NET Core or .NET Standard project, the process is a little different because there's no Code Analysis property tab. Follow the steps to copy a predefined rule set to your project and set it as the active rule set. After you've copied over a rule set, you can edit it in the Visual Studio rule set editor by opening it from Solution Explorer. [emphasis mine]

Taking the first link in that quote will eventually take you, after a little sleuthing, to Code style rule options, that finally tells you how to add the file:

In Visual Studio, you can generate this file and save it to a project at Tools > Options > Text Editor > [C# or Basic] > Code Style > General. Then, click the Generate .editorconfig file from settings button.

location of "Generate .editorconfig file from settings" button in VS settings

NOTE: This produces a tiny warning just under your toolbars that an .editorconfig has been added to your solution. Select the "Yes" button to include it in your solution.

And now you can open and edit your new .editorconfig file.

Looks like this is the "offending" section:

# this. and Me. preferences
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_property = false:suggestion

If that dotnet_style_qualification_for_property is changed to = true:suggestion (explanation here), I think you're golden [at least for properties, of course -- make edits as appropriate].

like image 30
ruffin Avatar answered Nov 18 '22 13:11

ruffin