Skip to content

Releases: pinterest/ktlint

1.4.0

24 Oct 14:59
Compare
Choose a tag to compare

🆕 Features

🔧 Fixes

  • Prevent line separators to be changed from CRLF to LF - #2752, by @paul-dingemans

  • fix: don't remove arrow from lambdas that are when/if leaf nodes - #2758, by @tKe

  • Fix false positive in no-semi rule for enum class without enum entries - #2774, by @paul-dingemans

  • Prevent conflict between multiline-expression-wrapping and function-signature - #2775, by @paul-dingemans

  • Ignore max_line_length property unless max-line-length rule is enabled - #2783, by @paul-dingemans

  • Fix false positive in class-signature when EOL comment is between a class annotation and other class modifier - #2786, by @paul-dingemans

  • Fix globs ending with ** - #2787, by @paul-dingemans

  • Return exit code 1 in case violations have been found but file is unchanged - #2803, by @paul-dingemans

  • Ignore missing whitespace after trailing comma in single line parameter value list - #2806, by @paul-dingemans

  • Remove HEADER_KEYWORD & IMPL_KEYWORD - #2810, by @3flex

  • Function signature rule ignores context receiver when on separate line - #2814, by @paul-dingemans

  • Do not remove imports for which the fully qualified path is identical to the package name - #2822, by @paul-dingemans

  • Fix indentation of a multiline parameter list inside a function literal for code style ktlint_official - #2823, by @paul-dingemans

  • Do not insert a trailing comma in a multiline when-entry containing a guard - #2825, by @paul-dingemans

  • Fix wrapping of expression body when max_line_length not set - #2833, by @paul-dingemans

📦 Dependencies

  • Update dependency io.github.oshai:kotlin-logging-jvm to v7 - #2701, by @renovate[bot]

  • Update dependency org.assertj:assertj-core to v3.26.3 - #2738, by @renovate[bot]

  • Update mikepenz/release-changelog-builder-action action to v5 - #2756, by @renovate[bot]

  • chore(deps): update plugin kotlinx-binary-compatibiltiy-validator to v0.16.3 - #2759, by @renovate[bot]

  • fix(deps): update dependency org.slf4j:slf4j-simple to v2.0.16 - #2764, by @renovate[bot]

  • Migrate to com.gradleup.shadow - #2763, by @Goooler

  • chore(deps): update gradle/actions action to v4 - #2760, by @renovate[bot]

  • chore(deps): update plugin com.gradle.develocity to v3.18.1 - #2792, by @renovate[bot]

  • chore(deps): update dependency gradle to v8.10.2 - #2812, by @renovate[bot]

  • chore(deps): update plugin shadow to v8.3.3 - #2820, by @renovate[bot]

  • fix(deps): update dependency com.github.ajalt.clikt:clikt to v5.0.1 - #2828, by @renovate[bot]

  • chore(deps): update kotlin monorepo to v2.0.21 - #2831, by @renovate[bot]

  • fix(deps): update dependency org.ec4j.core:ec4j-core to v1.1.0 - #2832, by @renovate[bot]

  • fix(deps): update dependency org.jetbrains.kotlin:kotlin-gradle-plugin to v2.1.0-beta2 - #2834, by @renovate[bot]

  • fix(deps): update dependency dev.drewhamilton.poko:poko-gradle-plugin to v0.17.2 - #2837, by @renovate[bot]

  • fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.11.3 - #2840, by @renovate[bot]

  • chore(deps): update actions/checkout digest to 11bd719 - #2841, by @renovate[bot]

1.3.1

02 Jul 15:46
49f376b
Compare
Choose a tag to compare

🔧 Fixes

  • Add link for backing-property-naming, correct binary-expression-wrapping - #2704, by @rsmith20
  • Do not insert a whitespace element as first or last child inside a composite element - #2715, by @paul-dingemans
  • Do not rewrite a class to a single line signature in case it contains an EOL comment - #2716, by @paul-dingemans
  • Fix false positive when anonymous function is used as value argument - #2718, by @paul-dingemans
  • Fix suppression handling when 'formatter:on' not properly specified - #2719, by @paul-dingemans
  • Fix false positive when primary constructor has no arguments and a secondary constructor exists - #2717, by @paul-dingemans
  • Ignore suppressions for no-unused-imports rule - #2720, by @paul-dingemans
  • Ignore suppressions in rule no-unused-imports - #2725, by @paul-dingemans
  • Fix false alert Format was not able to resolve all violations which (theoretically) can be autocorrected - #2727, by @paul-dingemans
  • Fix "unset" value for property ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than - #2728, by @paul-dingemans

