Misadventures in Automatic Code Formatting

Part two of my Godot journey, as I try to code a simple game in Godot/C# to reskill.

Disclaimer: I’ve been a Linux user for 11 months. I’ve been a Godot user for a total of about 10 hours. It’s been many years since I even touched C#, and I was never particularly good at it. I am barely a programmer. I am tired. I am fucking angry. So, please interpret everything that follows accordingly.

Whichever idiot decided it would be a good idea to automatically "simplify“ clear, easy-to-read if-elseif-else statements to dense, opaque, ternary operations can go to hell. Here’s a code snippet:

if (!game_started)
{
ScoreLabel.Text = "Press any direction to play!";
}
else if (score == 0)
{
ScoreLabel.Text = "Good luck!";
}
else if (score == 1)
{
ScoreLabel.Text = "1 point";
}
else
{
ScoreLabel.Text = score.ToString() + " points";
}

My code isn’t going to win any awards, but it’s nice and legible. I ignored the “quick fix” offered that this code could be “simplified”, and I saved it. Imagine my frustration when, despite my instruction, it was automatically “simplified” to:

if (!game_started)
{
ScoreLabel.Text = "Press any direction to play!";
}
else if (score == 0)
{
ScoreLabel.Text = "Good luck!";
}
else
{
ScoreLabel.Text = (score == 1) ? "1 point" : score.ToString() + " points";
}

I hit Ctrl+Z to undo it, and saved... it helpfully did it again.

But, dear reader, it gets worse.

I hit Ctrl+S again. And my code was again ”simplified” to:

if (!game_started)
{
ScoreLabel.Text = "Press any direction to play!";
}
else
{
ScoreLabel.Text = (score == 0) ? "Good luck!" : (score == 1) ? "1 point" : score.ToString() + " points";
}

We’re not done.

My frustration gave way to curiosity. I hit Ctrl+S a thrid time. Would it complete the set, removing my structured if statement altogether and replace it with a single, dense, ”simplified” line of code?

...no. No, that would make sense. It went in a different direction.

if (!game_started)
{
ScoreLabel.Text = "Press any direction to play!";
}
else
{
if (score == 0)
{
ScoreLabel.Text = "Good luck!";
}
else
{
ScoreLabel.Text = (score == 1) ? "1 point" : score.ToString() + " points";
}
}

Every time I saved from then on, it would alternate between the last two. Simplifying it. Realising its mistake and making it more legible. Simplifying it again.

And it was seemingly oblivious to the existence of “else if”.

So what was the culprit?

I’ve now solved the problem by uninstalling all my extensions, erasing ~/.config/VSCodium and ~/.omnisharp (just to be thorough) and reinstalling just the three essential extensions.

It doesn’t do that crap any more.

I suspect the culprit was Roslynator. But I don’t know for sure, and I don’t wish to contaminate my install by finding out - because, as part of my debugging process, I disabled all my addons except the essential three and it was still doing it. Somewhere, buried deep in opaque config files, was an option I couldn’t find that told it to fuck with my code. If the option is never set, the problem will never happen.

And I’ve backed up my config files this time.