-
-
Notifications
You must be signed in to change notification settings - Fork 766
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 --auto-correct cmdline option to gradle tasks #4202
Conversation
This allows you to run ./gradlew detekt --auto-correct
Codecov Report
@@ Coverage Diff @@
## main #4202 +/- ##
=========================================
Coverage 84.22% 84.22%
Complexity 3258 3258
=========================================
Files 472 472
Lines 10309 10309
Branches 1820 1820
=========================================
Hits 8683 8683
Misses 666 666
Partials 960 960 Continue to review full report at Codecov.
|
This is a nice idea - but the same can be achieved by something like And then in the Gradle config: val detektAutoCorrect: String? by project
tasks.withType<Detekt>().configureEach {
autoCorrect = detektAutoCorrect.toBoolean()
} It's a few more chars on the CLI but gets the same result. I don't feel strongly about this though, but just thinking that if we add a CLI option for auto correct, then does it make sense to add it for other parameters. The Gradle plugin is fairly complicated for what it does, so it would be good to keep it simple where we can. |
Yeah I've basically had to add that on every project I've worked on using detekt, and if a project I'm contributing to doesn't have it I have to tweak the build file to run it. Was hoping to save some time and add discoverability by having it built in. Don't know of another param in the same situation, but I feel like that could always be a follow-up if some is desired. |
I think the thing sets auto-correct apart from other args is that it can modify your source so it really should be obvious when you are running with it imo. I'd argue that the gradle dsl shouldn't even have it, but I can live with keeping that param there. |
I think that we declined already some PRs similar to this one but
this seems a very legit use case. Not in all the projects you have the control to decide how detekt is setup so this is probably a legit use case. And, because we had this request multiple times, it seems like a feature that "a lot/some" users want.
I agree with this. I don't think it should be in the dsl. I don't know if the best way would be a flag or a new task We know that our current gradle plugin api is a mess and we need to reframe it completely for 2.0 (more about this here: #4190 (comment)) but I think that until then this is a very clean way to give support to this use case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to update docs?
detekt-gradle-plugin/src/test/kotlin/io/gitlab/arturbosch/detekt/DetektTaskDslSpec.kt
Outdated
Show resolved
Hide resolved
@evant can you update the documentation? I think that's the only thing missing for us to merge this. |
Glad to see a change of ❤️ on this. I should provide better arguments time. |
This allows you to run
./gradlew detekt --auto-correct
I often find myself wanting to make this configurable particularly so that I can run it locally and not on ci. Also because auto-correct is a potentially destructive operation it's nice to have to be explicit to enable it on the cmdline instead of hard-coding it in the detekt task configuration. Having a standard option for this also makes it easier to autofix your code when working on various third-party projects using detekt.