Skip to content
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

UnnecessaryParentheses where IDE prompts for clarifying parentheses. #4495

Closed
eygraber opened this issue Jan 17, 2022 · 8 comments · Fixed by #5983
Closed

UnnecessaryParentheses where IDE prompts for clarifying parentheses. #4495

eygraber opened this issue Jan 17, 2022 · 8 comments · Fixed by #5983

Comments

@eygraber
Copy link
Contributor

The following code triggers a warning in the IDE, saying Expression should use clarifying parentheses:

val (adjustedFromItem, fromFragment) =
      validPages
        .firstOrNull { (from, frag) -> from != page && frag.isVisible }
        ?: null to null

It wants to correct it to:

val (adjustedFromItem, fromFragment) =
      validPages
        .firstOrNull { (from, frag) -> from != page && frag.isVisible }
        ?: (null to null)

But detekt flags it as UnnecessaryParentheses. I see the value of adding parentheses here, and a few other places that the IDE is suggesting it, but I don't want to have to suppress the detekt check in all of those places.

Can detekt use similar logic to exclude these cases?

@BraisGabin
Copy link
Member

We should look at the rule that is warning this in IJ and see if we can integrate it in this rule.

@cortinico
Copy link
Member

The following code triggers a warning in the IDE

Can we confirm that is a IDE warning and not a compiler warning? A compiler warning would be way easier to integrate if so.

@eygraber
Copy link
Contributor Author

eygraber commented May 1, 2022

https://youtrack.jetbrains.com/issue/KTIJ-8888

@dimsuz
Copy link
Contributor

dimsuz commented Oct 17, 2022

It seems like this has been fixed by #4881 ?

At least I found the corresponding test case here.

@BraisGabin
Copy link
Member

Yes, these one was fixed. Closing.

@eygraber
Copy link
Contributor Author

@BraisGabin I found two occurrences where the IDE tells me to add clarifying parentheses, but after I do, detekt says it is a UnnecessaryParentheses violation. Here they are after adding the clarifying parentheses:

string("id") to (floatOrNull("progress") ?: (index.toFloat() / (segments.size - 1)))

and

progress = segmentJson.floatOrNull("progress") ?: (index.toFloat() / (segmentArray.size - 1)),

@BraisGabin BraisGabin reopened this Jan 12, 2023
@BraisGabin
Copy link
Member

I was thinking that maybe #5684 would fix it. But after checking a bit more it doesn't seem so.

@atulgpt
Copy link
Contributor

atulgpt commented Apr 11, 2023

Hi @BraisGabin / @eygraber I have added the fix at #5983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants