Skip to content

Commit

Permalink
ci: add stylecheck to golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert committed Oct 6, 2022
1 parent 353e6a2 commit 525dd1b
Show file tree
Hide file tree
Showing 50 changed files with 170 additions and 172 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters:
enable:
- stylecheck
6 changes: 3 additions & 3 deletions cmd/ipfs/add_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func addMigrations(ctx context.Context, node *core.IpfsNode, fetcher migrations.
}
}
default:
return errors.New("Cannot get migrations from unknown fetcher type")
return errors.New("cannot get migrations from unknown fetcher type")
}
}

Expand Down Expand Up @@ -118,9 +118,9 @@ func addMigrationPaths(ctx context.Context, node *core.IpfsNode, peerInfo peer.A
fmt.Printf("connected to migration peer %q\n", peerInfo)

if pin {
pinApi := ipfs.Pin()
pinAPI := ipfs.Pin()
for _, ipfsPath := range paths {
err := pinApi.Add(ctx, ipfsPath)
err := pinAPI.Add(ctx, ipfsPath)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
routingOptionCustomKwd = "custom"
routingOptionDefaultKwd = "default"
unencryptTransportKwd = "disable-transport-encryption"
unrestrictedApiAccessKwd = "unrestricted-api"
unrestrictedAPIAccessKwd = "unrestricted-api"
writableKwd = "writable"
enablePubSubKwd = "enable-pubsub-experiment"
enableIPNSPubSubKwd = "enable-namesys-pubsub"
Expand Down Expand Up @@ -174,7 +174,7 @@ Headers.
cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount). Defaults to config setting."),
cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes"),
cmds.BoolOption(unrestrictedAPIAccessKwd, "Allow API access to unlisted hashes"),
cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"),
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").WithDefault(true),
Expand Down Expand Up @@ -654,7 +654,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
// because this would open up the api to scripting vulnerabilities.
// only the webui objects are allowed.
// if you know what you're doing, go ahead and pass --unrestricted-api.
unrestricted, _ := req.Options[unrestrictedApiAccessKwd].(bool)
unrestricted, _ := req.Options[unrestrictedAPIAccessKwd].(bool)
gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...)
if unrestricted {
gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
Expand Down
3 changes: 2 additions & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
profileOptionName = "profile"
)

// nolint
var errRepoExists = errors.New(`ipfs configuration file already exists!
Reinitializing would overwrite your keys.
Reinitializing would overwrite your keys
`)

var initCmd = &cmds.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
cmds "github.com/ipfs/go-ipfs-cmds"
)

