Skip to content

Commit

Permalink
- added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DrAlexD committed Oct 6, 2023
1 parent e24ce4b commit 8b7bc55
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
override fun logic(node: ASTNode) {
var isFixedSmthInPreviousStep: Boolean

// loop that trying to fix LineLength rule warnings until warnings run out
do {
isFixedSmthInPreviousStep = false

Expand Down Expand Up @@ -149,12 +150,16 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
val textLenAfterFix = node.textLength
val blankLinesAfterFix = node.text.lines().size - countCodeLines(node)

// checking that any fix may have been made
isFixedSmthInChildNode = fixableType !is None

// for cases when text doesn't change, and then we need to stop fixes
if (textBeforeFix == textAfterFix) {
isFixedSmthInChildNode = false
}

// for cases when fixes don't stop and start generate blank lines due to adding \n at each fix step
// then we need to make unFix last change and stop fixes
if (blankLinesAfterFix > blankLinesBeforeFix) {
isFixedSmthInChildNode = false
fixableType.unFix()
Expand Down Expand Up @@ -548,6 +553,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
node.treeParent.removeChild(node.treePrev)
}

// for cases when property has multiline initialization, and then we need to move comment before first line
val newLineNodeOnPreviousLine = if (node.treeParent.elementType == PROPERTY) {
node.treeParent.treeParent.findChildrenMatching {
it.elementType == WHITE_SPACE && node.treeParent.treeParent.isChildAfterAnother(node.treeParent, it) && it.textContains('\n')
Expand Down Expand Up @@ -744,11 +750,11 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
}

override fun unFix() {
node.findChildAfter(EQ, WHITE_SPACE)?.let {
if (it.textContains('\n')) {
it.nextSibling()?.let { it2 ->
if (it2.textContains('\n')) {
node.removeChild(it2)
node.findChildAfter(EQ, WHITE_SPACE)?.let { correctWhiteSpace ->
if (correctWhiteSpace.textContains('\n')) {
correctWhiteSpace.nextSibling()?.let { wrongWhiteSpace ->
if (wrongWhiteSpace.textContains('\n')) {
node.removeChild(wrongWhiteSpace)
}
}
}
Expand Down Expand Up @@ -830,11 +836,11 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
}

override fun unFix() {
node.findChildBefore(RPAR, WHITE_SPACE)?.let {
if (it.textContains('\n')) {
it.prevSibling()?.let { it2 ->
if (it2.textContains('\n')) {
node.removeChild(it2)
node.findChildBefore(RPAR, WHITE_SPACE)?.let { correctWhiteSpace ->
if (correctWhiteSpace.textContains('\n')) {
correctWhiteSpace.prevSibling()?.let { wrongWhiteSpace ->
if (wrongWhiteSpace.textContains('\n')) {
node.removeChild(wrongWhiteSpace)
}
}
}
Expand Down

0 comments on commit 8b7bc55

Please sign in to comment.