ktlint v0.46.0 Release Notes
Release Date: 2022-06-18 // almost 2 years ago-
Promoting experimental rules to standard
The rules below are promoted from the
experimental
ruleset to thestandard
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
settingdisabled_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 onlyExperimentalParams
. 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 methodgetEditorConfigValue
to retrieve a named.editorconfig
property for a given ASTNode. When implementing this interface, the valueeditorConfigProperties
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:astNode .getEditorConfigValue(DefaultEditorConfigProperties.disabledRulesProperty) .split(",")
and be supplied via the
ExperimentalParams
as follows:ExperimentalParams( ... 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:astNode .getEditorConfigValue(DefaultEditorConfigProperties.codeStyleProperty)
and be supplied via the
ExperimentalParams
as follows:ExperimentalParams( ... 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 itwrapping
(#1350) - ๐ Fix indentation of property getter/setter when the property has an initializer on a separate line
indent
(#1335) - ๐ When
.editorconfig
settingindentSize
is set to valuetab
then return the default tab width as value forindentSize
(#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 to1.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
propertyktlint_code_style = android
is defined