SonarLint for IntelliJ - Quick Fixes

If I understand correctly there are no Quick Fixes in SonarLint for IntelliJ (e.g. SonarLint quickfix), I’d be delighted to be wrong though :slight_smile:

Anyway, what I am looking for is a way to fix “simple” issues like java:S2209 (“static” members should be accessed statically) from SonarLint/IntelliJ with a simple “Quick Fix”, ideally as batch should it occur in more than one place.

Hi,

SonarLint quick fixes are only available for a few C# rules in Visual Studio.

This is a very debatable topic, because quick fixes are only useful when we are 100% sure to not break the code (especially if used in batch mode). In many cases, it is required for a human to have a close look. Example: rule detecting duplicate conditions:

if (a) {
  if (a) {
    // some code
  }
}

Of course we could suggest as a quick fix to remove the unnecessary nested condition. But removing a line is usually doable with a simple shortcut in an IDE, and this code smell could in fact hide a serious bug. Maybe the nested condition is a bad copy paste, and should be modified.

If you take the example of rule java:S2209, a quick fix is already suggested by IntelliJ (and Eclipse BTW):



so I don’t think we would add a lot of value here.

I have not tested, but I’m pretty sure there is a batch mode.

Summary: we are not against quick fixes, we are just lacking good candidates :wink:

Hi Julien,

thanks for the reply.

Indeed, any refactoring that goes beyond adding @SuppressWarning has it’s own risk attached. Which is by the way one good use case of applying a quick fix - no need to cut/copy/past squids around for @SuppressWarning would actually help me for certain squids where I can accept the risk of ignoring the code smell for the sake of “cleaning” my SQ reports.

We have an initiative to clarify our position regarding in code issues suppression. Once our position is clear, and assuming it goes in favor of in code annotations/markers/comments to suppress issues, having a quick fix to automatically add one is indeed a good idea.