Skip to content

Commit d2d25b3

Browse files
committed
linter
1 parent b53585b commit d2d25b3

File tree

10 files changed

+156
-192
lines changed

10 files changed

+156
-192
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
name: lint
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
1111
- name: golangci-lint
12-
uses: golangci/golangci-lint-action@v2
12+
uses: golangci/golangci-lint-action@v7
1313
with:
1414
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
15-
version: v1.63.4
15+
version: v2.1
1616

1717
# Optional: working directory, useful for monorepos
1818
# working-directory: somedir
@@ -22,3 +22,21 @@ jobs:
2222

2323
# Optional: show only new issues if it's a pull request. The default value is `false`.
2424
# only-new-issues: true
25+
#
26+
- name: golangci-lint cmd/tlog
27+
uses: golangci/golangci-lint-action@v7
28+
with:
29+
version: v2.1
30+
working-directory: cmd/tlog
31+
32+
- name: golangci-lint ext/tlclick
33+
uses: golangci/golangci-lint-action@v7
34+
with:
35+
version: v2.1
36+
working-directory: cmd/tlclick
37+
38+
- name: golangci-lint ext/tlgin
39+
uses: golangci/golangci-lint-action@v7
40+
with:
41+
version: v2.1
42+
working-directory: cmd/tlgin

.golangci.yml

Lines changed: 92 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,31 @@
1-
run:
2-
#modules-download-mode: readonly
3-
linters-settings:
4-
govet:
5-
check-shadowing: false
6-
golint:
7-
min-confidence: 0
8-
gocognit:
9-
min-complexity: 30
10-
cyclop:
11-
max-complexity: 30
12-
fieldalignment:
13-
suggest-new: true
14-
dupl:
15-
threshold: 100
16-
goconst:
17-
min-len: 2
18-
min-occurrences: 3
19-
gosec:
20-
excludes:
21-
- G108
22-
- G114
23-
- G115
24-
revive:
25-
rules:
26-
- name: unused-parameter
27-
disabled: true
28-
depguard:
29-
rules:
30-
main:
31-
allow:
32-
- $gostd
33-
- github.com/fsnotify/fsnotify
34-
- github.com/getsentry/sentry-go
35-
- github.com/gin-gonic/gin
36-
- github.com/nikandfor/assert
37-
- github.com/opentracing/opentracing-go
38-
- github.com/prometheus/client_golang
39-
- github.com/prometheus/client_model
40-
- github.com/stretchr/testify/assert
41-
- github.com/stretchr/testify/require
42-
- go.opentelemetry.io/otel
43-
- golang.org/x
44-
- nikand.dev/go/cbor
45-
- nikand.dev/go/cli
46-
- nikand.dev/go/graceful
47-
- nikand.dev/go/hacked
48-
- tlog.app/go/eazy
49-
- tlog.app/go/errors
50-
- tlog.app/go/loc
51-
- tlog.app/go/tlog
52-
misspell:
53-
lll:
54-
line-length: 170
55-
goimports:
56-
local-prefixes: github.com/nikandfor/tlog
57-
prealloc:
58-
simple: true
59-
for-loops: true
60-
gocritic:
61-
enabled-tags:
62-
- experimental
63-
- performance
64-
- style
65-
disabled-checks:
66-
- appendAssign
67-
- appendCombine
68-
- builtinShadow
69-
- commentedOutCode
70-
- octalLiteral
71-
- unnamedResult
72-
- whyNoLint
73-
- yodaStyleExpr
74-
1+
version: "2"
752
linters:
76-
enable-all: true
3+
default: all
774
disable:
785
- cyclop
796
- dogsled
807
- err113
818
- exhaustive
82-
- exhaustivestruct
839
- exhaustruct
8410
- forcetypeassert
11+
- funcorder
8512
- funlen
86-
- gci
8713
- gochecknoglobals
8814
- gochecknoinits
8915
- gocognit
9016
- goconst
9117
- gocyclo
9218
- godox
93-
- golint
94-
- gomnd
9519
- gosmopolitan
96-
- ifshort
9720
- inamedparam
9821
- ireturn
9922
- lll
10023
- maintidx
101-
- maligned
10224
- mnd
10325
- nakedret
10426
- nestif
10527
- nlreturn
10628
- nonamedreturns
107-
- nosnakecase
10829
- paralleltest
10930
- prealloc
11031
- predeclared
@@ -113,8 +34,96 @@ linters:
11334
- testifylint
11435
- testpackage
11536
- thelper
116-
- typecheck
11737
- unparam
11838
- varnamelen
11939
- wrapcheck
12040
- wsl
41+
settings:
42+
cyclop:
43+
max-complexity: 30
44+
depguard:
45+
rules:
46+
main:
47+
allow:
48+
- $gostd
49+
- github.com/ClickHouse/ch-go
50+
- github.com/fsnotify/fsnotify
51+
- github.com/getsentry/sentry-go
52+
- github.com/gin-gonic/gin
53+
- github.com/nikandfor/assert
54+
- github.com/opentracing/opentracing-go
55+
- github.com/prometheus/client_golang
56+
- github.com/prometheus/client_model
57+
- github.com/stretchr/testify/assert
58+
- github.com/stretchr/testify/require
59+
- go.opentelemetry.io/otel
60+
- golang.org/x
61+
- nikand.dev/go/cbor
62+
- nikand.dev/go/cli
63+
- nikand.dev/go/graceful
64+
- nikand.dev/go/hacked
65+
- tlog.app/go/eazy
66+
- tlog.app/go/errors
67+
- tlog.app/go/loc
68+
- tlog.app/go/tlog
69+
dupl:
70+
threshold: 100
71+
gocognit:
72+
min-complexity: 30
73+
goconst:
74+
min-len: 2
75+
min-occurrences: 3
76+
gocritic:
77+
disabled-checks:
78+
- appendAssign
79+
- appendCombine
80+
- builtinShadow
81+
- commentedOutCode
82+
- octalLiteral
83+
- unnamedResult
84+
- whyNoLint
85+
- yodaStyleExpr
86+
enabled-tags:
87+
- experimental
88+
- performance
89+
- style
90+
gosec:
91+
excludes:
92+
- G108
93+
- G114
94+
- G115
95+
lll:
96+
line-length: 170
97+
prealloc:
98+
simple: true
99+
for-loops: true
100+
revive:
101+
rules:
102+
- name: unused-parameter
103+
disabled: true
104+
exclusions:
105+
generated: lax
106+
presets:
107+
- comments
108+
- common-false-positives
109+
- legacy
110+
- std-error-handling
111+
paths:
112+
- third_party$
113+
- builtin$
114+
- examples$
115+
formatters:
116+
enable:
117+
- gofmt
118+
- gofumpt
119+
- goimports
120+
settings:
121+
goimports:
122+
local-prefixes:
123+
- github.com/nikandfor/tlog
124+
exclusions:
125+
generated: lax
126+
paths:
127+
- third_party$
128+
- builtin$
129+
- examples$

