- What language is this for? C#
- Which rule? S3240
- Why do you believe it’s a false-positive/false-negative? false-positive
- Are you using
- SonarQube Cloud? No
- SonarQube Server / Community Build - which version? v25.1.0.102122
- SonarQube for IDE - which IDE/version? VS 2022
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud? SonarQube Community Build
While if-else block already contains an interpolated string with conditional operator, there is an invalid suggestion S3240 to use ‘?:’ and if suggestion is applied it reports S3358 violation for ‘Ternary operators should not be nested’
string s1 = string.Empty;
if (condition1) // S3240: Use the '?:' operator here
{
s1 = "some value";
}
else
{
s1 = $"other value {(condition2 ? "suffix1" : "suffix2")}";
}