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
gabriel-vivas-sonarsource
changed the title
S3776 should not include the complexity of enclosed function definitions
S3776 should exclude the complexity of JSX attribute short-circuits and nested function definitions
Aug 1, 2022
we didn't manage to do this in current sprint, removing from milestone |
See some of the comments in #2238 |
vilchik-elena
changed the title
S3776 should exclude the complexity of JSX attribute short-circuits and nested function definitions
Improve S3776: exclude complexity of JSX attribute short-circuits and nested function definitions
Oct 18, 2022
vilchik-elena
changed the title
Improve S3776: exclude complexity of JSX attribute short-circuits and nested function definitions
Improve S3776: Exclude complexity of JSX attribute short-circuits and nested function definitions
Oct 18, 2022
vilchik-elena
changed the title
Improve S3776: Exclude complexity of JSX attribute short-circuits and nested function definitions
Improve S3776: Exclude complexity of JSX attribute short-circuits
Oct 27, 2022
gabriel-vivas-sonarsource
added
mmf-2854
https://sonarsource.atlassian.net/browse/MMF-2854
and removed
mmf-2835
labels
Nov 28, 2022
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: