Disable all Resharper warnings with a comment

三世轮回 提交于 2019-11-27 15:34:32

问题


Is there a way to disable all Resharper warnings for a file or section of code with a single comment? I'm trying to create some coding exercises for interviewing potential candidates, and the Resharper warnings give away the problem I want the candidate to spot :P Suppressing the specific warning still makes it obvious what the problem is.

I still want to have Resharper available during the interview, I just want the candidate to spot this problem without Resharper spoiling the fun.

edit: Sorry I'll try to be more clear about what I'm after. I don't want to permanently disable a particular Resharper warning, I just want it to not show in one particular file, because the point of the exercise is to see if the developer understands the reason for the warning.

To give one example, there is a Resharper warning to use the .Any extension method instead of Count() > 0, which I want the developer to point out themselves. To disable that warning, you have to use a comment of:

// ReSharper disable UseMethodAny.0

around the code. That kind of gives the game away a little.

I was trying to find something like:

// ReSharper disable all

which I could place at the top of the class, so it won't give away what I want the developer to find. But I can't seem to find a way to do that. Using numbers for the Resharper warnings would be fine as well, but I don't think it works that way?


回答1:


According to this blog post on the JetBrains blog, in ReSharper 8 there will be a single comment that can disable resharper in a file.

It will be

// ReSharper disable All

Note: The "All" is case-sensitive, the rest is not.




回答2:


Nial, you can press Ctrl + Shift + Alt + 8 to disable analyses and highligtings in current file.




回答3:


The following worked for me.

  • Add "No Resharper" to Generated Code Regions in R# -> Options -> Code Inspection -> Generated Code
  • Use the following to suppress the warnings:

    #region No Resharper
    
    // All R# warnings are suppressed here
    
    #endregion
    



回答4:


you have to configure the ReSharper Inspections

http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Configuring_Warnings.html




回答5:


You could also use the SuppressMessageAttribute with ReSharper as the category and All as the checkId on the method or the class as shown below. This is more granular than disabling everything in the file if you need the fine grained control.

Tested with Visual Studio 2015 Update 3 and ReSharper Ultimate 10.0.2

[SuppressMessage("ReSharper", "All")]
private void MethodWithMultipleIssues()
{
    TestClass instance = null;
    // You would get an "Expression is always true" message
    if (instance == null)
    {
        Debug.WriteLine("Handle null");
    }
    else
    {
        // You would get an "Code is unreachable" message
        Debug.WriteLine("Handle instance");
    }
}



回答6:


You can add the file to the list of "Generated Code" in ReSharpers Options Menu:

Options > CodeInspection > Generated Code


来源:https://stackoverflow.com/questions/8854701/disable-all-resharper-warnings-with-a-comment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!