-
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
Feature. Enable confiuring of ktlint reporter in gradle plugin #724
Conversation
### What's done: * Logic began
### What's done: * Fixed bugs
### What's done: * Added tests
Codecov Report
@@ Coverage Diff @@
## master #724 +/- ##
============================================
- Coverage 80.17% 80.15% -0.02%
- Complexity 1913 1922 +9
============================================
Files 91 91
Lines 4937 4958 +21
Branches 1580 1584 +4
============================================
+ Hits 3958 3974 +16
- Misses 238 241 +3
- Partials 741 743 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@@ -50,6 +53,21 @@ open class DiktatJavaExecTaskBase @Inject constructor( | |||
} else { | |||
main = "com.pinterest.ktlint.Main" | |||
} | |||
diktatExtension.reporter = when(diktatExtension.reporterType) { |
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.
Actually, I think it should be passed to ktlint via CLI argument like --reporter=json
. Adding classpath dependency might even be not needed (depending on whether they already include all reporters in ktlint.jar
"html" -> { | ||
diktatConfiguration.dependencies.add(project.dependencies.create("com.pinterest.ktlint:ktlint-reporter-html:$KTLINT_VERSION")) | ||
diktatConfiguration.dependencies.remove(diktatConfiguration.dependencies.find { it.name == "ktlint-reporter-plain" }) | ||
HtmlReporter(System.out) |
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.
We also should support custom output files for reporters. Please check out ktlint's docs regarding supported options for different reporters.
.../src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginFunctionalTest.kt
Outdated
Show resolved
Hide resolved
### What's done: * Fixed bugs
### What's done: * Logic remade * Added tests
.../src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginFunctionalTest.kt
Outdated
Show resolved
Hide resolved
.../src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginFunctionalTest.kt
Outdated
Show resolved
Hide resolved
@@ -50,6 +54,9 @@ open class DiktatJavaExecTaskBase @Inject constructor( | |||
} else { | |||
main = "com.pinterest.ktlint.Main" | |||
} | |||
if (diktatExtension.reporterType == "html") { |
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.
Is it needed? If yes, why onlu for html?
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.
Others are already included in ktlint (plain, json, checkstyle)
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.
Oh, ok, that's strange. Leave a comment in code to explain this, pls.
"json" -> flag.append("--reporter=json") | ||
"html" -> flag.append("--reporter=html") | ||
"checkstyle" -> flag.append("--reporter=checkstyle") | ||
else -> flag.append("--reporter=plain") |
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.
I think they already have baseline
reporter (or was it added in 0.40.0?) Still, let's log a warning if unknown reporter is specified and then fallback to plain.
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.
Also, one could imagine a use case, when end user adds a custom reporter as a dependency in our plugin's configuration and then specifies it's name (need to see, how it's loaded in ktlint). So it might be more versatile to allow arbitrary names here and then let ktlint validate them.
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.
We need to specify it(--reporter=plain
) here if a user will provide us an output here
diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt
Show resolved
Hide resolved
### What's done: * Fixed bugs
Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome) | ||
val file = testProjectDir.root.walkTopDown().filter { it.name == "test.txt" }.first() | ||
val file = testProjectDir.root.walkTopDown().filter { it.name == "test.txt" }.firstOrNull() | ||
Assertions.assertTrue(file != null) |
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.
Does kotlin.test.assertNotNull
work in this case? It should have contract to enable smart cast of file
to non-nullable type.
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
@@ -55,10 +56,10 @@ class DiktatGradlePluginFunctionalTest { | |||
val diktatCheckBuildResult = result.task(":$DIKTAT_CHECK_TASK") | |||
requireNotNull(diktatCheckBuildResult) | |||
Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome) | |||
val file = testProjectDir.root.walkTopDown().filter { it.name == "test.txt" }.firstOrNull() | |||
Assertions.assertTrue(file != null) | |||
assertNotNull(testProjectDir.root.walkTopDown().filter { it.name == "test.txt" }.first()) |
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.
Is this line needed?
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.
No, it doesn't. Fixed
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
….com/cqfn/diKTat into feature/gradle-ktlint-reporter(#714)
What's done
This pull request closes #714