📦 Dependencies

  • Update dependency gradle to v8.8 - #2680, by @renovate[bot]
  • Update plugin com.gradle.develocity to v3.17.5 - #2697, by @renovate[bot]
  • Update actions/checkout digest to 692973e - #2699, by @renovate[bot]
  • Update dependency io.github.hakky54:logcaptor to v2.9.3 - #2707, by @renovate[bot]
  • Update dependency org.junit.jupiter:junit-jupiter to v5.10.3 - #2721, by @renovate[bot]

💬 Other

1.3.0

04 Jun 18:19
e61cbbc
Compare
Choose a tag to compare

🆕 Features

🔧 Fixes

📦 Dependencies

  • Update dependency org.jetbrains.dokka:dokka-gradle-plugin to v1.9.20 - #2590, by @renovate[bot]

  • Update softprops/action-gh-release action to v2 - #2600, by @renovate[bot]

  • Update dependency io.github.detekt.sarif4k:sarif4k to v0.6.0 - #2605, by @renovate[bot]

  • Update dependency gradle to v8.7 - #2616, by @renovate[bot]

  • Migrate to develocity plugin - #2625, by @Goooler

  • Update dependency org.slf4j:slf4j-simple to v2.0.13 - #2632, by @renovate[bot]

  • Update gradle/wrapper-validation-action action to v3 - #2633, by @renovate[bot]

  • Update dependency io.github.oshai:kotlin-logging-jvm to v6.0.9 - #2634, by @renovate[bot]

  • Update dependency com.github.ajalt.clikt:clikt to v4.4.0 - #2647, by @renovate[bot]

  • Update kotlin monorepo to v1.9.24 - #2649, by @renovate[bot]

  • Update plugin com.gradle.develocity to v3.17.4 - #2660, by @renovate[bot]

  • Update dependency dev.drewhamilton.poko:poko-gradle-plugin to v0.15.3 - #2662, by @renovate[bot]

  • Update actions/checkout digest to a5ac7e5 - #2664, by @renovate[bot]

  • Update dependency org.assertj:assertj-core to v3.26.0 - #2669, by @renovate[bot]

1.2.1

29 Feb 20:38
25924fa
Compare
Choose a tag to compare

🆕 Features

None

🔧 Fixes

1.2.0

28 Feb 17:58
ab287d9
Compare
Choose a tag to compare

🆕 Features

WARNING: The new rules have accidentally not been marked as experimental. This will be fixed in a bugfix!

  • Break dependency between string-template-indent and multiline-expression-wrapping - #2505, by @paul-dingemans

  • Allow string template to exceed max line length when it is the only element on a line - #2480, by @paul-dingemans

  • Add configuration setting for ignoring argument-list-wrapping above treshold of argument - #2481, by @paul-dingemans
    NOTE: In code style ktlint_official this threshold is unset so that arguments are always wrapped. If this impacts your code too much, you can make it backward compatible by setting .editorconfig property ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than to value 8. For other code styles this property is initialized with value 8 and as of that backward compatible by default.

  • Ignore EOL comment that causes max_line_length to be exceeded, except in max-line-length rule - #2516, by @paul-dingemans

  • Add new rule for disallowing KDoc at non-whitelisted locations - #2548, by @paul-dingemans

  • Improve insert of suppression - #2546, by @paul-dingemans

  • Ignore modifier of backing property in android_studio code style - #2552, by @paul-dingemans

  • Add rule to check spacing around square brackets 'square-brackets-spacing' - #2555, by @paul-dingemans

  • Add rule blank-line-between-when-conditions - #2564, by @paul-dingemans

🔧 Fixes

📦 Dependencies

  • chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.8.0 - #2503, by @renovate[bot]

  • fix(deps): update dependency io.github.oshai:kotlin-logging-jvm to v6 - #2440, by @renovate[bot]

  • Replace gradle/gradle-build-action@v3 with gradle/actions/setup-gradle@v3 - #2518, by @paul-dingemans

  • chore(deps): update plugin kotlinx-binary-compatibiltiy-validator to v0.14.0 - #2522, by @renovate[bot]

  • chore(deps): update gradle/wrapper-validation-action action to v2 - #2523, by @renovate[bot]

  • chore(deps): update ffurrer2/extract-release-notes action to v2 - #2515, by @renovate[bot]

  • chore(deps): update dependency gradle to v8.6 - #2531, by @renovate[bot]

  • fix(deps): update dependency org.assertj:assertj-core to v3.25.3 - #2536, by @renovate[bot]

  • fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.10.2 - #2534, by @renovate[bot]

  • fix(deps): update dependency org.slf4j:slf4j-simple to v2.0.12 - #2538, by @renovate[bot]

  • fix(deps): update dependency org.codehaus.janino:janino to v3.1.12 - #2559, by @renovate[bot]

