Skip to content

Commit 6fd3fec

Browse files
authored
chore: auto remove unused imports + format (#68)
* auto remove unused imports * also format source
1 parent f75d7ec commit 6fd3fec

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ require (
1414
github.com/strangelove-ventures/simapp v0.0.0-00000000-000000000000
1515
github.com/stretchr/testify v1.8.4
1616
golang.org/x/text v0.14.0
17+
golang.org/x/tools v0.18.0
1718
)
1819

1920
require (
2021
github.com/chzyer/readline v1.5.1 // indirect
2122
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2223
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2324
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
25+
golang.org/x/mod v0.15.0 // indirect
2426
golang.org/x/sys v0.17.0 // indirect
2527
gopkg.in/yaml.v3 v3.0.1 // indirect
2628
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
2929
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3030
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
3131
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
32+
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
33+
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
3234
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3335
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3436
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3537
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
3638
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3739
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
3840
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
41+
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
42+
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
3943
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4044
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4145
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

simapp/app/ante.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
77
"github.com/cosmos/ibc-go/v8/modules/core/keeper"
88

9-
corestoretypes "cosmossdk.io/core/store" // spawntag: wasm
9+
corestoretypes "cosmossdk.io/core/store"
1010
circuitante "cosmossdk.io/x/circuit/ante"
1111
circuitkeeper "cosmossdk.io/x/circuit/keeper"
1212

@@ -17,7 +17,7 @@ import (
1717
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
1818
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
1919

20-
sdkmath "cosmossdk.io/math" // spawntag:poa (Tagging with poa so if it is removed, this module is removed from import too)
20+
sdkmath "cosmossdk.io/math"
2121
poaante "github.com/strangelove-ventures/poa/ante"
2222

2323
globalfeeante "github.com/reecepbcups/globalfee/x/globalfee/ante"

simapp/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ import (
134134
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
135135
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
136136

137-
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" //spawntag:globalfee
137+
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
138138

139139
"github.com/CosmWasm/wasmd/x/wasm"
140140
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

spawn/chain_config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package spawn
33
import (
44
"embed"
55
"fmt"
6+
"go/format"
67
"io/fs"
78
"log/slog"
89
"os"
910
"path"
1011
"strings"
1112

1213
"github.com/strangelove-ventures/simapp"
14+
"golang.org/x/tools/imports"
1315
)
1416

1517
var (
@@ -124,6 +126,23 @@ func (cfg *NewChainConfig) SetupMainChainApp() error {
124126
// *All Files
125127
fc.ReplaceEverywhere(cfg)
126128

129+
// Removes unused imports & tidies up the files
130+
if strings.HasSuffix(fc.NewPath, ".go") && len(fc.Contents) > 0 {
131+
newSrc, err := imports.Process(fc.NewPath, []byte(fc.Contents), nil)
132+
if err != nil {
133+
cfg.Logger.Error("error processing imports", "err", err, "file", fc.NewPath)
134+
return fc.Save()
135+
}
136+
137+
bz, err := format.Source(newSrc)
138+
if err != nil {
139+
cfg.Logger.Error("error formatting go file", "err", err, "file", fc.NewPath)
140+
return fc.Save()
141+
}
142+
143+
fc.Contents = string(bz)
144+
}
145+
127146
return fc.Save()
128147
})
129148
}

0 commit comments

Comments
 (0)