detekt/detekt

Allow only Destructuring declaration for some classes

オープン

#3,257 opened on 2020/11/29

 (4 件のコメント) (2 件のリアクション) (0 人の担当者)Kotlin (834 件のフォーク)batch import
help wantedrules

Repository metrics

Stars
 (6,942 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Expected Behavior of the rule

This rule will only allow the use of Destructuring declaration for some clases as Pair, Triple or Entry. It should be configurable because it have sense to allow things like Point or Color to use destructuring declaration. Any other use of Destructuring declaration should be marked as an error.

Probably we should add other flag to allow destructuring any private class to. It's kind of common pattern that, if you want a function to return two values you create a private class to return it and receive the value in a destructuring way. And use destructuring declarations in private classes is kind of safe because if you change the number of parameters or it's order the only affected code is in the same file

Context

This issue is related with #3256 but not the same.

The destructing declarations are dangerous because they depend on the position of the parameters. Adding a new parameter can blow up all your code in a non obvious way. So it's safer to only allow the use of it in the classes that have a defined order in their properties.

コントリビューターガイド