website/versioned_docs/version-2.0.0-alpha.0/rules/naming.md
The naming ruleset contains rules which assert the naming of different parts of the codebase.
Reports boolean property names that do not follow the specified naming convention.
Active by default: No
Requires Type Resolution
allowedPattern (default: '^(is|has|are)')
naming pattern
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
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
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
Reports enum names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
Aliases: EnumEntryName
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.
This can be used to prevent the use of overly generic class names like *Manager or names shadowing common
types like LocalDate.
Active by default: No
forbiddenName (default: [])
List of glob patterns to be disallowed as class names
Reports when very long function names are used.
Active by default: No
Aliases: FunctionMaxNameLength
maximumFunctionNameLength (default: 30)
maximum name length
Reports when very short function names are used.
Active by default: No
Aliases: FunctionMinNameLength
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
Aliases: FunctionName
functionPattern (default: '[a-z][a-zA-Z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores functions in classes which match this regex
Reports function parameter names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
parameterPattern (default: '[a-z][A-Za-z0-9]*')
naming pattern
excludeClassPattern (default: '$^')
ignores variables in classes which match this regex
Reports when the file location does not match the declared package.
Active by default: Yes - Since v1.21.0
Aliases: PackageDirectoryMismatch
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
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
mustBeFirst (default: true)
name should only be checked if the file starts with a class or object
multiplatformTargets (default: ['ios', 'android', 'js', 'jvm', 'native', 'iosArm64', 'iosX64', 'macosX64', 'mingwX64', 'linuxX64'])
kotlin multiplatform targets, used to allow file names like MyClass.jvm.kt
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 name 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
Requires Type Resolution
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
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 chapter 8.3.2 on the Java Language Specification
Active by default: No
Requires Type Resolution
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
Aliases: ObjectPropertyName
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
Aliases: PackageName
packagePattern (default: '[a-z]+(\.[a-z][A-Za-z0-9]*)*')
naming pattern
Reports top level property names that do not follow the specified naming convention.
Active by default: Yes - Since v1.0.0
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
maximumVariableNameLength (default: 64)
maximum name length
Reports when very short variable names are used.
Active by default: No
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
Aliases: PropertyName
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