💬 Other

1.1.1

08 Jan 18:08
0b4193e
Compare
Choose a tag to compare

🆕 Features

None

🔧 Fixes

📦 Dependencies

  • fix(deps): update kotlin monorepo to v1.9.22 - #2456, by @renovate[bot]

  • chore(deps): update actions/setup-python action to v5 - #2417, by @renovate[bot]

  • fix(deps): update dependency org.slf4j:slf4j-simple to v2.0.10 - #2470, by @renovate[bot]

  • fix(deps): update dependency dev.drewhamilton.poko:poko-gradle-plugin to v0.15.2 - #2485, by @renovate[bot]

  • fix(deps): update dependency org.assertj:assertj-core to v3.25.1 - #2486, by @renovate[bot]

1.1.0

19 Dec 12:03
ebfe2d0
Compare
Choose a tag to compare

🆕 Features

🔧 Fixes

📦 Dependencies

  • fix(deps): update dependency org.jetbrains.dokka:dokka-gradle-plugin to v1.9.10 - #2323, by @renovate[bot]

  • fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.10.1 - #2342, by @renovate[bot]

  • fix(deps): update kotlin monorepo to v1.9.21 - #2374, by @renovate[bot]

  • fix(deps): update dependency org.codehaus.janino:janino to v3.1.11 - #2387, by @renovate[bot]

  • fix(deps): update dependency dev.drewhamilton.poko:poko-gradle-plugin to v0.15.1 - #2389, by @renovate[bot]

  • chore(deps): update dependency gradle to v8.5 - #2392, by @renovate[bot]

  • chore(deps): update actions/checkout digest to b4ffde6 - #2329, by @renovate[bot]

  • chore(deps): update actions/setup-java action to v4 - #2393, by @renovate[bot]

  • fix(deps): update dependency ch.qos.logback:logback-classic to v1.3.14 - #2406, by @renovate[bot]

  • fix(deps): update dependency io.github.hakky54:logcaptor to v2.9.2 - #2409, by @renovate[bot]

  • fix(deps): update dependency io.github.oshai:kotlin-logging-jvm to v5.1.4 - #2439, by @renovate[bot]

1.0.1

13 Oct 12:25
3e55920
Compare
Choose a tag to compare

🆕 Features

  • Add .editorconfig property ktlint_function_naming_ignore_when_annotated_with so that rule function-naming can be ignored based on annotations on that rule. See function-naming.

🔧 Fixes

📦 Dependencies

  • Update dependency io.github.detekt.sarif4k:sarif4k to v0.5.0 - #2277, by @renovate[bot]

  • Update dependency gradle to v8.4 - #2294, by @renovate[bot]

  • Update actions/checkout action to v4 - #2225, by @renovate[bot]

  • Update actions/checkout digest to 8ade135 - #2295, by @renovate[bot]

💬 Other

1.0.0

05 Sep 14:01
a510eed
Compare
Choose a tag to compare

