Skip to content

Corrected analysis if maximum lineLength drop in first symbol of the last word long binary expression #1389

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

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
splitOffset?.let {
val parentIsBiExprOrParenthesized = parent.treeParent.elementType in listOf(BINARY_EXPRESSION, PARENTHESIZED)
val parentIsFunOrProperty = parent.treeParent.elementType in listOf(FUN, PROPERTY)
if (parentIsBiExprOrParenthesized || (parentIsFunOrProperty && splitOffset >= configuration.lineLength)) {
if (parentIsBiExprOrParenthesized || (parentIsFunOrProperty && splitOffset > configuration.lineLength)) {
parent = parent.treeParent
} else {
return checkBinaryExpression(parent, configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class LineLengthFixTest : FixTestBase("test/paragraph3/long_line", ::LineLength)
RulesConfig(LONG_LINE.name, true,
mapOf("lineLength" to "20"))
)
private val rulesConfigListErrorLineLength1: List<RulesConfig> = listOf(
RulesConfig(LONG_LINE.name, true,
mapOf("lineLength" to "151"))
)

@Test
fun `should fix long comment`() {
Expand Down Expand Up @@ -98,4 +102,9 @@ class LineLengthFixTest : FixTestBase("test/paragraph3/long_line", ::LineLength)
fun `fix long value arguments list`() {
fixAndCompare("LongValueArgumentsListExpected.kt", "LongValueArgumentsListTest.kt", rulesConfigListLineLength)
}

@Test
fun `fix bin expression first symbol last word`() {
fixAndCompare("LongBinaryExpressionLastWordExpected.kt", "LongBinaryExpressionLastWordTest.kt", rulesConfigListErrorLineLength1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test.paragraph3.long_line

val elem1 = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc &&
!isReferenceExpressionWithSameName

val elem2 = (hasExplicitNotUnitReturnType || isFunWithExpressionBody1 && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc &&
isReferenceExpressionWithSameName

val elem3 = "sdfghjkl;kjhgfdsdfghjkllkjhgfdsfghjkl;';lkiuytrdfghjklkjuhgfdsdfghnm,.lkjhgfdcvbnm,.lkjhgfdcvbnm,.lkjhgfdxcvbnm,lkjhgfdxcvbnm,lkgfdcvm" +
"hgfjdgdsvfmg.k,gfdsgbh.gkhjhmhgdf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test.paragraph3.long_line

val elem1 = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName

val elem2 = (hasExplicitNotUnitReturnType || isFunWithExpressionBody1 && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && isReferenceExpressionWithSameName

val elem3 = "sdfghjkl;kjhgfdsdfghjkllkjhgfdsfghjkl;';lkiuytrdfghjklkjuhgfdsdfghnm,.lkjhgfdcvbnm,.lkjhgfdcvbnm,.lkjhgfdxcvbnm,lkjhgfdxcvbnm,lkgfdcvm" + "hgfjdgdsvfmg.k,gfdsgbh.gkhjhmhgdf"

This file was deleted.

This file was deleted.