Skip to content
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

Merged
merged 15 commits into from
Jan 27, 2021

Conversation

aktsay6
Copy link
Collaborator

@aktsay6 aktsay6 commented Jan 25, 2021

What's done

  • Added configuring
  • Added tests

This pull request closes #714

### What's done:
  * Logic began
### What's done:
  * Fixed bugs
### What's done:
  * Added tests
@aktsay6 aktsay6 added the plugins Plugins for build systems to allow them to run diktat label Jan 25, 2021
@aktsay6 aktsay6 requested review from petertrr and kentr0w January 25, 2021 08:55
@aktsay6 aktsay6 marked this pull request as draft January 25, 2021 08:55
@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Merging #724 (cf1fb82) into master (c4c32b2) will decrease coverage by 0.01%.
The diff coverage is 78.26%.

Impacted file tree graph

@@             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     
Flag Coverage Δ Complexity Δ
unittests 80.15% <78.26%> (-0.02%) 0.00 <9.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...rg/cqfn/diktat/plugin/gradle/DiktatGradlePlugin.kt 100.00% <ø> (ø) 2.00 <0.00> (ø)
...qfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt 88.46% <76.19%> (-4.53%) 25.00 <7.00> (+8.00) ⬇️
...n/org/cqfn/diktat/plugin/gradle/DiktatExtension.kt 100.00% <100.00%> (ø) 8.00 <2.00> (+1.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4c32b2...cf1fb82. Read the comment docs.

@@ -50,6 +53,21 @@ open class DiktatJavaExecTaskBase @Inject constructor(
} else {
main = "com.pinterest.ktlint.Main"
}
diktatExtension.reporter = when(diktatExtension.reporterType) {
Copy link
Member

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)
Copy link
Member

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.

### What's done:
  * Fixed bugs
### What's done:
  * Logic remade
  * Added tests
@aktsay6 aktsay6 marked this pull request as ready for review January 26, 2021 08:55
@aktsay6 aktsay6 requested review from petertrr and kentr0w January 26, 2021 08:55
@@ -50,6 +54,9 @@ open class DiktatJavaExecTaskBase @Inject constructor(
} else {
main = "com.pinterest.ktlint.Main"
}
if (diktatExtension.reporterType == "html") {
Copy link
Member

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?

Copy link
Collaborator Author

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)

Copy link
Member

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")
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

@aktsay6 aktsay6 Jan 26, 2021

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

### 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)
Copy link
Member

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
@aktsay6 aktsay6 requested a review from petertrr January 26, 2021 15:02
@@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line needed?

Copy link
Collaborator Author

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

@aktsay6 aktsay6 merged commit 00a00ae into master Jan 27, 2021
@aktsay6 aktsay6 deleted the feature/gradle-ktlint-reporter(#714) branch January 27, 2021 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins Plugins for build systems to allow them to run diktat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable confiuring of ktlint reporter in gradle plugin
3 participants