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

Unable to specify any reporter if ktlint version is bigger than "0.9.x" #28

Closed
leinardi opened this issue Oct 24, 2017 · 6 comments
Closed
Labels

Comments

@leinardi
Copy link

leinardi commented Oct 24, 2017

There seems to be a bug that prevents you from using a custom reporter when ktlint version is bigger than "0.9.x", eg. "0.10.1".

This is due to comparing strings instead of integers:

private fun isReportAvailable(version: String, availableSinceVersion: String): Boolean {
    val versionsNumbers = version.split('.')
    val reporterVersionNumbers = availableSinceVersion.split('.')
    return versionsNumbers[0] >= reporterVersionNumbers[0] &&
            versionsNumbers[1] >= reporterVersionNumbers[1] &&
            versionsNumbers[2] >= reporterVersionNumbers[2]
}

To reproduce the issue you can use this configuration:

ktlint {
    version = "0.10.1"
    debug = true
    verbose = false
    reporter = "json"
    ignoreFailures = true
}

The output is:

> Task :app:ktlintItalyCheck
[DEBUG] Discovered ruleset "standard"
[DEBUG] Discovered reporter "plain"
[DEBUG] Discovered reporter "json"
[DEBUG] Discovered reporter "checkstyle"
[DEBUG] Initializing "plain" reporter with {verbose=false}
[DEBUG] {} loaded from .editorconfig
[...]
@JLLeitschuh
Copy link
Owner

@Tapchicoma you want to take a crack at this one? Can you add some simple Junit tests that cover this too for us?

@Tapchicoma
Copy link
Collaborator

@JLLeitschuh yeah, I will take a look.

In version 0.10.0 ktlint introduced multiple reporters support. I think this is the cause.

@JLLeitschuh
Copy link
Owner

JLLeitschuh commented Oct 24, 2017

@Tapchicoma Hijacking this issue for a second, come chat with me either in the gitter chat or find me in the Kotlin Slack (slack is better for me).

@leinardi
Copy link
Author

Quick and dirty fix:

private fun isReportAvailable(version: String, availableSinceVersion: String): Boolean {
    val versionsNumbers = version.split('.')
    val reporterVersionNumbers = availableSinceVersion.split('.')
    return versionsNumbers[0].toInt() >= reporterVersionNumbers[0].toInt() &&
            versionsNumbers[1].toInt() >= reporterVersionNumbers[1].toInt() &&
            versionsNumbers[2].toInt() >= reporterVersionNumbers[2].toInt()
}

@JLLeitschuh
Copy link
Owner

We may want to consider doing our parsing with this library:
https://github.com/zafarkhaja/jsemver.
Might be overkill though.

@Tapchicoma
Copy link
Collaborator

@leinardi little improve your fix, but solution is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants