Open ubuntudroid opened 6 years ago
This would probably be a helpful feature. Formatting failures can be split into two categories:
Spotless focuses heavily on the first category, because they're "free" from a developer effort standpoint. Issues that can't be fixed automatically require some amount of developer attention, which may or may not be worth it to any given project. That said, there are a lot of formatters out there that require user intervention, and there are users who want that.
This is the code that applies the steps, where the error is thrown and passed to the format exception policy:
This is the formatter exception policy used by the gradle plugin, which rethrows the error as runtime exception and stops the formatting:
To make the change you're suggesting, here is how I would go about it:
Btw, there is an open bug related to this at #194. It might be a good idea to start by understanding and fixing that bug.
Also, Gradle has the --continue
flag.
Sorry for the late response. Was busy on other projects.
@JLLeitschuh This is exactly what I needed and seems to be already the solution. I switched over to ktlint-gradle anyway as I mainly intended to use spotless for the ktlint checks and with ktlint-gradle your suggestion works perfectly fine.
I will try out this suggestion for spotless as well next week, just to ensure that we have a proper outcome of this issue.
This comment made me chuckle as I'm a maintainer on both projects.
If you don't mind me asking, were there any other reasons why you chose ktlint-gradle
over spotless
?
Also, if this issue is truly resolved for you, please close the issue when you've confirmed it's fixed.
@JLLeitschuh Haha, yeah, I saw that. ;)
The main reason for switching to ktlint-gradle is that I like to keep the toolchain as lean as possible and we really only want the checks in ktlint for now. No other reasons at the moment. :)
I will make sure to close the issue after confirming that --continue
works.
So I check on a project with two different violations in two different files.
First violation was a missing space after if
, the second one a too long line.
Unfortunately --continue
didn't work. :( With and without the flag I just get the line length error and the task ends failing.
So I have to keep the issue open.
Hi, Any solution or workaround for this?
The reason that --continue
isn't working I presume is because Gradle is probably treating java.lang.AssertionError
as a fatal error. I think the best thing to do is figure out where the AssertionError
is being thrown (probably from inside the KTlint codebase) and correct it to be an exception, instead of an error.
That's just a guess though. The root cause may not be that.
Any found a workaround for this?
sorry for getting here one year later did anyone get a solution for this?
It is blocked on #1097.
Just to add to this I run into a similar issue with only reporting the first style violation when using a multiple subproject build. When I run ./gradlew spotlessCheck
I get
.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sub-module-1:spotlessJavaCheck'.
.
Then I run ':sub-module-1:spotlessApply' and it fixes a load of files then when I run ./gradlew spotlessCheck
a second time I get and the process continues until I have formatted all of my files
.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sub-module-2:spotlessJavaCheck'.
.
I have the following in my root gradle
buildscript {
.
.
.
dependencies {
.
.
.
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
}
}
subprojects {
apply plugin: "java-library"
apply plugin: "jacoco"
apply plugin: "com.diffplug.spotless"
spotless {
java {
removeUnusedImports()
palantirJavaFormat()
}
}
For context I am trying to apply spotless to my entire codebase for the first time
I tried out spotless today for the first time on one of our Kotlin projects and thus used the ktlint plugin.
It seems to work quite well so far, however
spotlessCheck
always fails right after finding the first codestyle violation whilektlint
(when directly run on the codebase) lists all violations in a neat list.I also tried to apply various different ktlint reporters (like the checkstyle one), but the result always seems to be the same - failure after the first violation (and in this case also no checkstyle XML is generated).
Long story short: can I force spotless (or the ktlint plugin, if that's the culprit) to continue its checks after it found a violation so that I can see all violations at a glance (and if possible without that stacktrace which causes the need for a lot of scrolling to find the error)?
Config looks like this:
Sample output: