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
Bump KtLint to 0.44.0 and add UnnecessaryParenthesesBeforeTrailingLamda rule #4630
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
be9b084
Bump KtLint to 0.44.0 and add UnnecessaryParenthesesBeforeTrailingLam…
kvn-stgl 681a603
implement new RunAsLateAsPossible and RunOnRootNodeOnly annotations
kvn-stgl 41a291e
use internal ruleShouldOnlyRunOnFileNode method
kvn-stgl e95f358
revoke line wrap
kvn-stgl 3b42df7
fix indentation errors
kvn-stgl 65ba52f
deprecate indentSize in ParameterListWrapping.kt
kvn-stgl 39727c5
implement microutilsKotlinLoggingJvm and fake EDITOR_CONFIG_USER_DATA…
kvn-stgl 6ca5949
remove duplicate
kvn-stgl File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import io.gitlab.arturbosch.detekt.api.internal.ActiveByDefault | |
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable | ||
import io.gitlab.arturbosch.detekt.api.internal.Configuration | ||
import io.gitlab.arturbosch.detekt.formatting.FormattingRule | ||
import io.gitlab.arturbosch.detekt.formatting.INDENT_SIZE_KEY | ||
import io.gitlab.arturbosch.detekt.formatting.MAX_LINE_LENGTH_KEY | ||
|
||
/** | ||
|
@@ -21,14 +20,15 @@ class ParameterListWrapping(config: Config) : FormattingRule(config) { | |
override val wrapping = ParameterListWrappingRule() | ||
override val issue = issueFor("Detects mis-aligned parameter lists") | ||
|
||
@Configuration("indentation size") | ||
private val indentSize by config(4) | ||
Comment on lines
-24
to
-25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be deprecated instead |
||
|
||
@Configuration("maximum line length") | ||
private val maxLineLength: Int by configWithAndroidVariants(120, 100) | ||
|
||
@Configuration("indentation size") | ||
@Deprecated("`indentSize` is ignored by KtLint and will have no effect") | ||
@Suppress("UnusedPrivateMember") | ||
private val indentSize by config(4) | ||
|
||
override fun overrideEditorConfig() = mapOf( | ||
INDENT_SIZE_KEY to indentSize, | ||
MAX_LINE_LENGTH_KEY to maxLineLength | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
...itlab/arturbosch/detekt/formatting/wrappers/UnnecessaryParenthesesBeforeTrailingLambda.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.gitlab.arturbosch.detekt.formatting.wrappers | ||
|
||
import com.pinterest.ktlint.core.api.FeatureInAlphaState | ||
import com.pinterest.ktlint.ruleset.experimental.UnnecessaryParenthesesBeforeTrailingLambdaRule | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable | ||
import io.gitlab.arturbosch.detekt.formatting.FormattingRule | ||
|
||
/** | ||
* See <a href="https://ktlint.github.io/#rule-spacing">ktlint-website</a> for documentation. | ||
*/ | ||
@OptIn(FeatureInAlphaState::class) | ||
@AutoCorrectable(since = "1.20.0") | ||
class UnnecessaryParenthesesBeforeTrailingLambda(config: Config) : FormattingRule(config) { | ||
|
||
override val wrapping = UnnecessaryParenthesesBeforeTrailingLambdaRule() | ||
override val issue = issueFor("Ensures there are no unnecessary parentheses before a trailing lambda") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ class FormattingRuleSpec { | |
""" | ||
fun main() | ||
= Unit | ||
""", | ||
""", | ||
expectedPath | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../io/gitlab/arturbosch/detekt/formatting/UnnecessaryParenthesesBeforeTrailingLambdaSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.gitlab.arturbosch.detekt.formatting | ||
|
||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.formatting.wrappers.UnnecessaryParenthesesBeforeTrailingLambda | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* Test cases were used directly from KtLint to verify the wrapper rule: | ||
* | ||
* https://github.com/pinterest/ktlint/blob/master/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/UnnecessaryParenthesesBeforeTrailingLambdaRuleTest.kt | ||
*/ | ||
class UnnecessaryParenthesesBeforeTrailingLambdaSpec { | ||
|
||
@Test | ||
fun `reports unnecessary parentheses before trailing lambda`() { | ||
val code = """ | ||
fun countDash(input: String) = | ||
"some-string".count() { it == '-' } | ||
""".trimIndent() | ||
assertThat(UnnecessaryParenthesesBeforeTrailingLambda(Config.empty).lint(code)).hasSize(1) | ||
} | ||
|
||
@Test | ||
fun `does not report unnecessary parentheses before trailing lambda`() { | ||
val code = """ | ||
fun countDash(input: String) = | ||
"some-string".count { it == '-' } | ||
""".trimIndent() | ||
assertThat(UnnecessaryParenthesesBeforeTrailingLambda(Config.empty).lint(code)).isEmpty() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Duplicated?
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.
Fuuuu