Weird code cleanup/code style with using statements and preprocessor directives
Hello there,
I've encountered a weird issue with the code cleanup feature. I'm not sure whether it's a bug or if I just configured it the wrong way, but this is what happens (I'm using Rider 19.1.3 with Unity btw.):
For example, take this code:
Now I do my code cleanup with the specified code style and after that it looks like this:
This obviously leads to issues, because it completely rearranged the using-statements so some of them are now INSIDE of the the if-preprocessor-directives even though the weren't before and I have no idea why it does that.
Does anyone know what setting I need to adjust to correct this?
Thank you very much in advance!
Please sign in to leave a comment.
Hi Christian!
Could you please try to update Rider and recheck it? I can't reproduce this on 2019.2.2.
If the problem persists, could you add a small code snippet where you can reproduce the issue? Thank you in advance.
Hi,
okay, this is really strange. I tried to reproduce the issue with an "empty" new Unity project and added a new class.
After that I added these using-statements just for the purpose of testing it:
Which may be what Rider thinks would be correct, but actually alters the code in a way, that building the project from within Unity leads to errors.
The problem DOES NOT persist in 19.2.2. In Rider 19.2.2 it works like it's supposed to.
Thanks in advance.
Chris
Hi Chris,
The best way is to timely update to the latest version if you have such a possibility (not a fall-back licence).
However, you can disable optimising usings even in full cleanup profile. Go to `File | Settings | Editor | Code Cleanup`, clone the Full cleanup profile and then uncheck the `Optimize 'using' directives` section. Use this new profile instead of the default "Full Cleanup". For more information, please follow this article.
Hope this helps!
Thank you.