Configuring "optimize usings"

It is possible to have the "optimize usings" feature of code cleanups just remove unused using statements?  It seems to also shorten existing using statements, which I don't want.

Thanks!

2 comments

I would really like this feature.  Optimize usings can be too aggressive in the steps it takes, which tends to upset my co-workers.

I suggest that imports optimization should have additional options:
checkbox: remove unused using statements
checkbox: sort using statements alphabetically
checkbox: group using statements by root namespace  (this would interact with the setting for how many lines between using groups, so may not be necessary)

Radio buttons:
    Leave using directives in existing scope
    Move using directives to outtermost scope
    Move using directives to deepest scope
    Move using directives matching namespace inside namespace

I admit that the last item is a bit weird -- this is a pattern my co-worker uses:

using System.A;
using System.B;

using ThirdParty.A;
using ThirdParty.B;

namespace MyCompany.Foo
{
    using Bar;
...

(Where Bar is a shortening of MyCompany.Bar)
Even if the last option was not implemented, simply having the ability to "Leave using directives in existing scope" would allow me to run optimize usings across our entire codebase.
If the last option were implemented I would want any using directives that were moved to a deeper scope to be shortened (or not) according to the "Prefer fully qualified using name at nested scope" setting.

Thanks,
Dave

0

+1
You should open a feature request. :)

0

Please sign in to leave a comment.