Hi!
CodeRush and Refactor have the habit to remove the {} braces (e.g. when refactoring code),
if they are not necessary (only one statement).
But we have a coding policy to always use {} - so, is possible to configure this behaviour?
I posted in the forums
http://community.devexpress.com/forums/p/54296/183072.aspx
regarding this feature one year ago, and now I thought it would be a good idea to create an issue, so that I can track progress.
Frank
We have closed this ticket because another page addresses its subject:
CodeGen - Add options to specify code generation rules
Hi Frank,
The current product version doesn't allow you to change this behavior, sorry. However, we're planning to add support for this functionality in the future. Please track the following suggestion:
ID: S19229, CodeGen - Add options to specify code generation rules
Thanks,
Vito
Hi,
is this feature implemented in 11.1.6? There is a vast amount of options for
code formatting, but I did not find an option for this particular feature.
Frank
Hi Frank,
All our refactorings use a common mechanism of generating code. In the 11.1 release, we improved this mechanism and now it considers additional details of existing code (braces, white spaces, comments, preprocessor directives, etc.).
Thus, all refactorings should save your code as-is when they modify or replace it.
Please let me know if any refactoring removes {} braces or do other unnecessary actions.
Thanks,
Alex K
Hi Alex,
after reading your answer I realized that I used a code-provider and not a refactoring
to test this feature.
So, you are right: a refactoring on an "if"-statement preserves the {},
but if I invoke the "Add else statement" code-provider, the braces are removed from the "if" block".
Thanks
Frank
Code providers should save the details of your code too.
The issue with "Add else statement" is a bug and we have taken the liberty of creating a new issue on your behalf.
Refactoring - The "Add Else Statement" refactoring removes curly braces from if statements
Please refer to that ticket for further correspondence on this item.
Thanks,
Alex K
Hi,
i just noticed that the "flatten conditional" refactoring does not generate curly braces
for the "return"-statement.
Is there a setting in 11.2.5 to force the curly braces?
Regards
Frank
Hi Frank,
The Code Formatting feature can't add new tokens (in this case curly braces) in the text. Therefore, adding this option is impossible.
You can use the 'Force braces in "if…else" statement' rule of the Code Cleanup feature. This feature can be executed from 'DXCore Visualize' toolbar. You can learn more about it here: Code Cleanup.
Thanks,
Alex K