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
Upgrade ktlint to 0.47.1 #5312
Upgrade ktlint to 0.47.1 #5312
Conversation
748a3af
to
b0192a1
Compare
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/KtLintMultiRule.kt
Fixed
Show fixed
Hide fixed
b0192a1
to
40702ba
Compare
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/KtLintMultiRule.kt
Fixed
Show fixed
Hide fixed
40702ba
to
9c603d8
Compare
9c603d8
to
80f147a
Compare
80f147a
to
e564057
Compare
e564057
to
9efcbe7
Compare
...src/test/kotlin/io/gitlab/arturbosch/detekt/formatting/TrailingCommaOnDeclarationSiteSpec.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
96c7185
to
a16d9c7
Compare
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/FormattingRule.kt
Fixed
Show fixed
Hide fixed
a16d9c7
to
8ac3be1
Compare
if (contains(File.separatorChar)) { | ||
substringAfterLast(File.separatorChar) | ||
} else { | ||
this | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violation is detected once pinterest/ktlint#828 is addressed.
wrapping.beforeFirstNode(computeEditorConfigProperties()) | ||
root.node.visitASTNodes() | ||
wrapping.afterLastNode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Rule lifecycle hooks / deprecate RunOnRootOnly visitor modifier
in https://github.com/pinterest/ktlint/releases/tag/0.47.0
8ac3be1
to
0dc4247
Compare
open fun getTextLocationForViolation(node: ASTNode, offset: Int) = | ||
TextLocation(node.startOffset, node.psi.endOffset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is removed because no rules in Ktlint is RunOnRootNodeOnly
. RunOnRootNodeOnly
itself is also deprecated and to be removed in 0.48.0
|
||
private fun ruleShouldOnlyRunOnFileNode(node: ASTNode) = | ||
runOnRootNodeOnly && node !is FileASTNode | ||
private fun ASTNode.isNotDummyElement(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function is renamed to improve readability and consistency
TrailingCommaOnCallSite(config), // in standard ruleset but not enabled by default | ||
TrailingCommaOnDeclarationSite(config), // in standard ruleset but not enabled by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrailingCommaRule
is split into two separate rules - pinterest/ktlint#1555
I would propose to keep them disabled because it may sparkle endless conversation within a medium-large sized team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't they be enforced by default on declaration site in line with the Kotlin coding conventions?
https://kotlinlang.org/docs/coding-conventions.html#trailing-commas
The Kotlin style guide encourages the use of trailing commas at the declaration site
I also think they should be enabled by default for the call site for the reasons outlined in the coding conventions:
- It makes version-control diffs cleaner – as all the focus is on the changed value.
- It makes it easy to add and reorder elements – there is no need to add or delete the comma if you manipulate elements.
It's easy to disable for teams that don't want this. I don't think there's a strong reason to deviate from ktlint's default behaviour - and anyone using ktlint directly would have to have the same conversation if they don't like them. It's also easy to disable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a strong reason to deviate from ktlint's default behaviour
Agree on being consistent with KtLint's behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me keep this disabled for now in a separate PR because it will cause at least 200+ violations across the codebase - I will create a separate PR to demonstrate what it looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5386 is the PR to be consistent with ktlint
Shouldn't they be enforced by default on declaration site in line with the Kotlin coding conventions?
Yes, and ktlint's default configuration still diverges from kotlin coding convention. We could configure these rules in a way that conforms to the kotlin coding convention, namely:
- TrailingCommaOnDeclarationSite: active = true, useTrailingCommaOnDeclarationSite = true
- TrailingCommaOnDeclarationSite: active = false
getSortedRules().forEach { rule -> | ||
rule.visit(root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to move more logic into FormattingRule
itself to prepare for #5192 (comment)
0dc4247
to
e52a66b
Compare
Codecov Report
@@ Coverage Diff @@
## main #5312 +/- ##
============================================
- Coverage 86.11% 86.09% -0.02%
+ Complexity 3643 3637 -6
============================================
Files 515 516 +1
Lines 12085 12098 +13
Branches 2161 2156 -5
============================================
+ Hits 10407 10416 +9
- Misses 609 613 +4
Partials 1069 1069
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -79,15 +79,19 @@ class AnnotationExcluderSpec(private val env: KotlinCoreEnvironment) { | |||
@Test | |||
fun `should exclude when the annotation was found with SplitPattern`() { | |||
val (file, ktAnnotation) = createKtFile("@SinceKotlin") | |||
val excluder = @Suppress("DEPRECATION") AnnotationExcluder(file, SplitPattern("SinceKotlin")) | |||
|
|||
@Suppress("DEPRECATION") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seems like a false positive from ktlint
, isn't it? They are forcing you to increase the annotation scope.
@@ -179,11 +179,14 @@ formatting: | |||
StringTemplate: | |||
active: true | |||
autoCorrect: true | |||
TrailingComma: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of a breaking change. We should note it. Or adding it to the deprecation list. We don't have a way to deprecated plugin properties... we could use the "standard" one as a workaround for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do - I made this breaking change in ktlint 🙈 Let me add it to the deprecation list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to deprecation.properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it won't work. deprecation.properties
only takes care of deprecated rule properties, not the legacy properties that don't work
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good to me, modulo the open comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just need to match the default config with ktlint.
With regards to #5312 (comment), it looks like ktlint added a test specifically to ensure that annotation with parameters on expressions are put at a separate line pinterest/ktlint@069583e I don't hold a strong opinion on this, as it does not conflict with Kotlin official coding convention. |
Fixes #5281
Release note:
Majority of the changes are: