-
Notifications
You must be signed in to change notification settings - Fork 39
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
Deprecated replaceWith - support in diktat #1343
Comments
Do you mean support it in diktat with autofix? "replaceWith" doesn't mean replacement 1:1 |
No, it actually does the logic in 90% of scenarios. IDEA uses it: https://dev.to/mreichelt/the-hidden-kotlin-gem-you-didn-t-think-you-ll-love-deprecations-with-replacewith-3blo |
If we will support it as autofix logic -- we will produce irrelevant code in 10% of scenarios. |
How IDEA filters out false positives? |
Yep, looks like I didn't get properly Make the following example (inspired by
data class ParamsOld(
val arg1: String,
val arg2: String,
)
@Deprecated(
message = "extended params",
replaceWith = ReplaceWith("this.doLogicNew(ParamsNew(params.arg1, params.arg2, arg3))", imports = ["ParamsNew"])
)
fun doLogicOld(params: ParamsOld, arg3: String) {
println("${params.arg1} -> ${params.arg2} -> ${arg3}")
}
data class ParamsNew(
val arg1: String,
val arg2: String,
val arg3: String,
)
fun doLogicNew(params: ParamsNew) {
println("${params.arg1} -> ${params.arg2} -> ${params.arg3}")
} Usage: fun test() {
doLogicOld(ParamsOld("1", "2"), "3")
} IDEA transforms it to (problem with whitespaces on new line) fun test() {
val params = ParamsOld("1", "2")
doLogicNew(ParamsNew(params.arg1, params.arg2, "3"))
}
IDEA transforms it to (funny, but it doesn't have problem with whitespaces on new line) fun test() {
val params = ParamsOld("1", "2")
this.doLogicInvalid(ParamsNew(params.arg1, params.arg2, "3"))
} |
In response to the previous comment:
Exactly. And if my memory fails me not, there's an equivalent quickfix action in IDEA itself. Additionally, a user can always switch a particular DiKTat inspection off is they desire so. |
Kotlin has outstanding logic (deprecation scenarios) - library author can help user to fix the code.
Probably in the future, when we will have all information about the project (and new framework)
The text was updated successfully, but these errors were encountered: