Hi
I'm having issues with the new Formatting > Spacing options - as it is messing up some of my code now. I've gone through and identified which options:
NOTE - I believe some of the reasons is because I use TABS and not spaces - it seems to put spaces in the code instead of tabs.
Code as it should be:
C#public static string GetHashSha256(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
var hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
return GetStringFromHash(hash);
}
Issue #1
Option ticked>>> C#>Formatting>Spacing> "Statement" - this turned on, but no sub options ticked produces this code:
C# public static string GetHashSha256(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
var hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
return GetStringFromHash(hash);
}
Notice the bottom 4 lines are all to the left - and have SPACES in front of them, though the correct number of spaces, strange how the first 3 lines are not.
Issue #2
Option ticked>>> C#>Formatting>Spacing> "Parameters" - this turned on, but only default sub options ticked produces this code:
C#public static string GetHashSha256(string text){
byte[] bytes = Encoding.UTF8.GetBytes(text);
var hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
return GetStringFromHash(hash);
}
Notice the opening curly brace is now on the same line as the method - I like to have mine on the line below and the formatting is changing this and ignoring my VS setting.
That's it for now - it's only tested on a small cs file I've looked at, but will report any others I spot!
Disabling the two options "Statements, Parameters" solves it for now.
Thanks
Hi Alan,
You are right that the issue is related to using Tabs instead of Spaces. I have reproduced the issue and we are working on it.
Hi Alex,
I've just spotted a 3rd one that isn't formatting correctly - again think it's because I use TABs and not spaces.
This time it's w ith the "Attributes" section - when turned off all is ok, but when ticked.
BEFORE;
namespace Test { internal static class Program { [STAThread] private static void Main() {
AFTER:
namespace Test { internal static class Program { [STAThread] private static void Main() {
Notice the attribute and the Main Method are only in 2 spaces and not 2 tabs.
Cheers.
Hi Alan,
Thank you for the update and providing one more code snippet.
Yes, we also tend to think that the problem relates to using TABs and will make sure to verify this case as well once we prepare a fix.
Great work again guys, thanks for fixing it so quick - I've requested a HF so will test it again for you.
Thank you, Alan.
We appreciate your willing to help us make CRR better. I uploaded the hotfix in the ticket and we will be happy to hear your feedback!
Hi Alex,
I've installed and HF and the above 3 issues have been fixed… BUT a NEW one has been introduced.
It's on the Formatting>Spacing>Statement option – when this is turned ON the below issue happens… The comment line in the code below is duplicated each time the code cleanup button is pressed. So before it has one line, then after 3 presses it looks like the after section:
NOTE - this happens if i have either Spaces or Tabs selected for indenting.
BEFORE:
public static string GetHashSha256(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); var hashstring = new SHA256Managed(); // a comment byte[] hash = hashstring.ComputeHash(bytes); return GetStringFromHash(hash); }
AFTER 3 cleanup clicks:
public static string GetHashSha256(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); var hashstring = new SHA256Managed(); // a comment // a comment // a comment // a comment // a comment // a comment // a comment // a comment byte[] hash = hashstring.ComputeHash(bytes); return GetStringFromHash(hash); }
This is only 3 clicks on the code cleanup button I have in the tool bar (I have to always click it 3 times to do a full clean up of the file.
For now, I have to leave the "Statement" option unchecked due to this.
Alan,
Thank you for testing the hotfix and providing your feedback!
I've created a separate ticket on your behalf (Formatting - Comments are duplicated when spacing options are used). It has been placed in our processing queue and will be answered shortly.