-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fixed smoke tests #1769
Fixed smoke tests #1769
Conversation
### What's done: - fixed rule PACKAGE_NAME_MISSING It closes #1737
JUnit Tests (Windows, EnricoMi/publish-unit-test-result-action@v2) 164 files ±0 164 suites ±0 5m 14s ⏱️ - 2m 40s Results for commit a1a32ce. ± Comparison against base commit c1c3cab. ♻️ This comment has been updated with latest results. |
JUnit Tests (macOS, EnricoMi/publish-unit-test-result-action@v2) 164 files ±0 164 suites ±0 7m 4s ⏱️ +47s Results for commit a1a32ce. ± Comparison against base commit c1c3cab. ♻️ This comment has been updated with latest results. |
...ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt
Show resolved
Hide resolved
...at-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter3/FileStructureRuleFixTest.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/PackageNaming.kt
Fixed
Show fixed
Hide fixed
Can be useful for testing: Index: diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/KtLintRuleWrapper.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/KtLintRuleWrapper.kt b/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/KtLintRuleWrapper.kt
--- a/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/KtLintRuleWrapper.kt (revision 39de04c9bc487b601dd1081f70d1843c974fe558)
+++ b/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/KtLintRuleWrapper.kt (date 1698919199521)
@@ -8,6 +8,13 @@
import com.pinterest.ktlint.rule.engine.core.api.RuleId
import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
+import org.jetbrains.kotlin.psi.stubs.elements.KtFileElementType
+import java.nio.file.Paths
+import java.util.concurrent.atomic.AtomicInteger
+import kotlin.io.path.listDirectoryEntries
+import kotlin.io.path.name
+import kotlin.io.path.readText
+import kotlin.io.path.writeText
private typealias EmitType = (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
@@ -27,11 +34,37 @@
node: ASTNode,
autoCorrect: Boolean,
emit: EmitType,
- ) = rule.invoke(node, autoCorrect) { offset, errorMessage, canBeAutoCorrected ->
- emit.invoke(offset, errorMessage.correctErrorDetail(canBeAutoCorrected), canBeAutoCorrected)
- }
+ ) {
+ node.dumpNodeIfRequired(rule, true)
+ rule.invoke(node, autoCorrect) { offset, errorMessage, canBeAutoCorrected ->
+ emit.invoke(offset, errorMessage.correctErrorDetail(canBeAutoCorrected), canBeAutoCorrected)
+ }
+ }
+
+ override fun afterVisitChildNodes(node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) {
+ super.afterVisitChildNodes(node, autoCorrect, emit)
+ node.dumpNodeIfRequired(rule, false)
+ }
+
companion object {
+ private val counter = AtomicInteger(1000)
+
+ private val folder = Paths.get("d:\\projects\\diktat\\test")
+
+ private fun ASTNode.dumpNodeIfRequired(rule: DiktatRule, isBefore: Boolean) {
+ if (elementType == KtFileElementType.INSTANCE) {
+ val newContent = prettyPrint()
+ val latestContent = folder.listDirectoryEntries()
+ .find { it.name.startsWith("${counter.get()}") }
+ ?.readText()
+ if (latestContent != newContent) {
+ folder.resolve("${counter.incrementAndGet()}_${if (isBefore) "before" else "after"}_${rule.javaClass.simpleName}.txt")
+ .writeText(newContent)
+ }
+ }
+ }
+
private val about: About = About(
maintainer = "Diktat",
repositoryUrl = "https://github.com/saveourtool/diktat",
@@ -73,5 +106,29 @@
* @return a rule to which a logic is delegated
*/
internal fun Rule.unwrap(): DiktatRule = (this as? KtLintRuleWrapper)?.rule ?: error("Provided rule ${javaClass.simpleName} is not wrapped by diktat")
+
+
+ /**
+ * Converts this AST node and all its children to pretty string representation
+ */
+ @Suppress("AVOID_NESTED_FUNCTIONS")
+ fun ASTNode.prettyPrint(level: Int = 0, maxLevel: Int = -1): String {
+ /**
+ * AST operates with \n only, so we need to build the whole string representation and then change line separator
+ */
+ fun ASTNode.doPrettyPrint(level: Int, maxLevel: Int): String {
+ val result = StringBuilder("${this.elementType}: \"${this.text}\"").append('\n')
+ if (maxLevel != 0) {
+ this.getChildren(null).forEach { child ->
+ result.append(
+ "${"-".repeat(level + 1)} " +
+ child.doPrettyPrint(level + 1, maxLevel - 1)
+ )
+ }
+ }
+ return result.toString()
+ }
+ return doPrettyPrint(level, maxLevel).replace("\n", System.lineSeparator())
+ }
}
} |
and fix for new line after package when import_list is empty
diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/DiktatRuleSetFactoryImpl.kt
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #1769 +/- ##
============================================
- Coverage 78.25% 77.99% -0.27%
- Complexity 2409 2415 +6
============================================
Files 126 127 +1
Lines 8453 8511 +58
Branches 2149 2152 +3
============================================
+ Hits 6615 6638 +23
- Misses 880 914 +34
- Partials 958 959 +1
|
### What's done: - added a duplicated Code from KTLint - added fix before calling warn in warnAndFix scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests passed, good
What's done:
It closes #1737
It closes #1538
It closes #1774