Skip to main content

Formatting Rule Set

This rule set provides wrappers for rules implemented by ktlint - https://ktlint.github.io/.

Note: Issues reported by this rule set can only be suppressed on file level (@file:Suppress("detekt.rule"). Note: The formatting rule set is not included in the detekt-cli or gradle plugin.

To enable this rule set, add detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$version" to your gradle dependencies or reference the detekt-formatting-jar with the --plugins option in the command line interface.

AnnotationOnSeparateLine

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

AnnotationSpacing

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

ArgumentListWrapping

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

Configuration options:

  • indentSize (default: 4)

    indentation size

  • maxLineLength (default: 120) (android default: 100)

    maximum line length

BlockCommentInitialStarAlignment

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

ChainWrapping

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

CommentSpacing

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

CommentWrapping

See <a href="https://ktlint.github.io/#rule-indentation">ktlint-website</a> for documentation.

Active by default: No

Configuration options:

  • indentSize (default: 4)

    indentation size

DiscouragedCommentLocation

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

EnumEntryNameCase

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

Filename

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

This rules overlaps with naming&gt;MatchingDeclarationName from the standard rules, make sure to enable just one.

Active by default: Yes - Since v1.0.0

FinalNewline

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

This rules overlaps with style&gt;NewLineAtEndOfFile from the standard rules, make sure to enable just one. The pro of this rule is that it can auto-correct the issue.

Active by default: Yes - Since v1.0.0

Configuration options:

  • insertFinalNewLine (default: true)

    report absence or presence of a newline

FunKeywordSpacing

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

FunctionTypeReferenceSpacing

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

ImportOrdering

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

For defining import layout patterns see: https://github.com/pinterest/ktlint/blob/a6ca5b2edf95cc70a138a9470cfb6c4fd5d9d3ce/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt

Active by default: Yes - Since v1.19.0

Configuration options:

  • layout (default: '*,java.**,javax.**,kotlin.**,^') (android default: '*')

    the import ordering layout

Indentation

See <a href="https://ktlint.github.io/#rule-indentation">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.19.0

Configuration options:

  • indentSize (default: 4)

    indentation size

  • continuationIndentSize (default: 4)

    Deprecated: continuationIndentSize is ignored by KtLint and will have no effect

    continuation indentation size

KdocWrapping

See <a href="https://ktlint.github.io/#rule-indentation">ktlint-website</a> for documentation.

Active by default: No

Configuration options:

  • indentSize (default: 4)

    indentation size

MaximumLineLength

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

This rules overlaps with style&gt;MaxLineLength from the standard rules, make sure to enable just one or keep them aligned. The pro of this rule is that it can auto-correct the issue.

Active by default: Yes - Since v1.0.0

Configuration options:

  • maxLineLength (default: 120) (android default: 100)

    maximum line length

  • ignoreBackTickedIdentifier (default: false)

    ignore back ticked identifier

ModifierListSpacing

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

ModifierOrdering

See <a href="https://ktlint.github.io/#rule-modifier-order">ktlint-website</a> for documentation.

This rules overlaps with style&gt;ModifierOrder from the standard rules, make sure to enable just one. The pro of this rule is that it can auto-correct the issue.

Active by default: Yes - Since v1.0.0

MultiLineIfElse

See <a href="https://ktlint.github.io/#rule-modifier-order">ktlint-website</a> for documentation.

Active by default: No

NoBlankLineBeforeRbrace

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoConsecutiveBlankLines

See <a href="https://ktlint.github.io/#rule-blank">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoEmptyClassBody

See <a href="https://ktlint.github.io/#rule-empty-class-body">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoEmptyFirstLineInMethodBlock

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

NoLineBreakAfterElse

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoLineBreakBeforeAssignment

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoMultipleSpaces

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoSemicolons

See <a href="https://ktlint.github.io/#rule-semi">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoTrailingSpaces

See <a href="https://ktlint.github.io/#rule-trailing-whitespaces">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoUnitReturn

See <a href="https://ktlint.github.io/#rule-unit-return">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoUnusedImports

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

NoWildcardImports

See <a href="https://ktlint.github.io/#rule-import">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

Configuration options:

  • packagesToUseImportOnDemandProperty (default: 'java.util.*,kotlinx.android.synthetic.**')

    Defines allowed wildcard imports

PackageName

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: No

ParameterListWrapping

See <a href="https://ktlint.github.io">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

Configuration options:

  • maxLineLength (default: 120) (android default: 100)

    maximum line length

  • indentSize (default: 4)

    Deprecated: indentSize is ignored by KtLint and will have no effect

    indentation size

SpacingAroundAngleBrackets

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

SpacingAroundColon

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundComma

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundCurly

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundDot

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundDoubleColon

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

SpacingAroundKeyword

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundOperators

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundParens

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundRangeOperator

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

SpacingAroundUnaryOperator

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

SpacingBetweenDeclarationsWithAnnotations

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

SpacingBetweenDeclarationsWithComments

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

StringTemplate

See <a href="https://ktlint.github.io/#rule-string-template">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.0.0

TrailingComma

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

Configuration options:

  • allowTrailingComma (default: false)

    Defines whether a trailing comma (or no trailing comma) should be enforced on the defining side

  • allowTrailingCommaOnCallSite (default: false)

    Defines whether a trailing comma (or no trailing comma) should be enforced on the calling side

TypeArgumentListSpacing

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

UnnecessaryParenthesesBeforeTrailingLambda

See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation.

Active by default: No

Wrapping

See <a href="https://ktlint.github.io/#rule-indentation">ktlint-website</a> for documentation.

Active by default: Yes - Since v1.20.0