Skip to content

Commit

Permalink
Fixed IndentationRule (#1760)
Browse files Browse the repository at this point in the history
### What's done:
- Fixed bug related to string templates starting with new line.

It's part of #1737
  • Loading branch information
DrAlexD committed Oct 5, 2023
1 parent 2c10a00 commit 6cf2882
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtFileElementType

import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.math.abs
import kotlin.reflect.KCallable

import java.util.ArrayDeque as Stack
Expand Down Expand Up @@ -226,8 +225,8 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
addException(exceptionInitiatorNode, expectedIndent - indentError.expected, checkResult.includeLastChild)
}

if (astNode.treeParent.elementType == LONG_STRING_TEMPLATE_ENTRY && indentError.expected != indentError.actual) {
addException(astNode.treeParent, abs(indentError.expected - indentError.actual), false)
if (astNode.treeParent.elementType == LONG_STRING_TEMPLATE_ENTRY && astNode.treeNext.elementType != LONG_TEMPLATE_ENTRY_END) {
addException(astNode.treeParent, SINGLE.level() * configuration.indentationSize, false)
}

val alignedOpeningAndClosingQuotes = hasAlignedOpeningAndClosingQuotes(astNode, indentError.actual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.saveourtool.diktat.util.FixTestBase
import generated.WarningNames
import org.assertj.core.api.Assertions.assertThat
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -57,7 +56,6 @@ class IndentationRuleFixTest : FixTestBase("test/paragraph3/indentation",
fixAndCompare("IndentationParametersExpected.kt", "IndentationParametersTest.kt")
}

@Disabled("https://github.com/saveourtool/diktat/issues/1737")
@Test
@Tag(WarningNames.WRONG_INDENTATION)
fun `indentation rule - example 1`() {
Expand Down
23 changes: 11 additions & 12 deletions examples/gradle-kotlin-dsl/src/main/kotlin/AnotherTest.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package whate.ver

fun String.createPluginConfig() {
val pluginConfig = TomlDecoder.decode<T>(
serializer(),
fakeFileNode,
DecoderConf()
)
pluginConfig.configLocation = this.toPath()
pluginConfig.prop1 = property1
// comment1
pluginConfig.configLocation2 = this.toPath()
// comment2
pluginConfig.prop2 = property2
val pluginConfig = TomlDecoder.decode<T>(
serializer(),
fakeFileNode,
DecoderConf()
)
pluginConfig.configLocation = this.toPath()
pluginConfig.prop1 = property1
// comment1
pluginConfig.configLocation2 = this.toPath()
// comment2
pluginConfig.prop2 = property2
}

12 changes: 6 additions & 6 deletions examples/gradle-kotlin-dsl/src/main/kotlin/Test.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package incorrect

class incorrectname: Exception() {
fun INCORRECT_FUNCTION() {
throw Exception()
}
fun INCORRECT_FUNCTION() {
throw Exception()
}

// fun myCommentedFunction() {
// }
// fun myCommentedFunction() {
// }

val Incorrect_Val = 5
val Incorrect_Val = 5

}

0 comments on commit 6cf2882

Please sign in to comment.