cmd/tlog/tlogcmd/main.go

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package tlogcmd
33
import (
44
"context"
55
"io"
6-
"io/fs"
76
"net"
87
"net/http"
98
_ "net/http/pprof"
@@ -39,11 +38,6 @@ type (
3938
perrWriter struct {
4039
io.WriteCloser
4140
}
42-
43-
listenerClose struct {
44-
net.Listener
45-
def []io.Closer
46-
}
4741
)
4842

4943
func App() *cli.Command {
@@ -306,8 +300,8 @@ func agentRun(c *cli.Command) (err error) {
306300
return errors.Wrap(err, "listen %v", host)
307301
}
308302

309-
switch {
310-
case u.Scheme == "unix", u.Scheme == "tcp":
303+
switch u.Scheme {
304+
case "unix", "tcp":
311305
group.Add(func(ctx context.Context) error {
312306
var wg sync.WaitGroup
313307

@@ -333,7 +327,7 @@ func agentRun(c *cli.Command) (err error) {
333327

334328
defer tr.Finish("err", &err)
335329

336-
defer closeWrap(c, &err, "close conn")
330+
defer closer(c, &err, "close conn")
337331

338332
if f, ok := a.(tlio.Flusher); ok {
339333
defer doWrap(f.Flush, &err, "flush db")
@@ -347,7 +341,7 @@ func agentRun(c *cli.Command) (err error) {
347341
}, graceful.WithStop(func(ctx context.Context) error {
348342
return l.Close()
349343
}))
350-
case u.Scheme == "unixgram", u.Scheme == "udp":
344+
case "unixgram", "udp":
351345
group.Add(func(ctx context.Context) error {
352346
buf := make([]byte, 0x1000)
353347

@@ -385,7 +379,7 @@ func cat(c *cli.Command) (err error) {
385379
tlflag.Describe(tlog.Root(), w)
386380
}
387381

388-
var fs *fsnotify.Watcher //nolint:gocritic
382+
var fs *fsnotify.Watcher
389383

390384
if c.Bool("follow") {
391385
fs, err = fsnotify.NewWatcher()
@@ -716,26 +710,6 @@ func (w perrWriter) Close() (err error) {
716710
return
717711
}
718712

719-
func isDir(name string) bool {
720-
inf, err := os.Stat(name)
721-
if err != nil {
722-
return false
723-
}
724-
725-
return inf.IsDir()
726-
}
727-
728-
func isFifo(name string) bool {
729-
inf, err := os.Stat(name)
730-
if err != nil {
731-
return false
732-
}
733-
734-
mode := inf.Mode()
735-
736-
return mode&fs.ModeNamedPipe != 0
737-
}
738-
739713
func listen(netw, addr string) (l net.Listener, p net.PacketConn, err error) {
740714
switch netw {
741715
case "unix", "unixgram":
@@ -767,44 +741,13 @@ func listen(netw, addr string) (l net.Listener, p net.PacketConn, err error) {
767741
return l, p, nil
768742
}
769743

770-
func (p listenerClose) SetDeadline(t time.Time) error {
771-
return p.Listener.(interface{ SetDeadline(time.Time) error }).SetDeadline(t)
772-
}
773-
774-
func (p listenerClose) Close() (err error) {
775-
err = p.Listener.Close()
776-
777-
for i := len(p.def) - 1; i >= 0; i-- {
778-
e := p.def[i].Close()
779-
if err == nil {
780-
err = e
781-
}
782-
}
783-
784-
return
785-
}
786-
787-
func closeWrap(c io.Closer, errp *error, msg string) {
744+
func closer(c io.Closer, errp *error, msg string) { //nolint:gocritic
788745
doWrap(c.Close, errp, msg)
789746
}
790747

791-
func flushWrap(x interface{}, errp *error, msg string) {
792-
if f, ok := x.(tlio.Flusher); ok {
793-
doWrap(f.Flush, errp, msg)
794-
}
795-
}
796-
797-
func doWrap(f func() error, errp *error, msg string) {
798-
e := f()
799-
if *errp == nil {
800-
*errp = errors.Wrap(e, msg)
801-
}
802-
}
803-
804-
func closeIfErr(c io.Closer, errp *error) {
748+
func doWrap(f func() error, errp *error, msg string) { //nolint:gocritic
749+
err := f()
805750
if *errp == nil {
806-
return
751+
*errp = errors.Wrap(err, msg)
807752
}
808-
809-
_ = c.Close()
810753
}

0 commit comments

Comments
 (0)