Skip to content

Commit d5688e4

Browse files
feat: add gopls modernize integration via Makefile and GitHub Actions (#3)
Co-authored-by: Brandon Young <[email protected]>
1 parent 8b57af8 commit d5688e4

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v5
1919
with:
20-
go-version: '1.23'
20+
go-version: "1.23"
2121

2222
- name: Install dependencies
2323
run: go mod tidy
2424

25+
- name: Check code modernization
26+
run: make modernize-check
27+
2528
- name: Run tests
2629
run: go test ./... -v

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: modernize modernize-fix modernize-check
2+
3+
MODERNIZE_CMD = go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected]
4+
5+
modernize: modernize-fix
6+
7+
modernize-fix:
8+
@echo "Running gopls modernize with -fix..."
9+
$(MODERNIZE_CMD) -test -fix ./...
10+
11+
modernize-check:
12+
@echo "Checking if code needs modernization..."
13+
$(MODERNIZE_CMD) -test ./...

godump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func printValue(tw *tabwriter.Writer, v reflect.Value, indent int, visited map[u
224224

225225
fmt.Fprintf(tw, "%s ", colorize(colorGray, "#"+t.String()))
226226
fmt.Fprintln(tw)
227-
for i := 0; i < v.NumField(); i++ {
227+
for i := range v.NumField() {
228228
field := t.Field(i)
229229
fieldVal := v.Field(i)
230230
symbol := "+"
@@ -260,7 +260,7 @@ func printValue(tw *tabwriter.Writer, v reflect.Value, indent int, visited map[u
260260
fmt.Fprint(tw, "}")
261261
case reflect.Slice, reflect.Array:
262262
fmt.Fprintln(tw, "[")
263-
for i := 0; i < v.Len(); i++ {
263+
for i := range v.Len() {
264264
if i >= maxItems {
265265
indentPrint(tw, indent+1, colorize(colorGray, "... (truncated)\n"))
266266
break

godump_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestMaxDepth(t *testing.T) {
6565
}
6666
n := &Node{}
6767
curr := n
68-
for i := 0; i < 20; i++ {
68+
for range 20 {
6969
curr.Child = &Node{}
7070
curr = curr.Child
7171
}
@@ -234,7 +234,7 @@ func TestPrimitiveTypes(t *testing.T) {
234234
uintptr(5),
235235
float32(1.5),
236236
[2]int{6, 7},
237-
interface{}(42),
237+
any(42),
238238
))
239239

240240
assert.Contains(t, out, "1") // int8
@@ -310,7 +310,7 @@ func TestMaxDepthTruncation(t *testing.T) {
310310
}
311311
root := &Node{}
312312
curr := root
313-
for i := 0; i < 20; i++ {
313+
for range 20 {
314314
curr.Next = &Node{}
315315
curr = curr.Next
316316
}
@@ -332,15 +332,15 @@ func TestDetectColorEnvVars(t *testing.T) {
332332

333333
func TestMapTruncation(t *testing.T) {
334334
largeMap := map[int]int{}
335-
for i := 0; i < 200; i++ {
335+
for i := range 200 {
336336
largeMap[i] = i
337337
}
338338
out := stripANSI(DumpStr(largeMap))
339339
assert.Contains(t, out, "... (truncated)")
340340
}
341341

342342
func TestNilInterfaceTypePrint(t *testing.T) {
343-
var x interface{} = (*int)(nil)
343+
var x any = (*int)(nil)
344344
out := stripANSI(DumpStr(x))
345345
assert.Contains(t, out, "(nil)")
346346
}

0 commit comments

Comments
 (0)