💔 Breaking changes

  • Update and align Maven coordinates - #2195, by @paul-dingemans
    Be sure to update Maven coordinates below, to get latest changes!

    Old Maven coordinates New Maven coordinates
    com.pinterest:ktlint com.pinterest.ktlint:ktlint-cli
    com.pinterest.ktlint:ktlint-reporter-baseline com.pinterest.ktlint:ktlint-cli-reporter-baseline
    com.pinterest.ktlint:ktlint-reporter-checkstyle com.pinterest.ktlint:ktlint-cli-reporter-checkstyle
    com.pinterest.ktlint:ktlint-cli-reporter com.pinterest.ktlint:ktlint-cli-reporter-core
    com.pinterest.ktlint:ktlint-reporter-format com.pinterest.ktlint:ktlint-cli-reporter-format
    com.pinterest.ktlint:ktlint-reporter-html com.pinterest.ktlint:ktlint-cli-reporter-html
    com.pinterest.ktlint:ktlint-reporter-json com.pinterest.ktlint:ktlint-cli-reporter-json
    com.pinterest.ktlint:ktlint-reporter-plain com.pinterest.ktlint:ktlint-cli-reporter-plain
    com.pinterest.ktlint:ktlint-reporter-plain-summary com.pinterest.ktlint:ktlint-cli-reporter-plain-summary
    com.pinterest.ktlint:ktlint-reporter-sarif com.pinterest.ktlint:ktlint-cli-reporter-sarif
  • Add binary compatibility validator - #2131, by @mateuszkwiecinski

  • Replace kotlin public data classes with Poko compiler plugin generated ones - #2136, by @mateuszkwiecinski
    As a part of public API stabilization, data classes are no longer used in the public API. As of that, functions like copy() or componentN() (used for destructuring declarations) are not available anymore.

  • Promote experimental rules - #2218, by @paul-dingemans
    The rules below have been promoted to non-experimental rules:

  • Fix statement-wrapping and align rule classes - #2178, by @paul-dingemans
    Rule class MultilineExpressionWrapping has been renamed to MultilineExpressionWrappingRule. Rule class StatementWrapping has been renamed to StatementWrappingRule. RULE_ID constants below are moved to a different Java class at compile time. Each rule provided by Ktlint is to be accompanied by a RULE_ID constant that can be used in the VisitorModifier.RunAfter. Filenames did not comply with standard that it should end with Rule suffix.

    RULE ID Old Java class name New Java class name
    FUNCTION_EXPRESSION_BODY_RULE_ID FunctionExpressionBodyKt FunctionExpressionBodyRuleKt
    FUNCTION_LITERAL_RULE_ID FunctionLiteralKt FunctionLiteralRuleKt
    MULTILINE_EXPRESSION_WRAPPING_RULE_ID MultilineExpressionWrappingKt MultilineExpressionWrappingRuleKt
    NO_BLANK_LINE_IN_LIST_RULE_ID NoBlankLineInListKt NoBlankLineInListRuleKt
    NO_EMPTY_FILE_RULE_ID (not applicable) NoEmptyFileRuleKt
  • Update to Kotlin 1.9 & remove TreeCopyHandler extension - #2113, by @paul-dingemans
    Class org.jetbrains.kotlin.com.intellij.treeCopyHandler is no longer registered as extension point for the compiler as this is not supported in Kotlin 1.9. Please test your custom rules. In case of unexpected exceptions during formatting of code, see #2044 for possible remediation.

🆕 Features

  • Change default code style to ktlint_official - #2144, by @paul-dingemans

  • Add new experimental rule class-signature - #2119, by @paul-dingemans

  • Add new experimental rule function-expression-body - #2151, by @paul-dingemans

  • Add new experimental rule chain-method-continuation - #2088, by @atulgpt

  • Add new experimental rule function-literal - #2137, by @paul-dingemans

  • Add new experimental rule function-type-modifier-spacing rule - #2216, by @t-kameyama

  • Define EditorConfigOverride for dynamically loaded ruleset - #2194, by @paul-dingemans
    The EditorConfigOverride parameter of the KtlintRuleEngine can be defined using the factory method EditorConfigOverride.from(vararg properties: Pair<EditorConfigProperty<*>, *>). This requires the EditorConfigProperty's to be available at compile time. Some common EditorConfigProperty's are defined in ktlint-rule-engine-core which is loaded as transitive dependency of ktlint-rule-engine and as of that are available at compile.
    If an EditorConfigProperty is defined in a Rule that is only provided via a runtime dependency, it gets a bit more complicated. The ktlint-api-consumer example has now been updated to show how the EditorConfigProperty can be retrieved from the Rule.

  • Move wrapping on semicolon from wrapping rule to statement-wrapping rule - #2222, by @paul-dingemans

🔧 Fixes

Read more

0.50.0

29 Jun 20:16
fdb0506
Compare
Choose a tag to compare

Deprecation of ktlint-enable and ktlint-disable directives

The ktlint-disable and ktlint-enable directives are no longer supported. Ktlint rules can now only be suppressed using the @Suppress or @SuppressWarnings annotations. A new rule, internal:ktlint-suppression, is provided to replace the directives with annotations.

API consumers do not need to provide this rule, but it does no harm when done.

The internal:ktlint-suppression rule can not be disabled via the .editorconfig nor via @Suppress or @SuppressWarnings annotations.

Custom Rule Providers need to prepare for Kotlin 1.9

