Skip to content

Commit

Permalink
### Whats added: (#1389)
Browse files Browse the repository at this point in the history
* Corrected analysis if maximum lineLength drop in first symbol last word long binary expression
* Delete 2 unused test in DiktatSmokeTest
* Added 1 fix test split long binary expression with maximum lineLength = offset last word in binary expression

### Issue(#1385)
  • Loading branch information
Arrgentum authored Jun 22, 2022
1 parent bc8d5d9 commit 57af86c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
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.

0 comments on commit 57af86c

Please sign in to comment.