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

Add output report and report type. #18

Merged
merged 3 commits into from
Aug 15, 2017

Conversation

Tapchicoma
Copy link
Collaborator

Now plugin outputs check task results to build/reports/ktlint/ folder.
Also user can select one of supported report types.
Fixes #13

Signed-off-by: Yahor Berdnikau egorr.berd@gmail.com

Now plugin outputs check task results to build/reports/ktlint/ folder.
Also user can select one of supported report types.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
@Tapchicoma
Copy link
Collaborator Author

One of the minor problems so far - now there is no plugin output in the console. User needs to open report file to see the errors.

I've tried to use TeeOutputStream to output both to the console and a file, but then ktlint, for example, for checkstyle reporter, prints out in the console in xml format that is also not looking good.

@Tapchicoma
Copy link
Collaborator Author

Opened an issue for it: pinterest/ktlint#71

/**
* Report output format.
*
* Possible values are: plain, checkstyle, json.
Copy link
Owner

@JLLeitschuh JLLeitschuh Aug 4, 2017

Choose a reason for hiding this comment

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

Do want to turn this into an enum?

Copy link
Owner

@JLLeitschuh JLLeitschuh Aug 4, 2017

Choose a reason for hiding this comment

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

Edit: probably not in case more are added and this plugin isn't updated.

Copy link
Owner

Choose a reason for hiding this comment

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

Can you set it to multiple output formats or only one at a time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only one at a time.

Enum may be not a bad idea, but harder to maintain - like adding a new one and check supported version.

Copy link
Owner

Choose a reason for hiding this comment

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

Put supported version in the enum along with the file extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've introduced reporter enum. See 5fd454c.


private fun createCheckTaskOutputDir(target: Project, extension: KtlintExtension): File {
val reportsDir = File(target.buildDir, "reports/ktlint")
reportsDir.mkdirs()
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use org.gradle.util.GFileUtils.mkdirs instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 82ec747.

"checkstyle" -> "xml"
"json" -> "json"
else -> "txt"
}
Copy link
Owner

Choose a reason for hiding this comment

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

What if a different output format is added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then txt will be used. Again I can introduce enum for this reporters and define there file extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now plugin uses enum for defining possible variants.

private fun addReporter(extension: KtlintExtension, runArgs: MutableSet<String>) {
if (isReportAvailable(extension.version)) {
runArgs.add("--reporter=${extension.reporter}")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Log a debug message in the else case. It isn't really a warning but it may help someone trying to debug why their isn't a report showing up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 82ec747.

Copy link
Owner

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

See the various comments I've left. On the whole this looks really good. Thanks!

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
Apply reporter in one place - on check task creation.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
@Tapchicoma
Copy link
Collaborator Author

@JLLeitschuh please review updated PR.

this.args("--reporter=${extension.reporter.reporterName}")
this.standardOutput = createReportOutputDir(target, extension).outputStream()
} else {
target.logger.info("Reporter is not available in this ktlint version")
Copy link
Owner

@JLLeitschuh JLLeitschuh Aug 15, 2017

Choose a reason for hiding this comment

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

Perhaps making this level debug would be more appropriate? What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've also initially thought about debug level, but gradle, on debug level, produces too much output. This message can be missed. And this message, IMHO, is more informational, then debug.

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds good!

@JLLeitschuh
Copy link
Owner

Are you happy with where this is? Should this be merged?

@Tapchicoma
Copy link
Collaborator Author

@JLLeitschuh yes, it is ready to be merged.

Will do improvement when ktlint will add reporter output param.

@JLLeitschuh JLLeitschuh merged commit e00c266 into JLLeitschuh:master Aug 15, 2017
@Tapchicoma Tapchicoma deleted the add-output-formats branch October 5, 2017 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants