Any way to generate a compiler warning for unused users?

Is there a way to generate a warning in VS2008 for unused operators? I know there is Edit->Intellisense->Organize Usings->Remove Unused Usings

, but it would be nice if it was a compile-time warning.

+2


source to share


4 answers


If you are using ReSharper , it will show unused names in a different color by default (as a warning in the error analysis sidebar), and if you highlight them, you can change them to show them as errors. Unfortunately this will not prevent compilation, but it warns you that they are not being used.



+3


source


We try to create warnings for situations where the code in question is almost certainly broken, misleading, or useless. Also, since many people are compiled with "warnings as errors" we have a high bar; it is bad to introduce a false or unnecessary warning.

Imagine compiling with warnings enabled by default as errors. Imagine that we have implemented the function you want. You start a new project and we generate for you:



using System;
using System.Text;
using System.Linq;

class Program
{
  static void Main(string[] arguments)
  {
  }
}

      

and we will immediately inform you that you have a bug in your program, because none of the "tricks" are needed! This is a very bad user experience . Those "usings" are put there by the IDE for your convenience, so you don't need to define them yourself. Your suggested function will turn this from convenience to nag.

+8


source


No, because this is not a compiler issue, so you cannot generate compiler warnings. Compiler warnings are only generated when a code dead spot is found, such as an empty catch statement. Or an unused variable. Basically anything that can cause runtime problems. Since the use of statements has nothing to do with the runtime and more text file style problems, they won't generate warnings.

But you can use a tool like reSharper to alert you to unused operators.

+2


source


I assume this is not a compiler warning, because it has absolutely no consequences ...

0


source







All Articles