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
Allow consistent brace formatting checks (OptionalWhenBraces triggered) #5133
Comments
100%. I think that I would remove
What do you think? Opinion: the braces on the |
Heya folks! Is this issue up for grabs? If it is, I'd love to have a go at it, if that's okay. |
Yes it is 👍 I've assigned it to you @segunfamisa |
Quick question: TL;DRI'm wondering if ContextI noticed that per the current implementation the code snippet below is non compliant for
To be clear on what is expected in terms of how the two new rules will work together, does it mean that the implementation will look like:
Or, we could go with the alternative suggestion from @TWiStErRob in #5133 (comment) |
I would like to come back to this, this rule is very inconsistent with when {
AGPVersions.CLASSPATH >= AGPVersions.v70x -> { // OptionalWhenBraces
// AGP 7.4 compatibility: calling onVariants$default somehow changed, being explicit about params helps.
project.androidComponents.onVariants(project.androidComponents.selector().all()) {
if (version.isRenameAPK) // MandatoryBracesIfStatements
renameAPKPost7(it as ApplicationVariant)
}
}
else -> { // OptionalWhenBraces
project.beforeAndroidTasksCreated {
android.applicationVariants.all {
if (version.isRenameAPK) // MandatoryBracesIfStatements
renameAPKPre7(it, it)
}
}
}
} notice that the |
I think they would coexist for one release while deprecation happens, but not sure how rules are deprecated. Re alternative solution, I thought more and
|
I really like this idea! We could create a rule set called braces and add there the rules:
(as far as I know you can't write a And give to each of them those options! ( |
Hello, I'd like to work on the issue if it's available. |
Hi, @VitalyVPinchuk thanks for taking this up. I am super interested in this PR 😍 |
@BraisGabin I would re-open this, there's 3 more rules to write :) |
Sure! It was closed automatically by Github. |
For the record: we've decided to keep the |
Expected Behavior of the rule
In many cases consistency is more important than minimalistic code. So I think it would be beneficial to add a flag (and enable by default) to treat curly braces as allowed (dare I say "mandatory"?). This would elevate all
when
cases to the same level of visibility and structure giving the code more consistency. I'm all for removing all braces, iff all cases in thewhen
let me remove it, but as soon as there's one with complex logic, the others should be treated equally too.Context
Compare these two functions:
and notice how in the first one
TextContent
handling is hidden away because the "braces are optional".The text was updated successfully, but these errors were encountered: