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

Invalid boolean config values are evaluated silently to false #2045

Closed
kepocnhh opened this issue Oct 21, 2019 · 5 comments
Closed

Invalid boolean config values are evaluated silently to false #2045

kepocnhh opened this issue Oct 21, 2019 · 5 comments
Milestone

Comments

@kepocnhh
Copy link

Expected Behavior

I can use any number of configuration files.

Observed Behavior

If I use 3 or more configuration files, detekt always throws an error when completing a task.

Steps to Reproduce

I use my task:

task<Detekt>("verifyQuality") {
    source = files(subprojects.withPlugin("kotlin").srcDirs("main")).asFileTree
    val configPath = "buildSrc/src/main/resources/detekt/config"
    config.setFrom(
        "$configPath/common.yml",
        "$configPath/comments.yml",
        "$configPath/potential_bugs.yml",
        "$configPath/performance.yml"
    )
    reports {
        html {
            enabled = true
            destination = File(analysisQualityHtmlPath)
        }
        xml.enabled = false
        txt.enabled = false
    }
}

And the service does not note errors in the code, but prints it to the log:
https://gist.github.com/kepocnhh/558c85a50419df1a1db400eb54786d96

Context

This error occurs only if the configuration files are 3 or more. That is, in all other cases, the detekt works:

config.setFrom()

or

config.setFrom("$configPath/common.yml")

or

config.setFrom(
    "$configPath/common.yml",
    "$configPath/comments.yml"
)

or

config.setFrom(
    "$configPath/common.yml",
    "$configPath/performance.yml"
)

or

config.setFrom(
    "$configPath/potential_bugs.yml",
    "$configPath/performance.yml"
)

or

config.setFrom("$configPath/potential_bugs.yml")

common.yml is

build:
  maxIssues: 0

processors:
  active: false

the rest are like that

performance:
  active: true
  ArrayPrimitive:
    active: true

❕ Each configuration file is unique.

Your Environment

java 1.8.0_221
kotlin 1.3.50
detekt 1.1.1
Gradle 5.5.1
macOS Mojave Version 10.14.6 (18G87)

@arturbosch
Copy link
Member

Hey, thanks for reporting this.

The error message is:

Analyzing '/Users/username/dev/kotlin/test/ContinuousStuffExperience/lib/src/main/kotlin/continuous/stuff/experience/OtherLib1Class.kt' led to an exception.
The original exception message was: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
...
io.gitlab.arturbosch.detekt.api.ConfigAware$DefaultImpls.getActive(ConfigAware.kt:59)
...

Can it be that you are using a wrong value which cannot be converted to a boolean for an active property?

@kepocnhh
Copy link
Author

kepocnhh commented Nov 6, 2019

Fair remark. Then the question arises - why do configuration files work alone? After all, then they contain all the same "incorrect values" that cannot be converted.

@schalkms
Copy link
Member

schalkms commented Feb 7, 2020

Since detekt's now validates the config options, I'm asking whether this problem still applies?

@kepocnhh
Copy link
Author

@arturbosch @schalkms

I think I figured out the problem. Firstly, I had a typo, which I could only see by chance in the editor with a different syntax highlighting :). In one of the configuration files, I used active: fasle (instead of active: false). But everything works almost as I described. For some reason, the detekt does not see this error if the configuration file is one.

Using only one configuration file with:

potential-bugs:
  active: true
  RedundantElseInWhen:
    active: fasle

I get a successful result.

But if you use such a configuration file in a list of several, then the detekt prints the error that I indicated above and fails. That is, in this case, the detekt works correctly.

As a result, it turns out that I was faced with the fact that the detector says that it works correctly when the configuration file is transferred to it with an error (and not vice versa, as I described in the issue header).

The last tests I conducted on kotlin 1.3.70 and detekt 1.6.0

Please comment. Maybe someone will try to reproduce.

@schalkms
Copy link
Member

schalkms commented Mar 18, 2020

Did you try to do the following in your config.yml file?

config:
   validation: true

@arturbosch arturbosch reopened this Mar 19, 2020
@arturbosch arturbosch changed the title Detekt does not work with multiple configuration files Invalid boolean config values are evaluated silently to false Mar 19, 2020
arturbosch added a commit that referenced this issue Mar 19, 2020
Co-Authored-By: Brais Gabín <braisgabin@gmail.com>
arturbosch added a commit that referenced this issue Mar 19, 2020
Co-Authored-By: Brais Gabín <braisgabin@gmail.com>
@arturbosch arturbosch added this to the 1.7.0 milestone Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants