Highlight redundant SuppressMessage attributes and "ReSharper disabled" comments

Sometimes I have to disable Rider warnings if my classes are being instantiated by third party libraries or through exceptions or otherwise (see here https://rider-support.jetbrains.com/hc/en-us/community/posts/360006858879)

One common usage is implementing a class which would then be auto-wired by a DI library:


public interface IMyClass { void MyMethod() };

public class MyClass: IMyClass { public void MyMethod() {...} }

container.RegisterAutoWiredAs<MyClass, IMyClass>();

public class OtherClass { private readonly IMyClass _myClass; OtherClass(IMyClass myClass) { _myClass = myClass } }


MyClass is never instantiated directly by my code, so I have to add ClassNeverInstantiated.Global to suppress the Rider warning.

Then I might want to add a unit test which would create an instance of MyClass directly.

The SuppressMessage attribute on the class then becomes redundant (it suppresses a warning which not have happened in the first place), however I have no way of telling this by looking at the code.

It would be nice if the redundant SuppressMessage attributes and "ReSharper disable" comments could be highlighted.

Please sign in to leave a comment.