ktlint v0.46.1 Release Notes

Release Date: 2022-06-21 // 3 months ago
  • ๐Ÿš€ Minor release to address some regressions introduced in 0.46.0

    ๐Ÿ›  Fixed

    • โœ‚ Remove experimental flag -Xuse-k2 as it forces API Consumers to compile their projects with this same flag (#1506).
    • ๐Ÿ‘• Account for separating spaces when parsing the disabled rules (#1508).
    • ๐Ÿ‘• Do not remove space before a comment in a parameter list (#1509).
    • ๐Ÿ‘• A delegate property which starts on the same line as the property declaration should not have an extra indentation indent (#1510)

Previous changes from v0.46.0

  • Promoting experimental rules to standard

    The rules below are promoted from the experimental ruleset to the standard ruleset.

    • annotation
    • annotation-spacing
    • argument-list-wrapping
    • double-colon-spacing
    • enum-entry-name-case
    • multiline-if-else
    • no-empty-first-line-in-method-block
    • ๐Ÿ“ฆ package-name
    • trailing-comma
    • spacing-around-angle-brackets
    • spacing-between-declarations-with-annotations
    • spacing-between-declarations-with-comments
    • unary-op-spacing

    ๐Ÿšš Note that as a result of moving the rules that the prefix experimental: has to be removed from all references to this rule. Check references in:

    • The .editorconfig setting disabled_rules.
    • ๐Ÿ‘• KtLint disable and enable directives.
    • The VisitorModifier.RunAfterRule.

    ๐Ÿ‘• If your project did not run with the experimental ruleset enabled before, you might expect new lint violations to be reported. Please note that rules can be disabled via the the .editorconfig in case you do not want the rules to be applied on your project.

    API Changes & RuleSet providers

    ๐Ÿš€ If you are not an API user nor a RuleSet provider, then you can safely skip this section. Otherwise, please read below carefully and upgrade your usage of ktlint. In this and coming releases, we are changing and adapting important parts of our API in order to increase maintainability and flexibility for future changes. Please avoid skipping a releases as that will make it harder to migrate.

    ๐Ÿ‘• Lint and formatting functions

    ๐Ÿ‘• The lint and formatting changes no longer accept parameters of type Params but only ExperimentalParams. Also, the VisitorProvider parameter has been removed. Because of this, your integration with KtLint breaks. Based on feedback with ktlint 0.45.x, we now prefer to break at compile time instead of trying to keep the interface backwards compatible. Please raise an issue, in case you help to convert to the new API.

    ๐Ÿ‘‰ Use of ".editorconfig" properties & userData

    ๐Ÿ‘ป The interface UsesEditorConfigProperties provides method getEditorConfigValue to retrieve a named .editorconfig property for a given ASTNode. When implementing this interface, the value editorConfigProperties needs to be overridden. Previously it was not checked whether a retrieved property was actually recorded in this list. Now, retrieval of unregistered properties results in an exception.

    ๐Ÿ‘• Property Ktlint.DISABLED has been removed. The property value can now be retrieved as follows:


    and be supplied via the ExperimentalParams as follows:

        editorConfigOverride =  EditorConfigOverride.from(
          DefaultEditorConfigProperties.disabledRulesProperty to "some-rule-id,experimental:some-other-rule-id"

    ๐Ÿ‘‰ Property Ktlint.ANDROID_USER_DATA_KEY has been removed. The property value can now be retrieved as follows:


    and be supplied via the ExperimentalParams as follows:

        editorConfigOverride =  EditorConfigOverride.from(
          DefaultEditorConfigProperties.codeStyleProperty to "android" 

    ๐Ÿ’… This property defaults to the official Kotlin code style when not set.

    ๐Ÿ‘• Testing KtLint rules

    ๐Ÿ’… An AssertJ style API for testing KtLint rules (#1444) has been added. Usage of this API is encouraged in favor of using the old RuleExtension API. For more information, see KtLintAssertThat API

    โž• Added

    • โž• Add experimental rule for unexpected spacing between function name and opening parenthesis (spacing-between-function-name-and-opening-parenthesis) (#1341)
    • โž• Add experimental rule for unexpected spacing in the parameter list (parameter-list-spacing) (#1341)
    • โž• Add experimental rule for incorrect spacing around the function return type (function-return-type-spacing) (#1341)
    • โž• Add experimental rule for unexpected spaces in a nullable type (nullable-type-spacing) (#1341)
    • ๐Ÿ‘• Do not add a space after the typealias name (type-parameter-list-spacing) (#1435)
    • โž• Add experimental rule for consistent spacing before the start of the function body (function-start-of-body-spacing) (#1341)
    • ๐Ÿ‘• Suppress ktlint rules using @Suppress (more information) (#765)
    • โž• Add experimental rule for rewriting the function signature (function-signature) (#1341)

    ๐Ÿ›  Fixed

    • ๐Ÿ‘• Move disallowing blank lines in chained method calls from no-consecutive-blank-lines to new rule (no-blank-lines-in-chained-method-calls) (#1248)
    • ๐Ÿ›  Fix check of spacing in the receiver type of an anonymous function (#1440)
    • ๐Ÿ‘ Allow comment on same line as super class in class declaration wrapping (#1457)
    • ๐Ÿ‘• Respect git hooksPath setting (#1465)
    • ๐Ÿ›  Fix formatting of a property delegate with a dot-qualified-expression indent (#1340)
    • ๐Ÿ‘• Keep formatting of for-loop in sync with default IntelliJ formatter (indent) and a newline in the expression in a for-statement should not force to wrap it wrapping (#1350)
    • ๐Ÿ›  Fix indentation of property getter/setter when the property has an initializer on a separate line indent (#1335)
    • ๐Ÿ‘• When .editorconfig setting indentSize is set to value tab then return the default tab width as value for indentSize (#1485)
    • ๐Ÿ‘ Allow suppressing all rules or a list of specific rules in the entire file with @file:Suppress(...) (#1029)

    ๐Ÿ”„ Changed

    • โšก๏ธ Update Kotlin development version to 1.7.0 and Kotlin version to 1.7.0.
    • ๐Ÿš€ Update shadow plugin to 7.1.2 release
    • ๐Ÿš€ Update picocli to 4.6.3 release
    • ๐Ÿ‘• A file containing only one (non private) top level declaration (class, interface, object, type alias or function) must be named after that declaration. The name also must comply with the Pascal Case convention. The same applies to a file containing one single top level class declaration and one ore more extension functions for that class. filename (#1004)
    • ๐Ÿ‘• Promote experimental rules to standard rules set: annotation, annotation-spacing, argument-list-wrapping, double-colon-spacing, enum-entry-name-case, multiline-if-else, no-empty-first-line-in-method-block, package-name, traling-comma, spacing-around-angle-brackets, spacing-between-declarations-with-annotations, spacing-between-declarations-with-comments, unary-op-spacing (#1481)
    • The CLI parameter --android can be omitted when the .editorconfig property ktlint_code_style = android is defined