facebook pixelKotlin Static Analysis Rules
BACK TO LIST

Kotlin rules

Codiga provides multiple set of rules for 12+ languages. Below we provide a link and a description for all the rules supported by our platform. Note that not all the rules are being listed and described below.

detekt.ArrayPrimitive

Error prone
Minor

Using Array<Primitive> leads to implicit boxing and a performance hit

detekt.ClassNaming

Error prone
Minor

Class and Object names should match the pattern: [A-Z][a-zA-Z0-9]*

detekt.ComplexCondition

Error prone
High

Condition is too complex

detekt.ComplexMethod

Error prone
Minor

Function too complex.

detekt.ConstructorParameterNaming

Error prone
Minor

Constructor private parameter names should match the pattern: [a-z][A-Za-z0-9]*

detekt.DuplicateCaseInWhenExpression

Error prone
Minor

When expression has multiple case statements for the same value

detekt.EmptyCatchBlock

Error prone
Minor

Empty catch block detected. If the exception can be safely ignored

detekt.EmptyClassBlock

Error prone
Minor

The class or object Attempts is empty.

detekt.EmptyDefaultConstructor

Error prone
Minor

An empty default constructor can be removed.

detekt.EmptyKtFile

Error prone
Minor

Detect empty files

detekt.EmptyWhenBlock

Error prone
Minor

This when block is empty.

detekt.EmptyWhileBlock

Design
Minor

This empty block of code can be removed.

detekt.EnumNaming

Error prone
Minor

Enum entry names should match the pattern: [A-Z][\_a-zA-Z0-9]*

detekt.ExplicitGarbageCollectionCall

Performance
Critical

An explicit call to the Garbage Collector as in System should not be made.

detekt.ForbiddenComment

Code style
Minor

This comment contains text that has been defined as forbidden in detekt.

detekt.ForEachOnRange

Error prone
Minor

Using the forEach method on ranges has a heavy performance cost. Prefer using simple for loops.

detekt.FunctionNaming

Error prone
Minor

Function names should match the pattern: ([a-z][a-zA-Z0-9]*)|(`.*`)

detekt.FunctionOnlyReturningConstant

Design
Medium

Function is returning a constant. Prefer declaring a constant instead.

detekt.FunctionParameterNaming

Error prone
Minor

Function parameter names should match the pattern: [a-z][A-Za-z0-9]*

detekt.IteratorNotThrowingNoSuchElementException

Error prone
Minor

This implementation of Iterator does not correctly implement the next() method as it doesn't throw a NoSuchElementException when no elements remain in the Iterator.

detekt.LargeClass

Design
High

Detect classes that are too large

detekt.LongMethod

Design
Medium

Function is too long

detekt.LongParameterList

Design
Medium

Too many parameters

detekt.LoopWithTooManyJumpStatements

Error prone
Medium

Too many jump statements

detekt.MagicNumber

Error prone
Medium

Replace magic numbers with a constant

detekt.MatchingDeclarationName

Error prone
Minor

The file name 'does not match the name of the single top-level declaration

detekt.MaxLineLength

Design
Medium

Line is too long

detekt.MayBeConst

Design
High

Refactor into a const

detekt.MemberNameEqualsClassName

Best practice
Medium

Name confusion

detekt.ModifierOrder

Error prone
Minor

Incorrect modifier order

detekt.NestedBlockDepth

Best practice
Medium

Function nested too deeply.

detekt.ObjectPropertyNaming

Error prone
Minor

Object constant names should match the pattern: [A-Za-z][\_A-Za-z0-9]*

detekt.OptionalAbstractKeyword

Error prone
Minor

The abstract keyword on this declaration is unnecessary.

detekt.PackageNaming

Error prone
Medium

Package name should match the pattern: [a-z]+(\\.[a-z][A-Za-z0-9]*)*

detekt.ProtectedMemberInFinalClass

Error prone
Minor

Member with protected visibility in final class is private. Consider using private or internal as modifier.

detekt.ReturnCount

Best practice
Minor

Function has 3 return statements which exceeds the limit of 2.

detekt.SpreadOperator

Best practice
Minor

In most cases using a spread operator causes a full copy of the array to be created before calling a method which has a very high performance penalty.

detekt.ThrowsCount

Best practice
Medium

Too many throw statements in function.

detekt.TooGenericExceptionCaught

Error prone
Medium

Caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.

detekt.TooGenericExceptionThrown

Error prone
Minor

Throwable is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.

detekt.TooManyFunctions

Design
Medium

Too many functions in object

detekt.TopLevelPropertyNaming

Best practice
Medium

Top level constant names should match the pattern: [A-Z][\_A-Z0-9]*

detekt.UnnecessaryAbstractClass

Best practice
Medium

An abstract class without a concrete member can be refactored to an interface.

detekt.UnreachableCode

Error prone
Minor

This expression is followed by unreachable code which should either be used or removed.

detekt.UtilityClassWithPublicConstructor

Error prone
Minor

The class only contains utility functions. Consider defining it as an object.

detekt.VariableNaming

Error prone
Minor

Private variable names should match the pattern: (\_)?[a-z][A-Za-z0-9]*

detekt.WildcardImport

Error prone
Minor

Use qualified import

detekt.EmptyElseBlock

Error prone
High

Empty block of code can be removed.

Learn more

detekt.EmptyFunctionBlock

Error prone
High

Empty function block can be removed

detekt.EmptyIfBlock

Error prone
High

Empty if block can be removed

detekt.EmptySecondaryConstructor

Error prone
High

Empty secondary constructor can be removed

detekt.EqualsWithHashCodeExist

Error prone
High

A class should always override hashCode when overriding equals and the other way around.

detekt.EmptyInitBlock

Best practice
Medium

Reports empty init expressions. Empty blocks of code serve no purpose and should be removed.

detekt.ImplicitDefaultLocale

Error prone
Medium

String.format() uses implicitly default locale for string formatting.

detekt.ExceptionRaisedInUnexpectedLocation

Safety
Medium

This method is not expected to throw exceptions. This can cause weird behavior.

detekt.UnusedPrivateMember

Best practice
Minor

Function parameter is unused

detekt.PrintStackTrace

Best practice
Medium

Instead of simply printing a stacktrace a better logging solution should be used.

detekt.SerialVersionUIDInSerializableClass

Code style
High

Classes which implement the Serializable interface should also correctly declare a serialVersionUID

detekt.SwallowedException

Error prone
Medium

Exceptions should not be swallowed.

detekt.ThrowingExceptionsWithoutMessageOrCause

Error prone
High

Exceptions should always call one of the constructor overloads to provide a message or a cause.