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

Not running formatting autocorrect #1766

Closed
akhbulatov opened this issue Jul 11, 2019 · 6 comments
Closed

Not running formatting autocorrect #1766

akhbulatov opened this issue Jul 11, 2019 · 6 comments

Comments

@akhbulatov
Copy link

Hey. I looked at similar issues and tried solutions from there, but it didn't work for Android project. For example, adding a new line at the end of a file. Maybe I missed something. When I run ./gradlew detekt, the analysis is run and creates a report, but without formatting. For formatting need another task or reason for something else?

build.gradle (project-level):

buildscript {
    ext.versions = [
            ....
            'detekt' : '1.0.0-RC16'
    ]

    repositories {
        google()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        ...
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${versions.detekt}"
    }
}

allprojects {
    apply from: "$rootDir/detekt.gradle"

    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

build.gralde (app module):

dependencies {
    ...
    detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:${versions.detekt}"
}

detekt.gradle (in project's root):

apply plugin: "io.gitlab.arturbosch.detekt"

detekt {
    toolVersion = "${versions.detekt}"
    input = files("src/main/java")
    parallel = true
    filters = ".*build.*,.*/resources/.*,.*/tmp/.*"
    config = files("$rootDir/default-detekt-config.yml")
}

default-detekt-config.yml:

formatting:
  active: true
  android: true
  autoCorrect: true
  ...
  FinalNewline:
    active: true
    autoCorrect: true
@arturbosch
Copy link
Member

arturbosch commented Jul 14, 2019

Please try adding autoCorrect = true to your gradle build file inside the detekt extensions.
We migrated away from a top level autoCorrect property in the config file.

@bagage
Copy link
Contributor

bagage commented Aug 1, 2019

I'm facing the same issue. I tried your suggestion, but autoCorrect is not a know property:

detekt {
			toolVersion = "1.0.0-RC16"
			config = project.rootProject.files("detekt-config.yml")
			parallel = true
			failFast = true
			autoCorrect = true
		}

It yields:

Build file '/build.gradle' line: 86
A problem occurred evaluating root project 'testproject'.
> Could not set unknown property 'autoCorrect' for object of type io.gitlab.arturbosch.detekt.extensions.DetektExtension.

@akhbulatov
Copy link
Author

akhbulatov commented Aug 1, 2019

@bagage add this in build.gradle:

tasks.withType(io.gitlab.arturbosch.detekt.Detekt) {
    // ...
    autoCorrect = true
}

@bagage
Copy link
Contributor

bagage commented Aug 1, 2019

Yes it works! Thanks a lot @akhbulatov!!

@bagage
Copy link
Contributor

bagage commented Aug 1, 2019

@akhbulatov maybe it's worth adding a note on the readme? I think many people would love to have autoCorrect enabled :).

@arturbosch
Copy link
Member

arturbosch commented Aug 1, 2019

Thanks @akhbulatov !
@bagage with the new release soon, you do not need the tasks.withType... thingy anymore, autoCorrect will work on the detekt {...} closure.
By mistake it was only added for the task but not for the extension - #1790.

@arturbosch arturbosch added this to the 1.0.0 milestone Aug 1, 2019
@arturbosch arturbosch added the bug label Aug 1, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants