Mustafa Ozhan
10/20/2023, 1:18 PMKonsist
.scopeFromProject()
.functions()
.assert { it.hasReturnType }
in a way that it will fail if a method return type is not specified but it can still pass in case the method is returning nothing
so
fun test1() { /* something */ }
should pass
while
fun test2() = 5
should fail because test2 should specify the return type as Int
is there any idea how we can check this with Konsist ?PoisonedYouth
10/20/2023, 1:53 PMMustafa Ozhan
10/21/2023, 8:38 AMPoisonedYouth
10/21/2023, 8:46 AMigor.wojda
10/22/2023, 11:55 PM=
character including lambdas and then tings become quite complex. We will not be able to make it perfect without adding K2 Compiller
support (to be investigated). However we will be able to match detekt check and most likely make it a bit better as Konsist has context of entire code base, nit just a single file. Thats' being said I made a note and we already have a ticket to improve this behaviour.
https://lemonappdev.atlassian.net/browse/KON-522
At the end of the day Konsist is parsing Kotlin code in form of text, so the idea is to give API for what you see in a "Kotlin text file" (and a bit of things that we can deduct).
BTW You can consider using hasBlockBody()
& hasExpressionBody
methods to improve your check. The expression body in most cases means that function has the return type, however you can also write such code fun test2() = println(5)
, so this will not be perfect.
Thx for the feedbackPoisonedYouth
10/23/2023, 5:49 AMAt the end of the day Konsist is parsing Kotlin code in form of text
. That is the difference between Konsist and detekt. Konsist can use everything that is available in the text representation of a Kotlin file but intepretation is something different.igor.wojda
10/23/2023, 8:51 AMfun test3() = { anything can happen here }
fun test4() = Foo()
.doSomething()
.also { }
igor.wojda
10/23/2023, 8:53 AMMustafa Ozhan
10/23/2023, 10:23 AMBTW You can consider using&hasBlockBody()
methods to improve your check.hasExpressionBody
PoisonedYouth
10/23/2023, 4:59 PMigor.wojda
10/24/2023, 2:01 PM