File tree 3 files changed +34
-1
lines changed
kotlin/com/github/ivy/explicit
3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package com.github.ivy.explicit
3
3
import com.github.ivy.explicit.rule.DataClassDefaultValuesRule
4
4
import com.github.ivy.explicit.rule.DataClassFunctionsRule
5
5
import com.github.ivy.explicit.rule.DataClassTypedIDsRule
6
+ import com.github.ivy.explicit.rule.NoImplicitFunctionReturnTypeRule
6
7
import io.gitlab.arturbosch.detekt.api.Config
7
8
import io.gitlab.arturbosch.detekt.api.RuleSet
8
9
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
@@ -16,7 +17,8 @@ class IvyExplicitRuleSetProvider : RuleSetProvider {
16
17
listOf (
17
18
DataClassFunctionsRule (config),
18
19
DataClassDefaultValuesRule (config),
19
- DataClassTypedIDsRule (config)
20
+ DataClassTypedIDsRule (config),
21
+ NoImplicitFunctionReturnTypeRule (config),
20
22
),
21
23
)
22
24
}
Original file line number Diff line number Diff line change
1
+ package com.github.ivy.explicit.rule
2
+
3
+ import io.gitlab.arturbosch.detekt.api.*
4
+ import org.jetbrains.kotlin.psi.KtNamedFunction
5
+
6
+ class NoImplicitFunctionReturnTypeRule (config : Config ) : Rule(config) {
7
+
8
+ override val issue = Issue (
9
+ " NoImplicitFunctionReturnType" ,
10
+ Severity .Warning ,
11
+ " Functions and class methods should declare their return types explicitly to improve code readability and maintainability." ,
12
+ Debt .FIVE_MINS
13
+ )
14
+
15
+ override fun visitNamedFunction (function : KtNamedFunction ) {
16
+ super .visitNamedFunction(function)
17
+ // Check if the function has an explicit return type
18
+ if (function.typeReference == null && ! function.hasBlockBody() && ! function.isLocal) {
19
+ report(
20
+ CodeSmell (
21
+ issue,
22
+ Entity .from(function),
23
+ " The function '${function.name} ' should declare an explicit return type."
24
+ )
25
+ )
26
+ }
27
+ }
28
+ }
29
+
Original file line number Diff line number Diff line change @@ -5,3 +5,5 @@ IvyExplicit:
5
5
active : true
6
6
DataClassTypedIDs :
7
7
active : true
8
+ NoImplicitFunctionReturnType :
9
+ active : true
You can’t perform that action at this time.
0 commit comments