detekt/detekt

New rule: UnnecesaryOptInAnnotation

开放

#5,889 创建于 2023年3月9日

 (5 条评论) (3 个反应) (0 位负责人)Kotlin (834 个派生)batch import
help wantedrules

仓库指标

星标
 (6,942 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Kotlin has an Opt-in mechanism to make sure that the users know that they are using a not stable API. They used on their Standard library and it's used by third parties too (even detekt uses it):

https://github.com/detekt/detekt/blob/4a89a25c82d35874571270fa1ff32751f2f268a1/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/UnstableApi.kt#L3-L7

This is a great mechanism but when an API go from unstable to stable a lot of @OptIn annotations are left back on the code. Also this happen when later you refactor the code and remove the usage of that unstable api.

My proposal is to implement a rule to check for this cases so we don't have any unused @OptIn annotation in the code.

I see warnings on IntelliJ so maybe we could port it.

It would be great to also raise usages of propagating opt-in but I'm not sure if we could find those cases.

贡献者指南