-
Notifications
You must be signed in to change notification settings - Fork 184
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
Improve S3776: Exclude complexity of JSX attribute short-circuits #3289
Closed
gabriel-vivas-sonarsource opened this issue
Aug 1, 2022
· 2 comments
· Fixed by SonarSource/eslint-plugin-sonarjs#377
Closed
Improve S3776: Exclude complexity of JSX attribute short-circuits #3289
gabriel-vivas-sonarsource opened this issue
Aug 1, 2022
· 2 comments
· Fixed by SonarSource/eslint-plugin-sonarjs#377
Comments
we didn't manage to do this in current sprint, removing from milestone |
See some of the comments in #2238 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation
In JSX, it is fairly common to use short-circuit logic for conditionally rendering values. Currently, we count this as Cognitive Complexity.
See example:
See the dogwood thread (internal):
Suggestion
When counting the Cognitive Complexity, we should consider short circuits, nulls coalescing, and optional chaining as shorthand.
Propagating
something && something.prop
something.?prop
Coalescing
something || other
something ?? other
This is true for the following cases at least:
In JSX
Everywhere, not only in JSX
return
statementsPerhaps there are more cases where it makes sense.
Perhaps we don't need to count them in any place?
The text was updated successfully, but these errors were encountered: