Repository with additional rules for detekt static analysis tool. Visit the main detekt repository for details.
- Download the pre-compiled library jar artifact
- Move the artifact to a convenient place to use (for example, the project folder)
- Add the rule set properties to detekt configuration file (yml)
- Specify the artifact as detekt plugin
AleksanderShRuleSet:
SpecifyFunctionExplicitReturnType:
active: true
SpecifyPropertyExplicitReturnType:
active: true
AvoidFunctionTupleReturnType:
active: true
AvoidPropertyTupleReturnType:
active: true
detekt-cli" --plugins "aleksandersh-detekt-ruleset-0.1.0.jar"
TBD
detekt-cli" --jvm-target 11 --classpath "lib/kotlin-stdlib-1.5.21.jar"
In most cases, functions or properties without an explicit type are harder to understand, and in some cases due to an implicit contract, it can lead to errors. Rule checks whether the type of function/property return value is explicitly specified.
Noncompliant Code
fun getProperties() = delegate.getProperties()
Compliant Code
fun getProperties(): Map<String, String> = delegate.getProperties()
Parameters
checkPublic
(default: true)checkInternal
(default: true)checkProtected
(default: false)checkPrivate
(default: false)
Unit-tests
It is more difficult to understand the return values if they are composed in a tuple, prefer to use custom classes instead.
Noncompliant Code
fun getUser(): Pair<String, String> = createUser()
Compliant Code
class User(val name: String, val email: String)
fun getUser(): User = createUser()
Parameters
checkPublic
(default: true)checkInternal
(default: true)checkProtected
(default: false)checkPrivate
(default: false)
Unit-tests
checkPublic
- apply rule for public declarationscheckInternal
- apply rule for internal declarationscheckProtected
- apply rule for protected declarationscheckPrivate
- apply rule for private declarations
The visibility of a declaration is based on its modifier and the modifier of the class/object in which it is found. A common case is disabling the rule for private or protected declaration.