In Kotlin 1.9 the extension points of the embedded kotlin compiler will change. Ktlint only uses the org.jetbrains.kotlin.com.intellij.treeCopyHandler extension point. This extension is not yet supported in 1.9, neither is it documented (#KT-58704). Without this extension point it might happen that your custom rules will throw exceptions during runtime. See #1981.

In Ktlint, 7 out of 77 rules needed small and sometimes bigger changes to become independent of the extension point org.jetbrains.kotlin.com.intellij.treeCopyHandler. The impact on your custom rules may vary dependent on the way the autocorrect has been implemented. When manipulating ASTNodes there seems to be no impact. When, manipulating PsiElements, some functions consistently result in a runtime exception.

Based on the refactoring of the rules as provided by ktlint-ruleset-standard in Ktlint 0.49.x the suggested refactoring is as follows:

  • Replace LeafElement.replaceWithText(String) with LeafElement.rawReplaceWithText(String).
  • Replace PsiElement.addAfter(PsiElement, PsiElement) with AstNode.addChild(AstNode, AstNode). Note that this method inserts the new node (first) argument before the second argument node and as of that is not a simple replacement of the PsiElement.addAfter(PsiElement, PsiElement).
  • Replace PsiElement.replace(PsiElement) with a sequence of AstNode.addChild(AstNode, AstNode) and AstNode.removeChild(AstNode).

Be aware that your custom rules might use other functions which also throw exceptions when the extension point org.jetbrains.kotlin.com.intellij.treeCopyHandler is no longer supported.

In order to help you to analyse and fix the problems with your custom rules, ktlint temporarily supports to disable the extension point org.jetbrains.kotlin.com.intellij.treeCopyHandler using a flag. This flag is available in the Ktlint CLI and in the KtlintRuleEngine. By default, the extension point is enabled like it was in previous versions of ktlint.

At least you should analyse the problems by running your test suits by running ktlint and disabling the extension point. Next you can start with fixing and releasing the updated rules. All rules in this version of ktlint have already been refactored and are not dependent on the extension point anymore. In Ktlint CLI the flag is to be activated with parameter --disable-kotlin-extension-point. API Consumers that use the KtlintRuleEngine directly, have to set property enableKotlinCompilerExtensionPoint to false.

At this point in time, it is not yet decided what the next steps will be. Ktlint might drop the support of the extension points entirely. Or, if the extension point org.jetbrains.kotlin.com.intellij.treeCopyHandler is fully supported at the time that ktlint will be based on kotlin 1.9 it might be kept. In either case, the flag will be dropped in a next version of ktlint.

Added

  • Add new experimental rule binary-expression-wrapping. This rule wraps a binary expression in case the max line length is exceeded (#1940)
  • Add flag to disable extension point org.jetbrains.kotlin.com.intellij.treeCopyHandler to analyse impact on custom rules #1981
  • Add new experimental rule no-empty-file for all code styles. A kotlin (script) file may not be empty (#1074)
  • Add new experimental rule statement-wrapping which ensures function, class, or other blocks statement body doesn't start or end at starting or ending braces of the block (#1938)
  • Add new experimental rule blank-line-before-declaration. This rule requires a blank line before class, function or property declarations (#1939)
  • Wrap multiple statements on same line wrapping (#1078)
  • Add new rule ktlint-suppression to replace the ktlint-disable and ktlint-enable directives with annotations. This rule can not be disabled via the .editorconfig (#1947)
  • Inform user about using --format option of KtLint CLI when finding a violation that can be autocorrected (#1071)

Removed

  • Code which was deprecated in 0.49.x is removed. Consult changelog of 0.49.x` released for more information. Summary of removed code:

Fixed

  • Do not flag a (potential) mutable extension property in case the getter is annotated or prefixed with a modifier property-naming (#2024)
  • Do not merge an annotated expression body with the function signature even if it fits on a single line (#2043)
  • Ignore property with name serialVersionUID in property-naming (#2045)
  • Prevent incorrect reporting of violations in case a nullable function type reference exceeds the maximum line length parameter-list-wrapping (#1324)
  • Prevent false negative on else branch when body contains only chained calls or binary expression (#2057)
  • Fix indent when property value is wrapped to next line (#2095)

Changed

  • Fix Java interoperability issues with RuleId and RuleSetId classes. Those classes were defined as value classes in 0.49.0 and 0.49.1. Although the classes were marked with @JvmInline it seems that it is not possible to uses those classes from Java base API Consumers like Spotless. The classes have now been replaced with data classes (#2041)
  • Update dependency info.picocli:picocli to v4.7.4
  • Update dependency org.junit.jupiter:junit-jupiter to v5.9.3
  • Update Kotlin development version to 1.8.22 and Kotlin version to 1.8.22.
  • Update dependency io.github.detekt.sarif4k:sarif4k to v0.4.0
  • Update dependency org.jetbrains.dokka:dokka-gradle-plugin to v1.8.20
  • Run format up to 3 times in case formatting introduces changes which also can be autocorrected (#2084)