// This is the CLI root, used for executing commands accessible to CLI clients.
// Root is the CLI root, used for executing commands accessible to CLI clients.
// Some subcommands (like 'ipfs daemon' or 'ipfs init') are only accessible here,
// and can't be called through the HTTP API.
var Root = &cmds.Command{
Expand Down
12 changes: 6 additions & 6 deletions cmd/ipfs/pinmfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestPinMFSRootNodeError(t *testing.T) {
}

func TestPinMFSService(t *testing.T) {
cfg_invalid_interval := &config.Config{
cfgInvalidInterval := &config.Config{
Pinning: config.Pinning{
RemoteServices: map[string]config.RemotePinningService{
"disabled": {
Expand All @@ -119,7 +119,7 @@ func TestPinMFSService(t *testing.T) {
},
},
}
cfg_valid_unnamed := &config.Config{
cfgValidUnnamed := &config.Config{
Pinning: config.Pinning{
RemoteServices: map[string]config.RemotePinningService{
"valid_unnamed": {
Expand All @@ -134,7 +134,7 @@ func TestPinMFSService(t *testing.T) {
},
},
}
cfg_valid_named := &config.Config{
cfgValidNamed := &config.Config{
Pinning: config.Pinning{
RemoteServices: map[string]config.RemotePinningService{
"valid_named": {
Expand All @@ -149,9 +149,9 @@ func TestPinMFSService(t *testing.T) {
},
},
}
testPinMFSServiceWithError(t, cfg_invalid_interval, "remote pinning service \"invalid_interval\" has invalid MFS.RepinInterval")
testPinMFSServiceWithError(t, cfg_valid_unnamed, "error while listing remote pins: empty response from remote pinning service")
testPinMFSServiceWithError(t, cfg_valid_named, "error while listing remote pins: empty response from remote pinning service")
testPinMFSServiceWithError(t, cfgInvalidInterval, "remote pinning service \"invalid_interval\" has invalid MFS.RepinInterval")
testPinMFSServiceWithError(t, cfgValidUnnamed, "error while listing remote pins: empty response from remote pinning service")
testPinMFSServiceWithError(t, cfgValidNamed, "error while listing remote pins: empty response from remote pinning service")
}

func testPinMFSServiceWithError(t *testing.T, cfg *config.Config, expectedErrorPrefix string) {
Expand Down
2 changes: 1 addition & 1 deletion config/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Experiments struct {
ShardingEnabled bool `json:",omitempty"` // deprecated by autosharding: https://github.com/ipfs/kubo/pull/8527
GraphsyncEnabled bool
Libp2pStreamMounting bool
P2pHttpProxy bool
P2pHttpProxy bool //nolint
StrategicProviding bool
AcceleratedDHTClient bool
}
3 changes: 1 addition & 2 deletions core/commands/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
verifcid "github.com/ipfs/go-verifcid"
ipldmulticodec "github.com/ipld/go-ipld-prime/multicodec"
mbase "github.com/multiformats/go-multibase"
"github.com/multiformats/go-multicodec"
mc "github.com/multiformats/go-multicodec"
mhash "github.com/multiformats/go-multihash"
)
Expand Down Expand Up @@ -71,7 +70,7 @@ The optional format string is a printf style format string:
opts.fmtStr = fmtStr

if codecStr != "" {
var codec multicodec.Code
var codec mc.Code
err := codec.Set(codecStr)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cmdenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetNode(env interface{}) (*core.IpfsNode, error) {
}

// GetApi extracts CoreAPI instance from the environment.
func GetApi(env cmds.Environment, req *cmds.Request) (coreiface.CoreAPI, error) {
func GetApi(env cmds.Environment, req *cmds.Request) (coreiface.CoreAPI, error) { //nolint
ctx, ok := env.(*commands.Context)
if !ok {
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
Expand Down
4 changes: 2 additions & 2 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Specification of CAR formats: https://ipld.io/specs/transport/car/
// event should have only one of `Root` or `Stats` set, not both
if event.Root == nil {
if event.Stats == nil {
return fmt.Errorf("Unexpected message from DAG import")
return fmt.Errorf("unexpected message from DAG import")
}
stats, _ := req.Options[statsOptionName].(bool)
if stats {
Expand All @@ -233,7 +233,7 @@ Specification of CAR formats: https://ipld.io/specs/transport/car/
}

if event.Stats != nil {
return fmt.Errorf("Unexpected message from DAG import")
return fmt.Errorf("unexpected message from DAG import")
}

enc, err := cmdenv.GetLowLevelCidEncoder(req)
Expand Down
2 changes: 1 addition & 1 deletion core/commands/dag/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func finishCLIExport(res cmds.Response, re cmds.ResponseEmitter) error {
if !specified {
// default based on TTY availability
errStat, _ := os.Stderr.Stat()
if 0 != (errStat.Mode() & os.ModeCharDevice) {
if (errStat.Mode() & os.ModeCharDevice) != 0 {
showProgress = true
}
} else if val.(bool) {
Expand Down
8 changes: 4 additions & 4 deletions core/commands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
)

const offlineIdErrorMessage = "'ipfs id' cannot query information on remote peers without a running daemon; if you only want to convert --peerid-base, pass --offline option."
const offlineIDErrorMessage = "'ipfs id' cannot query information on remote peers without a running daemon; if you only want to convert --peerid-base, pass --offline option"

type IdOutput struct {
type IdOutput struct { //nolint
ID string
PublicKey string
Addresses []string
Expand Down Expand Up @@ -98,7 +98,7 @@ EXAMPLE:

offline, _ := req.Options[OfflineOption].(bool)
if !offline && !n.IsOnline {
return errors.New(offlineIdErrorMessage)
return errors.New(offlineIDErrorMessage)
}

if !offline {
Expand All @@ -107,7 +107,7 @@ EXAMPLE:
switch err {
case nil:
case kb.ErrLookupFailure:
return errors.New(offlineIdErrorMessage)
return errors.New(offlineIDErrorMessage)
default:
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ publish'.

type KeyOutput struct {
Name string
Id string
Id string //nolint
}

type KeyOutputList struct {
Expand All @@ -67,7 +67,7 @@ type KeyOutputList struct {
type KeyRenameOutput struct {
Was string
Now string
Id string
Id string //nolint
Overwrite bool
}

Expand Down
8 changes: 4 additions & 4 deletions core/commands/multibase.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ This command expects multibase inside of a file or via stdin:
if err != nil {
return fmt.Errorf("failed to access file: %w", err)
}
encoded_data, err := io.ReadAll(file)
encodedData, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read file contents: %w", err)
}
_, data, err := mbase.Decode(string(encoded_data))
_, data, err := mbase.Decode(string(encodedData))
if err != nil {
return fmt.Errorf("failed to decode multibase: %w", err)
}
Expand Down Expand Up @@ -156,11 +156,11 @@ but one can customize used base with -b:
if err != nil {
return fmt.Errorf("failed to access file: %w", err)
}
encoded_data, err := io.ReadAll(file)
encodedData, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read file contents: %w", err)
}
_, data, err := mbase.Decode(string(encoded_data))
_, data, err := mbase.Decode(string(encodedData))
if err != nil {
return fmt.Errorf("failed to decode multibase: %w", err)
}
Expand Down
18 changes: 9 additions & 9 deletions core/commands/pin/remotepin.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,27 +214,27 @@ NOTE: a comma-separated notation is supported in CLI for convenience:

// Block unless --background=true is passed
if !req.Options[pinBackgroundOptionName].(bool) {
requestId := ps.GetRequestId()
requestID := ps.GetRequestId()
for {
ps, err = c.GetStatusByID(ctx, requestId)
ps, err = c.GetStatusByID(ctx, requestID)
if err != nil {
return fmt.Errorf("failed to check pin status for requestid=%q due to error: %v", requestId, err)
return fmt.Errorf("failed to check pin status for requestid=%q due to error: %v", requestID, err)
}
if ps.GetRequestId() != requestId {
return fmt.Errorf("failed to check pin status for requestid=%q, remote service sent unexpected requestid=%q", requestId, ps.GetRequestId())
if ps.GetRequestId() != requestID {
return fmt.Errorf("failed to check pin status for requestid=%q, remote service sent unexpected requestid=%q", requestID, ps.GetRequestId())
}
s := ps.GetStatus()
if s == pinclient.StatusPinned {
break
}
if s == pinclient.StatusFailed {
return fmt.Errorf("remote service failed to pin requestid=%q", requestId)
return fmt.Errorf("remote service failed to pin requestid=%q", requestID)
}
tmr := time.NewTimer(time.Second / 2)
select {
case <-tmr.C:
case <-ctx.Done():
return fmt.Errorf("waiting for pin interrupted, requestid=%q remains on remote service", requestId)
return fmt.Errorf("waiting for pin interrupted, requestid=%q remains on remote service", requestID)
}
}
}
Expand Down Expand Up @@ -665,8 +665,8 @@ TIP: pass '--enc=json' for more useful JSON output.

type ServiceDetails struct {
Service string
ApiEndpoint string
Stat *Stat `json:",omitempty"` // present only when --stat not passed
ApiEndpoint string //nolint
Stat *Stat `json:",omitempty"` // present only when --stat not passed
}

type Stat struct {
Expand Down
3 changes: 1 addition & 2 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
DebugOption = "debug"
LocalOption = "local" // DEPRECATED: use OfflineOption
OfflineOption = "offline"
ApiOption = "api"
ApiOption = "api" //nolint
)

var Root = &cmds.Command{
Expand Down Expand Up @@ -118,7 +118,6 @@ The CLI will exit with one of the following values:
},
}

// commandsDaemonCmd is the "ipfs commands" command for daemon
var CommandsDaemonCmd = CommandsCmd(Root)

var rootSubcommands = map[string]*cmds.Command{
Expand Down
4 changes: 2 additions & 2 deletions core/commands/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Example:
return err
}
} else if tfound {
protoId := protocol.ID(tstr)
stats := nd.Reporter.GetBandwidthForProtocol(protoId)
protoID := protocol.ID(tstr)
stats := nd.Reporter.GetBandwidthForProtocol(protoID)
if err := res.Emit(&stats); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ The output of this command is JSON.
}

if node.ResourceManager == nil {
return libp2p.NoResourceMgrError
return libp2p.ErrNoResourceMgr
}

if len(req.Arguments) != 1 {
Expand Down Expand Up @@ -394,7 +394,7 @@ Changes made via command line are persisted in the Swarm.ResourceMgr.Limits fiel
}

if node.ResourceManager == nil {
return libp2p.NoResourceMgrError
return libp2p.ErrNoResourceMgr
}

scope := req.Arguments[0]
Expand Down
Loading

0 comments on commit 525dd1b

Please sign in to comment.