Eduardo Bottcher
Eduardo Bottcher

Reputation: 151

What is the static analysis rule to warn about unused using statements?

Is there any FxCop or StyleCop rule that warns when there is a using statement that is no longer referenced by any object in the file?

Upvotes: 5

Views: 2960

Answers (2)

Roald
Roald

Reputation: 2979

In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses.

So all in all:

  1. Set the Warning Level to 4 for code analyzers to fire.
  2. Set rules CS8019 and IDE0005 to warning in your projects' Code Analysis rules (Properties > Code Analysis).
  3. Make sure to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses.

Upvotes: 2

Udo
Udo

Reputation: 459

You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style.

Upvotes: 5

Related Questions