Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ktlint to v1 (major) #1729

Merged
merged 4 commits into from
Sep 20, 2023
Merged

Update Ktlint to v1 (major) #1729

merged 4 commits into from
Sep 20, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Sep 11, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
com.pinterest.ktlint:ktlint-cli-ruleset-core 0.49.1 -> 1.0.0 age adoption passing confidence
com.pinterest.ktlint:ktlint-logger 0.49.1 -> 1.0.0 age adoption passing confidence
com.pinterest.ktlint:ktlint-rule-engine 0.49.1 -> 1.0.0 age adoption passing confidence

⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information.


Release Notes

pinterest/ktlint (com.pinterest.ktlint:ktlint-cli-ruleset-core)

v1.0.0

Compare Source

💔 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
📦 Dependencies
💬 Other

v0.50.0

Compare Source

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). Note, although this rule is added in this release, it is never executed except in unit tests.
  • 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)

Configuration

📅 Schedule: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about these updates again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/major-ktlint branch from 23293e9 to 27899f6 Compare September 11, 2023 06:56
@nulls nulls self-assigned this Sep 11, 2023
@renovate renovate bot force-pushed the renovate/major-ktlint branch from 27899f6 to a4cfff6 Compare September 18, 2023 07:28
@renovate renovate bot force-pushed the renovate/major-ktlint branch from a4cfff6 to c0a34d9 Compare September 18, 2023 07:48
@nulls nulls mentioned this pull request Sep 19, 2023
1 task
- supported artifact names changes
- logging upgrades
- disabled tests which fails with repeatable run
- fixed test for comment when ASTNode.copy() is called
@renovate
Copy link
Contributor Author

renovate bot commented Sep 20, 2023

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

Warning: custom changes will be lost.

@nulls nulls added this to the 2.0.0 milestone Sep 20, 2023
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #1729 (5579d78) into master (84e380d) will decrease coverage by 3.46%.
The diff coverage is 12.90%.

@@             Coverage Diff              @@
##             master    #1729      +/-   ##
============================================
- Coverage     78.21%   74.76%   -3.46%     
+ Complexity     2324     2270      -54     
============================================
  Files           126      126              
  Lines          8223     8230       +7     
  Branches       2073     2072       -1     
============================================
- Hits           6432     6153     -279     
- Misses          876     1163     +287     
+ Partials        915      914       -1     
Files Changed Coverage Δ
...c/main/kotlin/com/saveourtool/diktat/DiktatMain.kt 0.00% <ø> (ø)
...iktat/common/config/reader/AbstractConfigReader.kt 66.66% <0.00%> (-8.34%) ⬇️
...ktat/common/config/reader/ApplicationProperties.kt 0.00% <0.00%> (ø)
...ol/diktat/common/config/rules/RulesConfigReader.kt 34.14% <0.00%> (ø)
...com/saveourtool/diktat/ruleset/rules/DiktatRule.kt 62.50% <0.00%> (-2.72%) ⬇️
...at/ruleset/rules/chapter2/comments/CommentsRule.kt 87.64% <0.00%> (-1.00%) ⬇️
.../ruleset/rules/chapter2/kdoc/CommentsFormatting.kt 52.97% <0.00%> (-18.46%) ⬇️
...diktat/ruleset/rules/chapter3/TrailingCommaRule.kt 74.07% <0.00%> (-18.38%) ⬇️
...iktat/ruleset/rules/chapter3/files/NewlinesRule.kt 81.86% <0.00%> (ø)
...tat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt 77.99% <0.00%> (ø)
... and 6 more

... and 9 files with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

JUnit Tests (macOS, EnricoMi/publish-unit-test-result-action@v2)

   164 files  ±0     164 suites  ±0   5m 32s ⏱️ +8s
1 377 tests ±0  1 308 ✔️  - 33  69 💤 +33  0 ±0 
2 756 runs  ±0  2 686 ✔️  - 34  70 💤 +34  0 ±0 

Results for commit 5579d78. ± Comparison against base commit 84e380d.

This pull request skips 33 tests.
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect class name fix()
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect object name fix()
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect variable name case fix()
com.saveourtool.diktat.ruleset.chapter2.CommentsFormattingFixTest ‑ check lines and spaces in comments()
com.saveourtool.diktat.ruleset.chapter2.KdocCommentsFixTest ‑ check fix without class kdoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ @param tag should be added to existing KDoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ @throws tag should be added to existing KDoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ KdocMethods rule should reformat code (full example)()
com.saveourtool.diktat.ruleset.chapter3.BracesRuleFixTest ‑ should add braces to do-while loops with empty body()
com.saveourtool.diktat.ruleset.chapter3.BracesRuleFixTest ‑ should add braces to if-else statements - 1()
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

JUnit Tests (Windows, EnricoMi/publish-unit-test-result-action@v2)

   164 files  ±0     164 suites  ±0   5m 15s ⏱️ - 1m 33s
1 377 tests ±0  1 320 ✔️  - 40  57 💤 +40  0 ±0 
2 756 runs  ±0  2 698 ✔️  - 41  58 💤 +41  0 ±0 

Results for commit 5579d78. ± Comparison against base commit 84e380d.

This pull request skips 40 tests.
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect class name fix()
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect object name fix()
com.saveourtool.diktat.ruleset.chapter1.IdentifierNamingFixTest ‑ incorrect variable name case fix()
com.saveourtool.diktat.ruleset.chapter2.CommentsFormattingFixTest ‑ check lines and spaces in comments()
com.saveourtool.diktat.ruleset.chapter2.KdocCommentsFixTest ‑ check fix without class kdoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ @param tag should be added to existing KDoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ @throws tag should be added to existing KDoc()
com.saveourtool.diktat.ruleset.chapter2.KdocMethodsFixTest ‑ KdocMethods rule should reformat code (full example)()
com.saveourtool.diktat.ruleset.chapter3.BracesRuleFixTest ‑ should add braces to do-while loops with empty body()
com.saveourtool.diktat.ruleset.chapter3.BracesRuleFixTest ‑ should add braces to if-else statements - 1()
…

♻️ This comment has been updated with latest results.

@nulls nulls enabled auto-merge (squash) September 20, 2023 09:33
@nulls nulls disabled auto-merge September 20, 2023 09:34
@nulls nulls merged commit 11ea0aa into master Sep 20, 2023
30 of 32 checks passed
@nulls nulls deleted the renovate/major-ktlint branch September 20, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant