belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.43k stars 99 forks source link

Consider removing redundant `using` statements #1008

Open will-molloy opened 1 year ago

will-molloy commented 1 year ago

I think the tool should remove redundant (duplicate or unused) using statements.

Expected:

using MyUsedHelper;

Actual:

using MyUsedHelper;
using MyUsedHelper;
using MyUnusedHelper;
belav commented 1 year ago

CSharpier is unable to determine if a using is unused, it only works with the syntax tree of a file.

I am debating if removing redundant usings should be one of the exceptions to the "only change whitespace" rule.

On the surface it seems like it would be fairly easy to implement. The only part that could get a bit complicated is the syntax tree validation, which tries to ensure that CSharpier doesn't unintentionally eat any code.

However there are other tools that can remove them, and I don't know how often they show up. So perhaps it isn't worth the effort.