-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supertypes should be on separate lines (#1902)
* ### What's done: - Fixed bug where more than two supertypes should be on separate lines - Added warning and smoke tests Closes #1890 --------- Co-authored-by: Andrey Kuleshov <[email protected]>
- Loading branch information
1 parent
66e03a1
commit 8f4b730
Showing
12 changed files
with
262 additions
and
38 deletions.
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
6 changes: 6 additions & 0 deletions
6
diktat-cli/src/test/resources/test/smoke/src/main/kotlin/NewlinesAfterInterfacesExpected.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,6 @@ | ||
package com.saveourtool.diktat | ||
|
||
class A<K : Any, P : Any, G : Any> : | ||
B<K>(), | ||
C<P>, | ||
D<G> {} |
3 changes: 3 additions & 0 deletions
3
diktat-cli/src/test/resources/test/smoke/src/main/kotlin/NewlinesAfterInterfacesTest.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,3 @@ | ||
package com.saveourtool.diktat | ||
|
||
class A<K : Any, P : Any, G : Any> : B<K>(), C<P>, D<G> {} |
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
86 changes: 86 additions & 0 deletions
86
...t-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter3/SuperClassListWarnTest.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,86 @@ | ||
package com.saveourtool.diktat.ruleset.chapter3 | ||
|
||
import com.saveourtool.diktat.common.config.rules.DIKTAT_RULE_SET_ID | ||
import com.saveourtool.diktat.ruleset.constants.Warnings.WRONG_NEWLINES | ||
import com.saveourtool.diktat.ruleset.rules.chapter3.files.NewlinesRule | ||
import com.saveourtool.diktat.util.LintTestBase | ||
|
||
import com.saveourtool.diktat.api.DiktatError | ||
import com.saveourtool.diktat.ruleset.constants.Warnings | ||
import generated.WarningNames | ||
import org.junit.jupiter.api.Tag | ||
import org.junit.jupiter.api.Test | ||
|
||
class SuperClassListWarnTest : LintTestBase(::NewlinesRule) { | ||
private val ruleId = "$DIKTAT_RULE_SET_ID:${NewlinesRule.NAME_ID}" | ||
|
||
@Test | ||
@Tag(WarningNames.WRONG_NEWLINES) | ||
fun `superclass list on the same line`() { | ||
lintMethod( | ||
""" | ||
|package com.saveourtool.diktat | ||
| | ||
|class A<K : Any, P : Any, G : Any> : B<K>(), C<P>, D<G> {} | ||
""".trimMargin(), | ||
DiktatError(3, 38, ruleId, "${Warnings.WRONG_NEWLINES.warnText()} supertype list entries should be placed on different lines in declaration of <A>", true), | ||
) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.WRONG_NEWLINES) | ||
fun `first superclass also on a new line`() { | ||
lintMethod( | ||
""" | ||
|package com.saveourtool.diktat | ||
| | ||
|class A<K : Any, P : Any, G : Any> : B<K>(), | ||
|C<P>, | ||
|D<G> {} | ||
""".trimMargin(), | ||
DiktatError(3, 38, ruleId, "${Warnings.WRONG_NEWLINES.warnText()} supertype list entries should be placed on different lines in declaration of <A>", true), | ||
) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.WRONG_NEWLINES) | ||
fun `superclass list of 2 elements on the same line`() { | ||
lintMethod( | ||
""" | ||
|package com.saveourtool.diktat | ||
| | ||
|class A<K : Any, P : Any, G : Any> : B<K>(), C<P> {} | ||
""".trimMargin(), | ||
) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.WRONG_NEWLINES) | ||
fun `superclass list on separate lines`() { | ||
lintMethod( | ||
""" | ||
|package com.saveourtool.diktat | ||
| | ||
|class A<K : Any, P : Any, G : Any> : | ||
|B<K>(), | ||
|C<P>, | ||
|D<G> {} | ||
""".trimMargin(), | ||
) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.WRONG_NEWLINES) | ||
fun `superclass list different whitespaces`() { | ||
lintMethod( | ||
""" | ||
|package com.saveourtool.diktat | ||
| | ||
|class A<K : Any, P : Any, G : Any> : | ||
|B<K>(), | ||
| C<P>, D<G> {} | ||
""".trimMargin(), | ||
DiktatError(4, 1, ruleId, "${Warnings.WRONG_NEWLINES.warnText()} supertype list entries should be placed on different lines in declaration of <A>", true), | ||
) | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...-rules/src/test/resources/test/paragraph3/newlines/SuperClassListOnTheSameLineExpected.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,6 @@ | ||
package test.paragraph3.newlines | ||
|
||
class A<K : Any, P : Any, G : Any> : | ||
B<K>(), | ||
C<P>, | ||
D<G> {} |
3 changes: 3 additions & 0 deletions
3
diktat-rules/src/test/resources/test/paragraph3/newlines/SuperClassListOnTheSameLineTest.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,3 @@ | ||
package test.paragraph3.newlines | ||
|
||
class A<K : Any, P : Any, G : Any> : B<K>(), C<P>, D<G> {} |