New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix S3358 FP: Nested ternary operator is in a lambda #5774
Fix S3358 FP: Nested ternary operator is in a lambda #5774
Conversation
As mentioned at the Community Platform, I think this is not a false positive; it's about readability, and that does not change by having lamda's or not. |
The ITs found the following FPs // 1.
var configWithDefaultFallback = bootstrap.HasValue
? bootstrap.Value.Config.Select(c => c == _defaultConfig ? c : c.WithFallback(_defaultConfig))
: _defaultConfig;
// 2.
var messages = (SupportsAtomicPersistAllOfSeveralEvents
? Enumerable.Range(from, to - 1)
.Select(
i =>
i == to - 1
? new AtomicWrite(
new[] {persistent(i), persistent(i + 1)}.ToImmutableList<IPersistentRepresentation>())
: new AtomicWrite(persistent(i)))
: Enumerable.Range(from, to).Select(i => new AtomicWrite(persistent(i))))
.ToArray();
// 3.
return empty != null
? new object[0]
: ctors.First().GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
"id": "S3358", | ||
"message": "Extract this nested ternary operation into an independent statement.", | ||
"location": { | ||
"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner\Discovery.cs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
@@ -24,6 +24,14 @@ public bool FooImpl(bool isMale, bool isMarried) | |||
? "Mrs. " | |||
: "Miss "; | |||
|
|||
var lambda1 = true // Compliant. Nested in Lambda is valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add noncompliant
var lambda3 = new Func<string, string>(s => isMale ? "Mr. " : isMarried ? "Mrs. " : "Miss ")
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
@andrei-epure-sonarsource I checked this on peach and found one nonreproducible issue (see above). Can we have a look together? |
Fixes #5773
Todo