Add code fixes for C# issues that have an easy fix

I know it is not your main focus, but as Roslyn allows to provides CodeFixProvider that can fix issues in a blink of an eye, it would be nice if you could provide more code fixers than you currently do.

To help out, I implemented one, which turned out to have a lot of issues on repo at my company:

Hey @Corniel, interesting idea, I will relay this to the team in case they’re interested.

A quick comment on this:

I know it is not your main focus

It actually is becoming more and more our focus to provide fixes! We have a few features, namely AI CodeFix and Remediation Agent aimed at this. These are AI-powered, and I understand that CodeFixProvider is different, it gives hardcoded fixes in the IDE, so it might still be interesting to consider it. But just wanted to comment on that statement :grin:

The thing is that hard code fixes are way more efficient to execute, so when there is a straight forward fix, having an old-fashioned one is just better. It also helps the AI to fix code for you. :wink:

@andres Can you please ask some human colleague of you too also have a look? Now to bots desired to close the PR, while I was waiting on actual feedback. (No human likes a “The computer says no”)

Hey @Corniel, sorry for the bad experience you’re having with the PR, I saw that the Gitar bot is not really replying to you and that our cleanup bot closed it… :face_with_spiral_eyes:

The current state of this request is that we’re waiting for a PM to consider if this idea to implement IDE fixes is something we want to adopt or not. It’s kind of a new feature so it’s not just a technical matter. I can’t promise when will they look into it.

Regarding the PR, most likely it would have to be cherry picked into a branch created by one of our devs, because we need the CI to run and the CI doesn’t run on branches created by external contributors. I recommend that you let the bot close it if it wants to close it, and if we end up accepting this, our devs will recreate it. In case you eventually delete your forked repo, maybe what you can do is attach a git patch file here, for extra persistence.

AI does not only bring joy. :slight_smile: @Pavel_Mikula was so friendly to re-open it. I’ll try to be patient now.

One small detail worth considering with the S6608 fix: array.First() and array[0] don’t behave exactly the same on an empty array.

The first throws InvalidOperationException, while the second throws IndexOutOfRangeException.

Probably not a big deal for most code, but it does mean the fix isn’t completely behavior-preserving. It could matter if something explicitly catches one of those exceptions.

I’d still prefer a simple Roslyn fix over involving AI for this kind of change. Just wondering whether that difference should be mentioned in the fix description, especially if bulk fixes are supported.

It is the whole point of the rule: Prefer list[0] and list[^1] of First() and Last(). You don’t expect an exception, otherwise you would use FirstOrDefault(), so the feedback is just wrong. Let me be clear, In general I’m extremely impressed by Gitar, and I actually don’t get why it so wrong here.