Version: SonarQube Developer Edition Version 9.3 (build 51899)
Issue: S3240 The simplest possible condition syntax should be used
We have an ASP.NET Core 6 Web Api application, using C# 10.
When an unhandled exception is raised in the application, we have different methods that handle it in Production and in Development. As recommended by Microsoft documentation - in our Program.cs we have the following code:
SonarQube raises an error and requires us to fix it with a ternary operator:
var appBuilder = app.Environment.IsDevelopment() ? app.UseExceptionHandler(“/development-error-action”) : app.UseExceptionHandler(“/production-error-action”);
So I need to introduce the variable appBuilder - which is absolutely not needed.
Generally, I believe this error raised by SonarQube is wrong. Since in this case - I don’t have to assign anything to a variable - I think this error shouldn’t be raised and the if-syntax should be kept.
I saw a similar issue here, but I am not sure it covers our case.
P.S. By the way - when I want to report a False-positive error - should I post here, or directly on the GitHub page?