Roslyn: Ability to promote dead code analysis suggestion to warning or error

Created on 22 Mar 2019  路  7Comments  路  Source: dotnet/roslyn

Ability to promote dead code analysis suggestion (IDE0051) to warning or error

image

Area-IDE Bug Resolution-By Design

All 7 comments

Hi, @kendrahavens

I have a question about how to detect useless code or functions. For sometimes I write an ASP.NET Core project and I just create a new action in my controller like this:

    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return something;
        }

        public IActionResult Error()
        {
            return someOtherThing;
        }
    }

Of course, the Index method has zero references and seems to be dead and useless. But it wasn't because it was an action which makes sense.

If the compiler treats it as a warning, it will make my project whole of warnings. Any solution for that?

Thanks!

Hey @Anduin2017,

What version are you seeing this warning? We did fix a bug where interface-implementing events appeared unused. Fix was released in Dev16 Preview 2.

@kendrahavens Thanks for your response! I just worried that fixing this one may cause more issues for detecting more useful code useless.

@kendrahavens You should be able to promote IDE0051 to a warning/error using a ruleset file entry. In future, when we add .editorconfig support in compiler to allow specifying diagnostic severity in .editorconfig file such that it is respected by the compiler, same functionality can be achieved by adding an entry in the .editorconfig file.

@Anduin2017 The analyzer only flags unused _private_ members which are never referenced/invoked as dead code.

@kendrahavens I believe once we have .editorconfig support in compiler, we should revive https://github.com/dotnet/roslyn/pull/29332 so we offer a code fix to configure severity of all reported diagnostics (including 3rd party analyzer diagnostics) via .editorconfig file

@mavasani what shall be contents of the ruleset file "to promote dead code analysis suggestion (IDE0051) to warning or error"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshua-mng picture joshua-mng  路  3Comments

MadsTorgersen picture MadsTorgersen  路  3Comments

NikChao picture NikChao  路  3Comments

AdamSpeight2008 picture AdamSpeight2008  路  3Comments

nlwolf picture nlwolf  路  3Comments