Skip to content

Commit 7a1680d

Browse files
authored
Merge pull request #94 from guggero/lint
Add linter to makefile, lint on Travis build
2 parents 9039e5f + a0a03b4 commit 7a1680d

24 files changed

+106
-51
lines changed

.golangci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
run:
2+
# timeout for analysis
3+
deadline: 4m
4+
5+
# Linting uses a lot of memory. Keep it under control by only running a single
6+
# worker.
7+
concurrency: 1
8+
9+
linters-settings:
10+
gofmt:
11+
# simplify code: gofmt with `-s` option, true by default
12+
simplify: true
13+
14+
linters:
15+
enable-all: true
16+
disable:
17+
# Global variables are used in many places throughout the code base.
18+
- gochecknoglobals
19+
20+
# Some lines are over 80 characters on purpose and we don't want to make them
21+
# even longer by marking them as 'nolint'.
22+
- lll
23+
24+
# We don't care (enough) about misaligned structs to lint that.
25+
- maligned
26+
27+
# We have long functions, especially in tests. Moving or renaming those would
28+
# trigger funlen problems that we may not want to solve at that time.
29+
- funlen
30+
31+
# Disable for now as we haven't yet tuned the sensitivity to our codebase
32+
# yet. Enabling by default for example, would also force new contributors to
33+
# potentially extensively refactor code, when they want to smaller change to
34+
# land.
35+
- gocyclo
36+
37+
# Instances of table driven tests that don't pre-allocate shouldn't trigger
38+
# the linter.
39+
- prealloc
40+
41+
issues:
42+
# Only show newly introduced problems.
43+
new-from-rev: 36838cf7f464cf73b0201798063b2caffeae4250

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sudo: required
1818

1919
script:
2020
- export GO111MODULE=on
21-
- make unit
21+
- make lint unit
2222

2323
after_script:
2424
- echo "Uploading to termbin.com..." && find *.log | xargs -I{} sh -c "cat {} | nc termbin.com 9999 | xargs -r0 printf '{} uploaded to %s'"

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,35 @@ PKG := github.com/lightninglabs/loop
22

33
GOTEST := GO111MODULE=on go test -v
44

5+
GO_BIN := ${GOPATH}/bin
6+
7+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
58
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
69

10+
LINT_BIN := $(GO_BIN)/golangci-lint
11+
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
12+
LINT_COMMIT := v1.18.0
13+
LINT = $(LINT_BIN) run -v
14+
15+
DEPGET := cd /tmp && GO111MODULE=on go get -v
716
XARGS := xargs -L 1
817

918
TEST_FLAGS = -test.timeout=20m
1019

1120
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
1221

22+
$(LINT_BIN):
23+
@$(call print, "Fetching linter")
24+
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
25+
1326
unit:
1427
@$(call print, "Running unit tests.")
1528
$(UNIT)
29+
30+
fmt:
31+
@$(call print, "Formatting source.")
32+
gofmt -l -w -s $(GOFILES_NOVENDOR)
33+
34+
lint: $(LINT_BIN)
35+
@$(call print, "Linting source.")
36+
$(LINT)

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
384384
return &LoopOutQuote{
385385
SwapFee: swapFee,
386386
MinerFee: minerFee,
387-
PrepayAmount: btcutil.Amount(quote.PrepayAmount),
387+
PrepayAmount: quote.PrepayAmount,
388388
SwapPaymentDest: quote.SwapPaymentDest,
389389
CltvDelta: quote.CltvDelta,
390390
}, nil

cmd/loop/loopin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func loopIn(ctx *cli.Context) error {
4141
args = args.Tail()
4242
default:
4343
// Show command help if no arguments and flags were provided.
44-
cli.ShowCommandHelp(ctx, "in")
45-
return nil
44+
return cli.ShowCommandHelp(ctx, "in")
4645
}
4746

4847
amt, err := parseAmt(amtStr)

cmd/loop/loopout.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ func loopOut(ctx *cli.Context) error {
5959
args = args.Tail()
6060
default:
6161
// Show command help if no arguments and flags were provided.
62-
cli.ShowCommandHelp(ctx, "out")
63-
return nil
62+
return cli.ShowCommandHelp(ctx, "out")
6463
}
6564

6665
amt, err := parseAmt(amtStr)

cmd/loop/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type limits struct {
9797
}
9898

9999
func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
100-
maxSwapRoutingFee := getMaxRoutingFee(btcutil.Amount(amt))
100+
maxSwapRoutingFee := getMaxRoutingFee(amt)
101101
maxPrepayRoutingFee := getMaxRoutingFee(btcutil.Amount(
102102
quote.PrepayAmt,
103103
))
@@ -126,7 +126,7 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits,
126126
if l.maxPrepayRoutingFee != nil {
127127
totalSuccessMax += *l.maxPrepayRoutingFee
128128
}
129-
129+
130130
if swapType == loop.TypeIn && externalHtlc {
131131
fmt.Printf("On-chain fee for external loop in is not " +
132132
"included.\nSufficient fees will need to be paid " +
@@ -135,7 +135,7 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits,
135135
}
136136

137137
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
138-
btcutil.Amount(amt), swapType, totalSuccessMax,
138+
amt, swapType, totalSuccessMax,
139139
)
140140

141141
fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ")

cmd/loop/quote.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func quote(ctx *cli.Context) error {
2828
// Show command help if the incorrect number arguments and/or flags were
2929
// provided.
3030
if ctx.NArg() != 1 || ctx.NumFlags() > 1 {
31-
cli.ShowCommandHelp(ctx, "quote")
32-
return nil
31+
return cli.ShowCommandHelp(ctx, "quote")
3332
}
3433

3534
args := ctx.Args()

executor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *executor) run(mainCtx context.Context,
6969

7070
select {
7171
case h := <-blockEpochChan:
72-
setHeight(int32(h))
72+
setHeight(h)
7373
case err := <-blockErrorChan:
7474
return err
7575
case <-mainCtx.Done():
@@ -134,10 +134,10 @@ func (s *executor) run(mainCtx context.Context,
134134
delete(blockEpochQueues, doneID)
135135

136136
case h := <-blockEpochChan:
137-
setHeight(int32(h))
137+
setHeight(h)
138138
for _, queue := range blockEpochQueues {
139139
select {
140-
case queue.ChanIn() <- int32(h):
140+
case queue.ChanIn() <- h:
141141
case <-mainCtx.Done():
142142
return mainCtx.Err()
143143
}

lndclient/invoices_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func (s *invoicesClient) WaitForFinished() {
5252
func (s *invoicesClient) SettleInvoice(ctx context.Context,
5353
preimage lntypes.Preimage) error {
5454

55-
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
55+
timeoutCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
5656
defer cancel()
5757

58-
rpcCtx = s.invoiceMac.WithMacaroonAuth(ctx)
58+
rpcCtx := s.invoiceMac.WithMacaroonAuth(timeoutCtx)
5959
_, err := s.client.SettleInvoice(rpcCtx, &invoicesrpc.SettleInvoiceMsg{
6060
Preimage: preimage[:],
6161
})

0 commit comments

Comments
 (0)