Releases: pinterest/ktlint
0.46.0
[0.46.0] - 2022-06-18
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
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 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:
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
0.45.2
[0.45.2] - 2022-04-06
Fixed
- Resolve compatibility issues introduced in 0.45.0 and 0.45.1 (#1434). Thanks to mateuszkwiecinski and jeremymailen for your input on this issue.
Changed
- Set Kotlin development version to
1.6.20
and Kotlin version to1.6.20
.
0.45.1
0.45.0
[0.45.0] - 2022-03-18
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.
Retrieving ".editorconfig" property value
This section is applicable when providing rules that depend on one or more values of ".editorconfig" properties. Property values should no longer be retrieved via EditConfig or directly via userData[EDITOR_CONFIG_USER_DATA_KEY]
. Property values should now only be retrieved using method ASTNode.getEditorConfigValue(editorConfigProperty)
of interface UsesEditorConfigProperties
which is provided in this release. Starting from next release after the current release, the EditConfig and/or userData[EDITOR_CONFIG_USER_DATA_KEY]
may be removed without further notice which will break your API or rule. To prevent disruption of your end user, you should migrate a.s.a.p.
Added
- Add experimental rule for unexpected spaces in a type reference before a function identifier (
function-type-reference-spacing
) (#1341) - Add experimental rule for incorrect spacing after a type parameter list (
type-parameter-list-spacing
) (#1366) - Add experimental rule to detect discouraged comment locations (
discouraged-comment-location
) (#1365) - Add rule to check spacing after fun keyword (
fun-keyword-spacing
) (#1362) - Add experimental rules for unnecessary spacing between modifiers in and after the last modifier in a modifier list (#1361)
- New experimental rule for aligning the initial stars in a block comment when present (
experimental:block-comment-initial-star-alignment
(#297) - Respect
.editorconfig
propertyij_kotlin_packages_to_use_import_on_demand
(no-wildcard-imports
) (#1272) - Add new experimental rules for wrapping of block comment (
comment-wrapping
) (#1403) - Add new experimental rules for wrapping of KDoc comment (
kdoc-wrapping
) (#1403) - Add experimental rule for incorrect spacing after a type parameter list (
type-parameter-list-spacing
) (#1366) - Expand check task to run tests on JDK 17 - "testOnJdk17"
Fixed
- Fix lint message to "Unnecessary long whitespace" (
no-multi-spaces
) (#1394) - Do not remove trailing comma after a parameter of type array in an annotation (experimental:trailing-comma) (#1379)
- Do not delete blank lines in KDoc (no-trailing-spaces) (#1376)
- Do not indent raw string literals that are not followed by either trimIndent() or trimMargin() (
indent
) (#1375) - Revert remove unnecessary wildcard imports as introduced in Ktlint 0.43.0 (
no-unused-imports
) (#1277), (#1393), (#1256) - (Possibly) resolve memory leak (#1216)
- Initialize loglevel in Main class after parsing the CLI parameters (#1412)
Changed
- Print the rule id always in the PlainReporter (#1121)
- All wrapping logic is moved from the
indent
rule to the new rulewrapping
(as part of thestandard
ruleset). In case you currently have disabled theindent
rule, you may want to reconsider whether this is still necessary or that you also want to disable the newwrapping
rule to keep the status quo. Both rules can be run independent of each other. (#835)
Removed
0.44.0
[0.44.0] - 2022-02-15
Please welcome paul-dingemans as an official maintainer of ktlint!
Added
- Use Gradle JVM toolchain with language version 8 to compile the project
- Basic tests for CLI (#540)
- Add experimental rule for unnecessary parentheses in function call followed by lambda (#1068)
Fixed
- Fix indentation of function literal (#1247)
- Fix false positive in rule spacing-between-declarations-with-annotations (#1281)
- Do not remove imports for same class when different alias is used (#1243)
- Fix NoSuchElementException for property accessor (
trailing-comma
) (#1280) - Fix ClassCastException using ktlintFormat on class with KDoc (
no-trailing-spaces
) (#1270) - Do not remove trailing comma in annotation (#1297)
- Do not remove import which is used as markdown link in KDoc only (
no-unused-imports
) (#1282) - Fix indentation of secondary constructor (
indent
) (#1222) - Custom gradle tasks with custom ruleset results in warning (#1269)
- Fix alignment of arrow when trailing comma is missing in when entry (
trailing-comma
) (#1312) - Fix indent of delegated super type entry (
indent
) (#1210) - Improve indentation of closing quotes of a multiline raw string literal (
indent
) (#1262) - Trailing space should not lead to delete of indent of next line (
no-trailing-spaces
) (#1334) - Force a single line function type inside a nullable type to a separate line when the max line length is exceeded (
parameter-list-wrapping
) (#1255) - A single line function with a parameter having a lambda as default argument does not throw error (
indent
) (#1330) - Fix executable jar on Java 16+ (#1195)
- Fix false positive unused import after autocorrecting a trailing comma (#1367)
- Fix false positive indentation (
parameter-list-wrapping
,argument-list-wrapping
) (#897, #1045, #1119, #1255, #1267, #1319, #1320, #1337 - Force a single line function type inside a nullable type to a separate line when the max line length is exceeded (
parameter-list-wrapping
) (#1255)
Changed
- Update Kotlin version to
1.6.0
release - Add separate tasks to run tests on JDK 11 - "testOnJdk11"
- Update Dokka to
1.6.0
release - Apply ktlint experimental rules on the ktlint code base itself.
- Update shadow plugin to
7.1.1
release - Add Kotlin-logging backed by logback as logging framework (#589)
- Update Gradle to
7.4
version
0.43.2
0.43.0
[0.43.0] - 2021-11-02
Added
- New
trailing-comma
rule (#709) (prior art by paul-dingemans)
Fixed
- Fix false positive with lambda argument and call chain (
indent
) (#1202) - Fix trailing spaces not formatted inside block comments (
no-trailing-spaces
) (#1197) - Do not check for
.idea
folder presence when usingapplyToIDEA
globally (#1186) - Remove spaces before primary constructor (
paren-spacing
) (#1207) - Fix false positive for delegated properties with a lambda argument (
indent
) (#1210) - Remove unnecessary wildcard imports (
no-unused-imports
) (#1256) - Fix indentation of KDoc comment when using tab indentation style (
indent
) (#850)
Changed
- Support absolute paths for globs (#1131)
- Fix regression from 0.41 with argument list wrapping after dot qualified expression (
argument-list-wrapping
)(#1159) - Update Gradle to
7.2
version - Update Gradle shadow plugin to
7.1
version - Update Kotlin version to
1.5.31
version. Default Kotlin API version was changed to1.4
!
0.42.1
[0.42.1] - 2021-08-06
Dot release to fix regressions in indent
rule introduced in 0.42.0 release. Thanks to t-kameyama for the fixes!
Fixed
0.42.0
Thank you to the following contributors for this release:
Added
- SARIF output support (#1102)
Fixed
- Remove needless blank lines in dot qualified expression (#1077)
- Fix false positives for SpacingBetweenDeclarationsWithAnnotationsRule (#1125)
- Fix false positive with eol comment (
annotation-spacing
) (#1124) - Fix KtLint dependency variant selection (#1114)
- Fix false positive with 'by lazy {}' (
indent
) (#1162) - Fix false positive with value argument list has lambda (
indent
) (#764) - Fix false positive in lambda in dot qualified expression (
argument-list-wrapping
) (#1112) - Fix false positive with multiline expression with elvis operator in assignment (
indent
) (#1165) - Ignore backticks in imports for ordering purposes (
import-ordering
) (#1106) - Fix false positive with elvis operator and comment (
chain-wrapping
) (#1055) - Fix false negative in when conditions (
chain-wrapping
) (#1130) - Fix the Html reporter Chinese garbled (#1140)
- Performance regression introduced in 0.41.0 (#1135)
Changed
- Updated to dokka 1.4.32 (#1148)
- Updated Kotlin to 1.5.20 version
0.41.0
[0.41.0] - 2021-03-16
Note: This release contains breaking changes to globs passed to ktlint via the command line. See (#999) and the README.
Thank you to t-kameyama and paul-dingemans for your contributions to this release!
Added
- New
ktlint_ignore_back_ticked_identifier
EditorConfig option formax-line-length
rule to ignore long method names inside backticks
(primarily used in tests) (#1007) - Allow to add/replace loaded
.editorconfig
values viaExperimentalParams#editorConfigOverride
(#1016) ReporterProvider
,LintError
,RuleSetProvider
now implementSerializable
interface
Fixed
- Incorrect indentation with multiple interfaces (#1003)
- Empty line before primary constructor is not reported and formatted-out (#1004)
- Fix '.editorconfig' generation for "import-ordering" rule (#1011)
- Fix "filename" rule will not work when '.editorconfig' file is not found (#997)
- EditorConfig generation for
import-ordering
(#1011) - Internal error (
no-unused-imports
) (#996) - Fix false positive when argument list is after multiline dot-qualified expression (
argument-list-wrapping
) (#893) - Fix indentation for function types after a newline (
indent
) (#918) - Don't remove the equals sign for a default argument (
no-line-break-before-assignment
) (#1039) - Fix internal error in
no-unused-imports
(#1040) - Fix false positives when declaration has tail comments (
spacing-between-declarations-with-comments
) (#1053) - Fix false positive after
else
keyword (argument-list-wrapping
) (#1047) - Fix formatting with comments (
colon-spacing
) (#1057) - Fix IndexOutOfBoundsException in
argument-list-wrapping-rule
formatting file with many corrections (#1081) - Fix formatting in arguments (
multiline-if-else
) (#1079) - Fix experimental:annotation-spacing-rule autocorrection with comments
- Migrate from klob dependency and fix negated globs passed to CLI are no longer worked (#999)
Breaking: absolute paths globs will no longer work, check updated README
Changed
- Update Gradle shadow plugin to
6.1.0
version - Align with Kotlin plugin on how alias pattern is represented for imports layout rule (#753)
- Align with Kotlin plugin on how subpackages are represented (#753)
- Deprecated custom
kotlin_imports_layout
EditorConfig property. Please useij_kotlin_imports_layout
to ensure
that the Kotlin IDE plugin and ktlint use same imports layout (#753) - Deprecated
idea
andascii
shortcuts as theij_kotlin_imports_layout
property does not support those.
Please check README on how to achieve those with patterns (#753) - Update Gradle to
6.8.3
version - Update Kotlin to
1.4.31
version. Fixes #1063.