Skip to content

Commit d3f7680

Browse files
committed
Introduce go extension for plugin-gradle
1 parent 2870d06 commit d3f7680

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static String name() {
4343
}
4444

4545
public static String defaultVersion() {
46-
return "1.20.0";
46+
return "go1.20.0";
4747
}
4848

4949
private final String version;

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -957,33 +957,6 @@ public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type, String version)
957957
return new EclipseWtpConfig(type, version);
958958
}
959959

960-
public class GofmtConfig {
961-
GofmtFormatStep stepCfg;
962-
963-
public GofmtConfig(String version) {
964-
stepCfg = (GofmtFormatStep) GofmtFormatStep.withVersion(version).create();
965-
addStep(createStep());
966-
}
967-
968-
public GofmtConfig withGoExecutable(String pathToGo) {
969-
stepCfg = stepCfg.withGoExecutable(pathToGo);
970-
replaceStep(createStep());
971-
return this;
972-
}
973-
974-
private FormatterStep createStep() {
975-
return stepCfg.create();
976-
}
977-
}
978-
979-
public GofmtConfig gofmt() {
980-
return new GofmtConfig(GofmtFormatStep.defaultVersion());
981-
}
982-
983-
public GofmtConfig gofmt(String version) {
984-
return new GofmtConfig(version);
985-
}
986-
987960
/**
988961
* <pre>
989962
* spotless {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2024 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import com.diffplug.spotless.FormatterStep;
19+
import com.diffplug.spotless.go.GofmtFormatStep;
20+
21+
import javax.inject.Inject;
22+
23+
public class GoExtension extends FormatExtension {
24+
public static final String NAME = "go";
25+
26+
@Inject
27+
public GoExtension(SpotlessExtension spotless) {
28+
super(spotless);
29+
}
30+
31+
public GofmtConfig gofmt() {
32+
return new GofmtConfig(GofmtFormatStep.defaultVersion());
33+
}
34+
35+
public GofmtConfig gofmt(String version) {
36+
return new GofmtConfig(version);
37+
}
38+
39+
public class GofmtConfig {
40+
GofmtFormatStep stepCfg;
41+
42+
public GofmtConfig(String version) {
43+
stepCfg = GofmtFormatStep.withVersion(version);
44+
addStep(createStep());
45+
}
46+
47+
public GofmtConfig withGoExecutable(String pathToGo) {
48+
stepCfg = stepCfg.withGoExecutable(pathToGo);
49+
replaceStep(createStep());
50+
return this;
51+
}
52+
53+
private FormatterStep createStep() {
54+
return stepCfg.create();
55+
}
56+
}
57+
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public void gherkin(Action<GherkinExtension> closure) {
223223
format(GherkinExtension.NAME, GherkinExtension.class, closure);
224224
}
225225

226+
public void go(Action<GoExtension> closure) {
227+
requireNonNull(closure);
228+
format(GoExtension.NAME, GoExtension.class, closure);
229+
}
230+
226231
/** Configures a custom extension. */
227232
public void format(String name, Action<FormatExtension> closure) {
228233
requireNonNull(name, "name");

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoGradleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void gofmt() throws IOException {
3030
" id 'com.diffplug.spotless'",
3131
"}",
3232
"spotless {",
33-
" format 'go' {",
33+
" go {",
3434
" target 'src/**/*.go'",
35-
" gofmt()",
35+
" gofmt(\"go1.21.5\")",
3636
" }",
3737
"}");
3838
setFile("src/test.go").toResource("go/gofmt/go.dirty");

0 commit comments

Comments
 (0)