Releases: pinterest/ktlint
1.2.0
🆕 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-wrappingabove treshold of argument - #2481, by @paul-dingemans
NOTE: In code stylektlint_officialthis threshold isunsetso that arguments are always wrapped. If this impacts your code too much, you can make it backward compatible by setting.editorconfigpropertyktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_thanto value8. For other code styles this property is initialized with value8and 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_studiocode 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
-
Prevent IllegalArgumentException in
argument-list-wrappingrule - #2500, by @paul-dingemans -
Ignore function which is returned as result in a function body - #2526, by @paul-dingemans
-
Fix false positive newline expected before comment in enum - #2527, by @paul-dingemans
-
Report violation when parameter list is preceded by a comment - #2541, by @paul-dingemans
-
Ignore EOL comments in
value-argument-commentandvalue-parameter-comment- #2551, by @paul-dingemans -
Do not indent string template starting at first position of line - #2553, by @paul-dingemans
-
Prevent conflict when curly closing brace is followed by range (until) operator - #2554, by @paul-dingemans
-
Run argument-list-wrapping after function-signature - #2568, by @paul-dingemans
-
Ignore simple reference expressions in
chain-method-continuation- #2569, by @paul-dingemans
📦 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
-
2550 clikt - #2556, by @paul-dingemans
1.1.1
🆕 Features
None
🔧 Fixes
-
Fix incorrect generateEditorConfig example in documentation - #2444, by @stay7
-
Fix insert of suppression on binary expression - #2463, by @paul-dingemans
-
Loosen dependency between chain-method-continuation and argument-list-wrapping - #2468, by @paul-dingemans
-
Keep arrow when both parameter list and block of function literal are empty - #2469, by @paul-dingemans
-
Improve wrapping of binary expressions - #2479, by @paul-dingemans
-
Resolve conflict between parameter-list-spacing and parameter-list-wrapping - #2491, by @paul-dingemans
-
Do not wrap binary expression value argument if it is already preceded by a newline - #2493, by @paul-dingemans
-
Fix operator spacing - #2473, by @paul-dingemans
-
Run
argument-list-wrapping,class-signatureandfunction-signaturewhen comment rules are disabled - #2466, by @paul-dingemans
📦 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
🆕 Features
-
Compile with java 21 instead of 20 - #2320, by @paul-dingemans
-
Improve checking on backing property - #2346, by @paul-dingemans
-
Add multiline-loop to complement multiline-if-else - #2298, by @hendraanggrian
-
Add "UnusedImport" as @Suppress alias - #2357, by @paul-dingemans
-
Allow backing property to be correlated to a public function - #2356, by @paul-dingemans
-
Add helper function 'fromSnippetWithPath' to create a Code instance - #2359, by @paul-dingemans
-
Support logging and exception throwing when loading baseline - #2362, by @paul-dingemans
-
Allow factory methods to use generics, and to overload other factory … - #2366, by @paul-dingemans
-
Remove dependencies on discouraged-comment-location rule - #2371, by @paul-dingemans
-
Ignore imports for
rangeUntilinno-unused-importsrule - #2376, by @paul-dingemans -
Ignore imports for
assigninno-unused-importsrule - #2382, by @paul-dingemans -
Ignore invalid function names when importing from "junit.framework" - #2386, by @paul-dingemans
-
Add experimental rules
condition-wrappingandmixed-condition-operators- #2401, by @paul-dingemans -
Allow property, function and class name to be same as keyword wrapped with backticks - #2405, by @paul-dingemans
-
Set offset of
max-line-lengthviolation to the last position at which a newline can be inserted to fix the violation - #2419, by @paul-dingemans -
Add support for API Consumers to add suppressions - #2428, by @paul-dingemans
-
Disallow
else-if (..) <statement>as single line construct - #2430, by @paul-dingemans -
Allow empty constructor for expected class declaration - #2431, by @paul-dingemans
-
Disallow comments in try-catch-finally at unexpected locations - #2432, by @paul-dingemans
-
Make ktlint.bat more environment agnostic - #2421, by @TWiStErRob
-
Suppress property-naming rule via
@Suppress("ConstPropertyName")- #2442, by @paul-dingemans
🔧 Fixes
-
Remove obsolete configuration files - #2321, by @paul-dingemans
-
De-indent the closing angle bracket of the type argument list and type parameter lists in ktlint_official code style - #2302, by @paul-dingemans
-
docs: Fix artifact url of Maven Central Badge - #2327, by @guicamest
-
Remove redundant arrow in function literal without parameters / fix documentation - #2365, by @paul-dingemans
-
Move curly brace before all consecutive comments preceding that curly brace - #2375, by @paul-dingemans
-
Prevent stack overflow exception when code provided via stdin can not be parsed as Kotlin, nor Kotlin script - #2380, by @paul-dingemans
-
Fix searching from inside a hidden directory - #2377, by @kitterion
-
Prevent unwanted joining of KDoc with preceding type-parameter-list - #2381, by @paul-dingemans
-
Fix false positive violation in
annotationrule - #2400, by @paul-dingemans -
Replace all function bodies with body expressions in a single run - #2395, by @paul-dingemans
-
Fix offset for violation when final newline is missing - #2407, by @paul-dingemans
-
Fix path to ktlint JAR file in
ktlint.bat- #2408, by @paul-dingemans -
Simplify
max-line-lengthimplementation - #2410, by @paul-dingemans -
Remove deprecated cli parameters
--experimental,--code-style,--disabled-rules- #2411, by @paul-dingemans -
Fix adding blank line between declaration and an annotated declaration which is preceded by comment - #2429, by @paul-dingemans
-
Update CODE_OF_CONDUCT with correct path - #2437, by @OriginalMHV
📦 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
🆕 Features
- Add
.editorconfigpropertyktlint_function_naming_ignore_when_annotated_withso that rulefunction-namingcan be ignored based on annotations on that rule. See function-naming.
🔧 Fixes
-
Fix code style parameter in cli - #2241, by @paul-dingemans
-
Anonymous function in assignment - #2263, by @paul-dingemans
-
Fix indent of multiline object declaration inside class - #2266, by @paul-dingemans
-
Do not replace function body with multiple exit points - #2273, by @paul-dingemans
-
Ignore override of function in rule
function-naming- #2274, by @paul-dingemans -
Suppress
function-namingbased on annotations - #2275, by @paul-dingemans -
Force blank line before object declaration - #2287, by @paul-dingemans
-
Multiline expression wrapping - #2290, by @paul-dingemans
-
Ignore function naming in Kotest classes - #2291, by @paul-dingemans
-
Improve violation message in
discouraged-comment-location- #2293, by @paul-dingemans -
Fix malformed AST when
&&or||is at start of linechain-wrapping- #2300, by @paul-dingemans -
Do not report false positives
type-argument-list-spacingandtype-parameter-list-spacing- #2303, by @paul-dingemans -
Fix chain method continuation containing higher order function call - #2305, by @paul-dingemans
📦 Dependencies
-
Update dependency io.github.detekt.sarif4k:sarif4k to v0.5.0 - #2277, 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
💔 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 likecopy()orcomponentN()(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:- blank-line-before-declaration
- context-receiver-wrapping
- discouraged-comment-location
- enum-wrapping
- function-naming
- function-signature
- if-else-bracing
- multiline-expression-wrapping
- if-else-wrapping
- no-blank-line-in-list
- no-consecutive-comments
- no-empty-file
- no-empty-first-line-in-class-body
- no-single-line-block-comment
- parameter-list-spacing
- property-naming
- statement-wrapping
- string-template-indent
- try-catch-finally-spacing
- type-argument-list-spacing
- type-parameter-list-spacing
- unnecessary-parentheses-before-trailing-lambda
-
Fix statement-wrapping and align rule classes - #2178, by @paul-dingemans
Rule classMultilineExpressionWrappinghas been renamed toMultilineExpressionWrappingRule. Rule classStatementWrappinghas been renamed toStatementWrappingRule.RULE_IDconstants below are moved to a different Java class at compile time. Each rule provided by Ktlint is to be accompanied by aRULE_IDconstant that can be used in theVisitorModifier.RunAfter. Filenames did not comply with standard that it should end withRulesuffix.RULE ID Old Java class name New Java class name FUNCTION_EXPRESSION_BODY_RULE_IDFunctionExpressionBodyKt FunctionExpressionBodyRuleKt FUNCTION_LITERAL_RULE_IDFunctionLiteralKt FunctionLiteralRuleKt MULTILINE_EXPRESSION_WRAPPING_RULE_IDMultilineExpressionWrappingKt MultilineExpressionWrappingRuleKt NO_BLANK_LINE_IN_LIST_RULE_IDNoBlankLineInListKt NoBlankLineInListRuleKt NO_EMPTY_FILE_RULE_ID(not applicable) NoEmptyFileRuleKt -
Update to Kotlin 1.9 & remove TreeCopyHandler extension - #2113, by @paul-dingemans
Classorg.jetbrains.kotlin.com.intellij.treeCopyHandleris 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-spacingrule - #2216, by @t-kameyama -
Define
EditorConfigOverridefor dynamically loaded ruleset - #2194, by @paul-dingemans
TheEditorConfigOverrideparameter of theKtlintRuleEnginecan be defined using the factory methodEditorConfigOverride.from(vararg properties: Pair<EditorConfigProperty<*>, *>). This requires theEditorConfigProperty's to be available at compile time. Some commonEditorConfigProperty's are defined inktlint-rule-engine-corewhich is loaded as transitive dependency ofktlint-rule-engineand as of that are available at compile.
If anEditorConfigPropertyis defined in aRulethat is only provided via a runtime dependency, it gets a bit more complicated. Thektlint-api-consumerexample has now been updated to show how theEditorConfigPropertycan be retrieved from theRule. -
Move wrapping on semicolon from
wrappingrule tostatement-wrappingrule - #2222, by @paul-dingemans
🔧 Fixes
-
Do not indent class body for classes having a long super type list - #2116, by @paul-dingemans
-
Fix indent of explicit constructor - #2118, by @paul-dingemans
-
Fix incorrect formatting of nested function literal - #2107, by @paul-dingemans
-
Add property to disable ktlint for a glob in
.editorconfig- #2108, by @paul-dingemans -
Fix spacing around colon in annotations - #2126, by @paul-dingemans
-
Fix solving problems in 3 consecutive runs - #2132, by @paul-dingemans
-
Fix indent parenthesized expression - #2127, by @paul-dingemans
-
Fix indent of IS_EXPRESSION, PREFIX_EXPRESSION and POSTFIX_EXPRESSION - #2125, by @paul-dingemans
-
Do not wrap a binary expression after an elvis operator - #2134, by @paul-dingemans
-
Drop obsolete class LintError in ktlint-api-consumer - #2145, by @paul-dingemans
-
Fix null pointer exception for if-else statement with empty THEN block - #2142, by @paul-dingemans
-
Fix false positive in propert...
0.50.0
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)withLeafElement.rawReplaceWithText(String). - Replace
PsiElement.addAfter(PsiElement, PsiElement)withAstNode.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 thePsiElement.addAfter(PsiElement, PsiElement). - Replace
PsiElement.replace(PsiElement)with a sequence ofAstNode.addChild(AstNode, AstNode)andAstNode.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.treeCopyHandlerto analyse impact on custom rules #1981 - Add new experimental rule
no-empty-filefor all code styles. A kotlin (script) file may not be empty (#1074) - Add new experimental rule
statement-wrappingwhich 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-suppressionto replace thektlint-disableandktlint-enabledirectives with annotations. This rule can not be disabled via the.editorconfig(#1947) - Inform user about using
--formatoption of KtLint CLI when finding a violation that can be autocorrected (#1071)
Removed
- Code which was deprecated in
0.49.xis 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
serialVersionUIDinproperty-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
elsebranch 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
RuleIdandRuleSetIdclasses. Those classes were defined as value classes in0.49.0and0.49.1. Although the classes were marked with@JvmInlineit 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:picoclito v4.7.4 - Update dependency
org.junit.jupiter:junit-jupiterto v5.9.3 - Update Kotlin development version to
1.8.22and Kotlin version to1.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)
0.49.1
Added
Removed
Fixed
- Store path of file containing a lint violation relative to the location of the baseline file itself (#1962)
- Print absolute path of file in lint violations when flag "--relative" is not specified in Ktlint CLI (#1963)
- Handle parameter
--code-style=android_studioin Ktlint CLI identical to deprecated parameter--android(#1982) - Prevent nullpointer exception (NPE) if class without body is followed by multiple blank lines until end of file
no-consecutive-blank-lines(#1987) - Allow to 'unset' the
.editorconfigpropertyktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_thanwhen usingktlint_officialcode stylefunction-signature(#1977) - Prevent nullpointer exception (NPE) if or operator at start of line is followed by dot qualified expression
indent(#1993) - Fix indentation of multiline parameter list in function literal
indent(#1976) - Restrict indentation of closing quotes to
ktlint_officialcode style to keep formatting of other code styles consistent with0.48.xand beforeindent(#1971) - Extract rule
no-single-line-block-commentfromcomment-wrappingrule. Theno-single-line-block-commentrule is added as experimental rule to thektlint_officialcode style, but it can be enabled explicitly for the other code styles as well. (#1980) - Clean-up unwanted logging dependencies (#1998)
- Fix directory traversal for patterns referring to paths outside of current working directory or any of it child directories (#2002)
Changed
- Moved class
Baselinefromktlint-clitoktlint-cli-reporter-baselineso that Baseline functionality is reusable for API Consumers.
0.49.0
WARNING: This version of KtLint contains a number of breaking changes in KtLint CLI and KtLint API. If you are using KtLint with custom ruleset jars or custom reporter jars, then those need to be upgraded before you can use them with this version of ktlint. Please contact the maintainers of those jars and ask them to upgrade a.s.a.p.
All rule id's in the output of Ktlint are now prefixed with a rule set. Although KtLint currently supports standard rules to be unqualified, users are encouraged to include the rule set id in all references to rules. This includes following:
- The
--disabled-rulesparameter in KtLint CLI. - The
.editorconfigproperties used to enable or disable rule and rule sets. Note that propertiesdisabled_rulesandktlint_disabled_ruleshave been removed in this release. See disabled rules for more information. - The
sourceelement in the KtLint CLIbaseline.xmlfile. Regenerating this file, fixes all rule references automatically. - The KtLint disable directives
ktlint-enable/ktlint-disableand the@Suppress('ktlint:...')annotations. - The
VisitorModifier.RunAfterRule.
Moving experimental rules to standard rule set
The experimental rule set has been merged with standard rule set. The rules which formerly were part of the experimental rule set are still being treated as before. The rules will only be run in case .editorconfig property ktlint_experimental is enabled or in case the rule is explicitly enabled.
Note that the prefix experimental: has to be removed from all references to this rule. Check references in:
- The
--disabled-rulesparameter in KtLint CLI. - The
.editorconfigproperties used to enable or disable rule and rule sets. Note that propertiesdisabled_rulesandktlint_disabled_ruleshave been removed in this release. See disabled rules for more information. - The KtLint disable directives
ktlint-enable/ktlint-disableand the@Suppress('ktlint:...')annotations. - The
VisitorModifier.RunAfterRule.
Promote experimental rules to non-experimental
The rules below have been promoted to non-experimental rules:
- block-comment-initial-star-alignment
- class-naming
- comment-wrapping
- function-return-type-spacing
- function-start-of-body-spacing
- function-type-reference-spacing
- fun-keyword-spacing
- kdoc-wrapping
- modifier-list-spacing
- nullable-type-spacing
- spacing-between-function-name-and-opening-parenthesis
- unnecessary-parentheses-before-trailing-lambda
Note that this only affects users that have enabled the standard ruleset while having the experimental rules disabled.
API Changes & RuleSet providers & Reporter Providers
This release is intended to be the last release before the 1.0.x release of ktlint. If all goes as planned, the 1.0.x release does not contain any new breaking changes with except of removal of functionality which is deprecated in this release.
This release contains a lot of breaking changes which aims to improve the future maintainability of Ktlint. If you get stuck while migrating, please reach out to us by creating an issue.
Experimental rules
Rules in custom rule sets can now be marked as experimental by implementing the Rule.Experimental interface on the rule. Rules marked with this interface will only be executed by Ktlint if .editorconfig property ktlint_experimental is enabled or if the rule itself has been enabled explicitly.
When using this feature, experimental rules should not be defined in a separate rule set as that would require a distinct rule set id. When moving a rule from an experimental rule set to a non-experimental rule set this would mean that the qualified rule id changes. For users of such rules this means that ktlint directives to suppress the rule and properties in the .editorconfig files have to be changed.
EditorConfig
Field defaultAndroidValue in class EditorConfigProperty has been renamed to androidStudioCodeStyleDefaultValue. New fields ktlintOfficialCodeStyleDefaultValue and intellijIdeaCodeStyleDefaultValue have been added. Read more about this in the section "Ktlint Official code style".
The .editorconfig properties disabled_rules and ktlint_disabled_rules are no longer supported. Specifying those properties in the editorConfigOverride or editorConfigDefaults result in warnings at runtime.
'Ktlint Official` code style and renaming of existing code styles
A new code style ktlint_official is introduced. This code style is work in progress but will become the default code style in the 1.0 release. Please try out the new code style and provide your feedback via the issue tracker.
This ktlint_official code style combines the best elements from the Kotlin Coding conventions and Android's Kotlin styleguide. This code style also provides additional formatting on topics which are not (explicitly) mentioned in those conventions and style guide. But do note that this code style sometimes formats code in a way which is not accepted by the default code formatters in IntelliJ IDEA and Android Studio. The formatters of those editors produce nicely formatted code in the vast majority of cases. But in a number of edge cases, the formatting contains bugs which are waiting to be fixed for several years. The new code style formats code in a way which is compatible with the default formatting of the editors whenever possible. When using this codestyle, it is best to disable (e.g. not use) code formatting in the editor.
The existing code styles have been renamed to make more clear what the basis of the code style is.
The official code style has been renamed to intellij_idea. Code formatted with this code style aims to be compatible with default formatter of IntelliJ IDEA. This code style is based on Kotlin Coding conventions. If .editorconfig property ktlint_code_style has been set to android then do not forget to change the value of that property to intellij_idea. When not set, this is still the default code style of ktlint 0.49. Note that the default code style will be changed to ktlint_official in the 1.0 release.
Code style android has been renamed to android_studio. Code formatted with this code style aims to be compatible with default formatter of Android Studio. This code style is based on Android's Kotlin styleguide. If .editorconfig property ktlint_code_style has been set to android then do not forget to change the value of that property to android_studio.
Package restructuring and class relocation
The internal structure of the Ktlint project has been revised. The Ktlint CLI and KtLint API modules have been decoupled where possible. Modules have been restructured and renamed. See API Overview for more information.
This is the last release that contains module ktlint-core as it had too many responsibilities. All classes in this module are relocated to other modules. Some classes have also been renamed. See tables below for details. Classes that are left behind in the ktlint-core module are deprecated and were kept in this version for backwards compatibility only. The ktlint-core module will be removed in Ktlint 0.50.x.
Classes below have been moved from module ktlint-core to the new module ktlint-rule-engine-core:
Old class/package name in ktlint-core |
New class/package name in ktlint-rule-engine-core |
|---|---|
| com.pinterest.ktlint.core.api.editorconfig | com.pinterest.ktlint.rule.engine.core.api.editorconfig |
| com.pinterest.ktlint.core.api.EditorConfigProperties | com.pinterest.ktlint.rule.engine.core.api.EditorConfig |
| com.pinterest.ktlint.core.api.OptInFeatures | com.pinterest.ktlint.rule.engine.core.api.OptInFeatures |
| com.pinterest.ktlint.core.ast.ElementType | com.pinterest.ktlint.rule.engine.core.api.ElementType |
| com.pinterest.ktlint.core.ast.package | com.pinterest.ktlint.rule.engine.core.api.ASTNodeExtension |
| com.pinterest.ktlint.core.IndentConfig | com.pinterest.ktlint.rule.engine.core.api.IndentConfig |
| com.pinterest.ktlint.core.Rule ... |
0.48.2
Additional clarification on API Changes in 0.48.0 and 0.48.1
Starting with Ktlint 0.48.x, rule and rule sets can be enabled/disabled with a separate property per rule (set). Please read deprecation of (ktlint_)disable_rules property for more information.
API Consumers that provide experimental rules to the KtLintRuleEngine, must also enable the experimental rules or instruct their users to do so in the .editorconfig file. From the perspective of the API Consumer it might be confusing or unnecessary to do so as the experimental rule was already provided explicitly.
Ktlint wants to provide the user (e.g. a developer) a uniform and consistent user experience. The .editorconfig becomes more and more central to store configuration for Ktlint. This to ensure that all team members use the exact same configuration when running ktlint regardless whether the Ktlint CLI or an API Consumer is being used.
The .editorconfig is a powerful configuration tool which can be used in very different ways. Most projects use a single .editorconfig file containing one common section for kotlin and kotlin scripts files. For example, the .editorconfig file of the Ktlint project contains following section:
[*.{kt,kts}]
ij_kotlin_imports_layout = *
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = trueOther projects might contain multiple .editorconfig files for different parts of the project directory hierarchy. Or, use a single .editorconfig file containing multiple sections with different globs. Like all other configuration settings in Ktlint, the user should be able to enable and disable the experimental rules. Both for the entire set of experimental rules and for individual experimental rules.
Ktlint allows API Consumers to set default values and override values for the .editorconfig. Specifying a default value means that the user does not need to define the property in the .editorconfig file but if the user specifies the value, it will take precedence. Specifying the override value ensures that this takes precedence on a value specified by the user in the .editorconfig.
From the Ktlint perspective, it is advised that API Consumers provide the default value. See example below, for how to specify the editorConfigDefault property:
KtLintRuleEngine(
ruleProviders = ruleProviders,
editorConfigDefaults = EditorConfigDefaults(
EditorConfig
.builder()
.section(
Section
.builder()
.glob(Glob("*.{kt,kts}"))
.properties(
Property
.builder()
.name("ktlint_experimental")
.value("enabled"),
),
)
.build()
)
)
If the user has set property ktlint_experimental explicitly than that value will be used. If the value is not defined, the value provided via editorConfigDefaults will be used.
If you do want to ignore the value of ktlint_experimental as set by the user, than you can set the EditorConfigOverride property. But as said before that is discouraged as the user might not understand why the .editorconfig property is being ignored (provided that the value set is not equal to the value provided by the API Consumer).
Added
Removed
Fixed
- Fix with array-syntax annotations on the same line as other annotations
annotation(#1765) - Do not enable the experimental rules by default when
.editorconfigpropertiesdisabled_rulesorktlint_disabled_rulesare set. (#1771) - A function signature not having any parameters which exceeds the
max-line-lengthshould be ignored by rulefunction-signature(#1773) - Allow diacritics in names of classes, functions packages, and properties
class-naming,function-naming,package-name,property-naming(#1757) - Prevent violation of
file-namerule on code snippets (#1768) - Clarify that API Consumers have to enable experimental rules (#1768)
- Trim spaces in the
.editorconfigpropertyij_kotlin_imports_layout's entries (#1770)
Changed
0.48.1
Added
Removed
Fixed
- An enumeration class having a primary constructor and in which the list of enum entries is followed by a semicolon then do not remove the semicolon in case it is followed by code element
no-semi(#1733) - Add API so that KtLint API consumer is able to process a Kotlin script snippet without having to specify a file path (#1738)
- Disable the
standard:filenamerule whenever Ktlint CLI is run with option--stdin(#1742) - Fix initialization of the logger when
--log-levelis specified. Throw exception when an invalid value is passed. (#1749) - Fix loading of custom rule set JARs.
- Rules provided via a custom rule set JAR (Ktlint CLI) or by an API provider are enabled by default. Only rules in the
experimentalrule set are disabled by default. (#1747)
Changed
- Update Kotlin development version to
1.8.0and Kotlin version to1.8.0.