Skip to content

Commit 8115592

Browse files
committed
Add noFailOnViolated option for SpotlessConfig
If this option is set `true`, a Spotless task won't fail even if the task detects any format violation.
1 parent c350073 commit 8115592

File tree

14 files changed

+53
-6
lines changed

14 files changed

+53
-6
lines changed

plugin/src/main/scala-sbt-0.13/net/moznion/sbt/SbtSpotless.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ object SbtSpotless extends AutoPlugin {
147147
.reduce((acc, taskResult) => acc && taskResult)
148148

149149
if (!succeeded) {
150-
throw new MessageOnlyException(
151-
s"Failed to run $taskName, please refer to the above logs."
152-
)
150+
if (!config.noFailOnViolated) {
151+
throw new MessageOnlyException(
152+
s"Failed to run $taskName, please refer to the above logs."
153+
)
154+
}
155+
logger.info(s"Some violations occur on $taskName, please refer to the above logs. `noFailOnViolated` is set true, so the task doesn't fail.")
153156
}
154157
}
155158
}

plugin/src/main/scala-sbt-1.0/net/moznion/sbt/SbtSpotless.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,13 @@ object SbtSpotless extends AutoPlugin {
157157
.reduce((acc, taskResult) => acc && taskResult)
158158

159159
if (!succeeded) {
160-
throw new MessageOnlyException(
161-
s"Failed to run $taskName, please refer to the above logs."
160+
if (!config.noFailOnViolated) {
161+
throw new MessageOnlyException(
162+
s"Failed to run $taskName, please refer to the above logs."
163+
)
164+
}
165+
logger.info(
166+
s"Some violations occur on $taskName, please refer to the above logs. `noFailOnViolated` is set true, so the task doesn't fail."
162167
)
163168
}
164169
}

plugin/src/main/scala/net/moznion/sbt/spotless/config/SpotlessConfig.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ case class SpotlessConfig(
4444
paddedCellWorkingDir: Target = null,
4545
paddedCellDiagnoseDir: Target = null,
4646
checkOnCompile: Boolean = false,
47-
applyOnCompile: Boolean = false
47+
applyOnCompile: Boolean = false,
48+
noFailOnViolated: Boolean = false
4849
) {
4950
private[sbt] def toPathConfig(
5051
defaultBaseDir: File,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src/main/java/*
2+
!src/main/java/.gitkeep
3+
src/test/java/*
4+
!src/test/java/.gitkeep
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import net.moznion.sbt.spotless.config._
2+
3+
lazy val root = (project in file("."))
4+
.settings(
5+
version := "0.1",
6+
scalaVersion := "2.12.11",
7+
spotless := SpotlessConfig(
8+
noFailOnViolated = true,
9+
dynamicDependencyWorkingDir = file(System.getProperty("plugin.scriptedTestDepDir")),
10+
dynamicDependencyCacheDir = file(System.getProperty("plugin.scriptedTestDepDir") + "/.spotless"),
11+
),
12+
spotlessJava := JavaConfig(
13+
googleJavaFormat = GoogleJavaFormatConfig(version = "1.7")
14+
),
15+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Main {
2+
public void method() {}
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
public void method() {}
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Main {
2+
public void method() {}
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
public void method() {}
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.3.9

0 commit comments

Comments
 (0)