appKODE / detekt-rules-compose

A collection of Detekt rules for Jetpack Compose
MIT License
136 stars 8 forks source link

Add "UnusedModifierParameter" rule #19

Closed Drjacky closed 1 year ago

Drjacky commented 2 years ago
@ExperimentalAnimationGraphicsApi
@ExperimentalCoilApi
@ExperimentalComposeUiApi
@Composable
fun ProductView(
    product: Product,
    modifier: Modifier = Modifier, //unused
) {
    val ...

    Card(
        modifier = Modifier
            .fillMaxWidth()
dimsuz commented 1 year ago

Usually IDE highlights such cases, but I guess this can be made into a rule too. Detekt has similar rules such as "UnusedImport", so we can follow its lead here :)

BraisGabin commented 1 year ago

I think that UnusedPrivateMember should detect that. And it's provided out of the box by detekt. If it doesn't it seems like a bug in UnusedPrivateMember. I mean, that use case doesn't feels like something special about Compose. Any unused parameter should be flagged.

dimsuz commented 1 year ago

Are you sure? This here is not a private member, but an unused function parameter. Or has UnusedPrivateMember evolved to detect those too? I recall it can do many things :)

BraisGabin commented 1 year ago

The name is clearly missleading. We could open an issue on detekt to rename it. But a function parameter is "private" in the function scope. As I said, missleading name but it should find this kind of issues. If it doesn't we should open an issue to detekt.

dimsuz commented 1 year ago

Hah, indeed this seems like a bug!

Reported it with more details here: https://github.com/detekt/detekt/issues/5373

Closing this issue, because once it will be fixed in detekt you'll be able to use built-in detekt rules for this type of issue.