enable linter

This commit is contained in:
Joost Jager 2022-12-02 12:10:50 +01:00
parent d676f63149
commit f8c0868d7f
No known key found for this signature in database
GPG key ID: B9A26449A5528325
6 changed files with 116 additions and 3 deletions

46
.github/workflows/golangci-lint.yml vendored Normal file
View file

@ -0,0 +1,46 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

65
.golangci.yml Normal file
View file

@ -0,0 +1,65 @@
run:
# timeout for analysis
deadline: 10m
linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
exhaustive:
# check switch statements in generated files also
check-generated: false
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: true
revive:
rules:
- name: var-naming
disabled: true
whitespace:
# Enforces newlines (or comments) after every multi-line if statement.
# Default: false
multi-if: true
# Enforces newlines (or comments) after every multi-line function signature.
# Default: false
multi-func: true
linters:
enable:
- exhaustive
- exportloopref
- gci
- gofmt
- misspell
- nilerr
- nlreturn
- revive
- unconvert
- unparam
- wastedassign
- execinquery
- nonamedreturns
- nosprintfhostport
- containedctx
- errchkjson
- contextcheck
- errname
- wastedassign
- nilerr
- gosec
- govet
- whitespace
issues:
exclude-rules:
# Exclude gosec from running for tests so that tests with weak randomness
# (math/rand) will pass the linter.
- path: _test\.go
linters:
- gosec

View file

@ -58,6 +58,7 @@ func newConfigLoader(path string) *configLoader {
loader := &configLoader{
path: path,
}
return loader
}

View file

@ -67,7 +67,7 @@ func (l *lndclientMock) getPendingIncomingHtlcs(ctx context.Context) (
}
type htlcEventsMock struct {
ctx context.Context
ctx context.Context //nolint:containedctx
routerrpc.Router_SubscribeHtlcEventsClient
htlcEvents chan *routerrpc.HtlcEvent
@ -84,7 +84,7 @@ func (h *htlcEventsMock) Recv() (*routerrpc.HtlcEvent, error) {
}
type htlcInterceptorMock struct {
ctx context.Context
ctx context.Context //nolint:containedctx
routerrpc.Router_HtlcInterceptorClient
htlcInterceptorRequests chan *routerrpc.ForwardHtlcInterceptRequest

View file

@ -11,7 +11,6 @@ import (
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/build"
"github.com/urfave/cli"
"google.golang.org/grpc"
)
@ -136,6 +135,7 @@ func main() {
defer client.close()
p := newProcess(client, config)
return p.run(context.Background())
}

View file

@ -14,6 +14,7 @@ type peerController struct {
func newPeerController(logger *zap.SugaredLogger, cfg *groupConfig,
htlcs map[circuitKey]struct{}) *peerController {
var limiter *rate.Limiter
// Skip if no interval set.