website/versioned_docs/version-1.22.0/rules/naming.md
The naming ruleset contains rules which assert the naming of different parts of the codebase.
Reports when a boolean property doesn't match a pattern
Active by default: No
Requires Type Resolution
Debt: 5min
allowedPattern (default: '^(is|has|are)')
naming pattern
ignoreOverridden (default: true)
ignores properties that have the override modifier
val progressBar: Boolean = true
val hasProgressBar: Boolean = true
Reports class or object names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
Aliases: ClassName
classPattern (default: '[A-Z][a-zA-Z0-9]*')
naming pattern
Reports constructor parameter names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
parameterPattern (default: '[a-z][A-Za-z0-9]*')
naming pattern
privateParameterPattern (default: '[a-z][A-Za-z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores variables in classes which match this regex
ignoreOverridden (default: true)
ignores constructor properties that have the override modifier
Reports enum names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
enumEntryPattern (default: '[A-Z][_a-zA-Z0-9]*')
naming pattern
Reports class names which are forbidden per configuration. By default, this rule does not report any classes.
Examples for forbidden names might be too generic class names like ...Manager.
Active by default: No
Debt: 5min
forbiddenName (default: [])
forbidden class names
Reports when very long function names are used.
Active by default: No
Debt: 5min
maximumFunctionNameLength (default: 30)
maximum name length
Reports when very short function names are used.
Active by default: No
Debt: 5min
minimumFunctionNameLength (default: 3)
minimum name length
Reports function names that do not follow the specified naming convention. One exception are factory functions used to create instances of classes. These factory functions can have the same name as the class being created.
Active by default: Yes - Since v1.0.0
Debt: 5min
Aliases: FunctionName
functionPattern (default: '[a-z][a-zA-Z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores functions in classes which match this regex
ignoreOverridden (default: true)
ignores functions that have the override modifier
Reports function parameter names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
parameterPattern (default: '[a-z][A-Za-z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores variables in classes which match this regex
(default: ignoreOverriddenFunctionstrue)
Deprecated: Use ignoreOverridden instead
ignores overridden functions with parameters not matching the pattern
ignoreOverridden (default: true)
ignores overridden functions with parameters not matching the pattern
Reports when the file location does not match the declared package.
Active by default: Yes - Since v1.21.0
Debt: 5min
rootPackage (default: '')
if specified this part of the package structure is ignored
requireRootInDeclaration (default: false)
requires the declaration to start with the specified rootPackage
Reports lambda parameter names that do not follow the specified naming convention.
Active by default: No
Debt: 5min
parameterPattern (default: '[a-z][A-Za-z0-9]*|_')
naming pattern
"If a Kotlin file contains a single non-private class (potentially with related top-level declarations), its name should be the same as the name of the class, with the .kt extension appended. If a file contains multiple classes, or only top-level declarations, choose a name describing what the file contains, and name the file accordingly. Use camel humps with an uppercase first letter (e.g. ProcessDeclarations.kt).
The name of the file should describe what the code in the file does. Therefore, you should avoid using meaningless words such as "Util" in file names." - Official Kotlin Style Guide
More information at: https://kotlinlang.org/docs/coding-conventions.html
Active by default: Yes - Since v1.0.0
Debt: 5min
mustBeFirst (default: true)
name should only be checked if the file starts with a class or object
class Foo // FooUtils.kt
fun Bar.toFoo(): Foo = ...
fun Foo.toBar(): Bar = ...
class Foo { // Foo.kt
fun stuff() = 42
}
fun Bar.toFoo(): Foo = ...
This rule reports a member that has the same as the containing class or object. This might result in confusion. The member should either be renamed or changed to a constructor. Factory functions that create an instance of the class are exempt from this rule.
Active by default: Yes - Since v1.2.0
Debt: 5min
(default: ignoreOverriddenFunctiontrue)
Deprecated: Use ignoreOverridden instead
if overridden functions and properties should be ignored
ignoreOverridden (default: true)
if overridden functions and properties should be ignored
class MethodNameEqualsClassName {
fun methodNameEqualsClassName() { }
}
class PropertyNameEqualsClassName {
val propertyEqualsClassName = 0
}
class Manager {
companion object {
// factory functions can have the same name as the class
fun manager(): Manager {
return Manager()
}
}
}
Disallows shadowing variable declarations. Shadowing makes it impossible to access a variable with the same name in the scope.
Active by default: Yes - Since v1.21.0
Requires Type Resolution
Debt: 5min
fun test(i: Int, j: Int, k: Int) {
val i = 1
val (j, _) = 1 to 2
listOf(1).map { k -> println(k) }
listOf(1).forEach {
listOf(2).forEach {
}
}
}
fun test(i: Int, j: Int, k: Int) {
val x = 1
val (y, _) = 1 to 2
listOf(1).map { z -> println(z) }
listOf(1).forEach {
listOf(2).forEach { x ->
}
}
}
Reports when property with 'is' prefix doesn't have a boolean type. Please check the chapter 8.3.2 at Java Language Specification
Active by default: No
Requires Type Resolution
Debt: 5min
val isEnabled: Int = 500
val isEnabled: Boolean = false
Reports property names inside objects that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
constantPattern (default: '[A-Za-z][_A-Za-z0-9]*')
naming pattern
propertyPattern (default: '[A-Za-z][_A-Za-z0-9]*')
naming pattern
privatePropertyPattern (default: '(_)?[A-Za-z][_A-Za-z0-9]*')
naming pattern
Reports package names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
Aliases: PackageDirectoryMismatch
packagePattern (default: '[a-z]+(\.[a-z][A-Za-z0-9]*)*')
naming pattern
Reports top level constant that which do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
constantPattern (default: '[A-Z][_A-Z0-9]*')
naming pattern
propertyPattern (default: '[A-Za-z][_A-Za-z0-9]*')
naming pattern
privatePropertyPattern (default: '_?[A-Za-z][_A-Za-z0-9]*')
naming pattern
Reports when very long variable names are used.
Active by default: No
Debt: 5min
maximumVariableNameLength (default: 64)
maximum name length
Reports when very short variable names are used.
Active by default: No
Debt: 5min
minimumVariableNameLength (default: 1)
minimum name length
Reports variable names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Debt: 5min
variablePattern (default: '[a-z][A-Za-z0-9]*')
naming pattern
privateVariablePattern (default: '(_)?[a-z][A-Za-z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores variables in classes which match this regex
ignoreOverridden (default: true)
ignores member properties that have the override modifier