Skip to content

Commit fa804f4

Browse files
authored
Merge pull request #138 from legendu-net/dev
Merge dev into main
2 parents 4487425 + d7b9c9d commit fa804f4

38 files changed

+420
-857
lines changed

.github/workflows/lint.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- dev
6+
- main
7+
8+
jobs:
9+
golangci:
10+
name: lint
11+
runs-on: ubuntu-latest
12+
container:
13+
image: golangci/golangci-lint:v2.6.2-alpine
14+
steps:
15+
- uses: actions/checkout@v5
16+
- name: golangci-lint fmt
17+
run: |
18+
golangci-lint fmt -d

.golangci.yml

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# This configuration file is not a recommendation.
2+
#
3+
# We intentionally use a limited set of linters.
4+
# This configuration file is used with different version of golangci-lint to avoid regressions:
5+
# the linters can change between version,
6+
# their configuration may be not compatible or their reports can be different,
7+
# and this can break some of our tests.
8+
# Also, some linters are not relevant for the project (e.g. linters related to SQL).
9+
#
10+
# We have specific constraints, so we use a specific configuration.
11+
#
12+
# See the file `.golangci.reference.yml` to have a list of all available configuration options.
13+
14+
version: "2"
15+
16+
linters:
17+
default: none
18+
# This list of linters is not a recommendation (same thing for all this configuration file).
19+
# We intentionally use a limited set of linters.
20+
# See the comment on top of this file.
21+
enable:
22+
- bodyclose
23+
- copyloopvar
24+
- depguard
25+
- dogsled
26+
- dupl
27+
- errcheck
28+
- errorlint
29+
- funlen
30+
- gocheckcompilerdirectives
31+
- gochecknoinits
32+
- goconst
33+
- gocritic
34+
- gocyclo
35+
- godox
36+
- mnd
37+
- goprintffuncname
38+
- gosec
39+
- govet
40+
- intrange
41+
- ineffassign
42+
- lll
43+
- misspell
44+
- nakedret
45+
- noctx
46+
- nolintlint
47+
- revive
48+
- staticcheck
49+
- testifylint
50+
- unconvert
51+
- unparam
52+
- unused
53+
- whitespace
54+
55+
settings:
56+
depguard:
57+
rules:
58+
logger:
59+
deny:
60+
# logging is allowed only by logutils.Log,
61+
- pkg: "github.com/sirupsen/logrus"
62+
desc: logging is allowed only by logutils.Log.
63+
- pkg: "github.com/pkg/errors"
64+
desc: Should be replaced by standard lib errors package.
65+
- pkg: "github.com/instana/testify"
66+
desc: It's a fork of github.com/stretchr/testify.
67+
files:
68+
# logrus is allowed to use only in logutils package.
69+
- "!**/pkg/logutils/**.go"
70+
dupl:
71+
threshold: 100
72+
funlen:
73+
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
74+
statements: 50
75+
goconst:
76+
min-len: 2
77+
min-occurrences: 3
78+
gocritic:
79+
enabled-tags:
80+
- diagnostic
81+
- experimental
82+
- opinionated
83+
- performance
84+
- style
85+
disabled-checks:
86+
- dupImport # https://github.com/go-critic/go-critic/issues/845
87+
- ifElseChain
88+
- octalLiteral
89+
- whyNoLint
90+
gocyclo:
91+
min-complexity: 15
92+
godox:
93+
keywords:
94+
- FIXME
95+
mnd:
96+
# don't include the "operation" and "assign"
97+
checks:
98+
- argument
99+
- case
100+
- condition
101+
- return
102+
ignored-numbers:
103+
- '0'
104+
- '1'
105+
- '2'
106+
- '3'
107+
ignored-functions:
108+
- strings.SplitN
109+
govet:
110+
settings:
111+
printf:
112+
funcs:
113+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Infof
114+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Warnf
115+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Errorf
116+
- (github.com/golangci/golangci-lint/v2/pkg/logutils.Log).Fatalf
117+
enable:
118+
- nilness
119+
- shadow
120+
errorlint:
121+
asserts: false
122+
lll:
123+
line-length: 140
124+
misspell:
125+
locale: US
126+
ignore-rules:
127+
- "importas" # linter name
128+
nolintlint:
129+
allow-unused: false # report any unused nolint directives
130+
require-explanation: true # require an explanation for nolint directives
131+
require-specific: true # require nolint directives to be specific about which linter is being skipped
132+
revive:
133+
rules:
134+
- name: indent-error-flow
135+
- name: unexported-return
136+
disabled: true
137+
- name: unused-parameter
138+
- name: unused-receiver
139+
140+
exclusions:
141+
presets:
142+
- comments
143+
- std-error-handling
144+
- common-false-positives
145+
- legacy
146+
paths:
147+
- test/testdata_etc # test files
148+
- internal/go # extracted from Go code
149+
- internal/x # extracted from x/tools code
150+
- pkg/goformatters/gci/internal # extracted from gci code
151+
- pkg/goanalysis/runner_checker.go # extracted from x/tools code
152+
rules:
153+
- path: (.+)_test\.go
154+
linters:
155+
- dupl
156+
- mnd
157+
- lll
158+
159+
# Based on existing code, the modifications should be limited to make maintenance easier.
160+
- path: pkg/golinters/unused/unused.go
161+
linters: [gocritic]
162+
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"
163+
164+
# Related to the result of computation but divided multiple times by 1024.
165+
- path: test/bench/bench_test.go
166+
linters: [gosec]
167+
text: "G115: integer overflow conversion uint64 -> int"
168+
169+
# The files created during the tests don't need to be secured.
170+
- path: scripts/website/expand_templates/linters_test.go
171+
linters: [gosec]
172+
text: "G306: Expect WriteFile permissions to be 0600 or less"
173+
174+
# Related to migration command.
175+
- path: pkg/commands/internal/migrate/two/
176+
linters:
177+
- lll
178+
179+
# Related to migration command.
180+
- path: pkg/commands/internal/migrate/
181+
linters:
182+
- gocritic
183+
text: "hugeParam:"
184+
185+
# The codes are close but this is not duplication.
186+
- path: pkg/commands/(formatters|linters).go
187+
linters:
188+
- dupl
189+
190+
# Deprecated linters
191+
- path: pkg/lint/lintersdb/builder_linter.go
192+
text: "SA1019: wsl.NewV4 is deprecated: use NewV5 instead."
193+
linters:
194+
- staticcheck
195+
- path: pkg/golinters/wsl/wsl.go
196+
text: "SA1019: config.WSLv4Settings is deprecated: use WSLv5Settings instead."
197+
linters:
198+
- staticcheck
199+
200+
formatters:
201+
enable:
202+
- gofmt
203+
- goimports
204+
settings:
205+
gofmt:
206+
rewrite-rules:
207+
- pattern: 'interface{}'
208+
replacement: 'any'
209+
goimports:
210+
local-prefixes:
211+
- github.com/golangci/golangci-lint/v2
212+
exclusions:
213+
paths:
214+
- test/testdata_etc # test files
215+
- internal/go # extracted from Go code
216+
- internal/x # extracted from x/tools code
217+
- pkg/goformatters/gci/internal # extracted from gci code
218+
- pkg/goanalysis/runner_checker.go # extracted from x/tools code
219+

cmd/ai/pytorch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package ai
22

33
import (
4+
"strings"
5+
46
"github.com/spf13/cobra"
57
"legendu.net/icon/utils"
6-
"strings"
78
)
89

910
// Install and configure PyTorch.

cmd/bigdata/arrowdb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package bigdata
22

33
import (
44
//"embed"
5+
"path/filepath"
6+
57
"github.com/spf13/cobra"
68
"legendu.net/icon/utils"
7-
"path/filepath"
89
)
910

1011
func linkArrowDbProfileFromHost() {

cmd/bigdata/spark.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package bigdata
22

33
import (
4-
//"embed"
5-
"io"
64
"fmt"
7-
"github.com/spf13/cobra"
8-
"golang.org/x/sys/unix"
9-
"legendu.net/icon/utils"
5+
"io"
106
"log"
117
"net/http"
128
"path/filepath"
139
"regexp"
1410
"runtime"
1511
"strings"
12+
13+
"github.com/spf13/cobra"
14+
"golang.org/x/sys/unix"
15+
"legendu.net/icon/utils"
1616
)
1717

1818
// Get the latest version of Spark.
@@ -52,7 +52,7 @@ func getSparkDownloadUrl(sparkVersion string, hadoopVersion string) (string, str
5252
html := string(body)
5353
html = html[strings.Index(html, "<strong>")+8:]
5454
url = html[:strings.Index(html, "</strong>")]
55-
return url, url[strings.LastIndex(url, "/")+1:strings.LastIndex(url, ".")]
55+
return url, url[strings.LastIndex(url, "/")+1 : strings.LastIndex(url, ".")]
5656
}
5757

5858
// Install and configure Spark.

cmd/dev/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func getGitUserName(cmd *cobra.Command) string {
2424
if utils.GetBoolFlag(cmd, "yes") {
2525
return USER
2626
}
27-
fmt.Printf("Please enter the user name for Git: ")
27+
fmt.Print("Please enter the user name for Git: ")
2828
scanner := bufio.NewScanner(os.Stdin)
2929
scanner.Scan()
3030
err := scanner.Err()
@@ -42,7 +42,7 @@ func getGitUserEmail(cmd *cobra.Command) string {
4242
if utils.GetBoolFlag(cmd, "yes") {
4343
return USER + "@example.com"
4444
}
45-
fmt.Printf("Please enter the user email for Git: ")
45+
fmt.Print("Please enter the user email for Git: ")
4646
scanner := bufio.NewScanner(os.Stdin)
4747
scanner.Scan()
4848
err := scanner.Err()

cmd/dev/golang.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package dev
22

33
import (
4-
"github.com/spf13/cobra"
5-
"golang.org/x/sys/unix"
6-
"legendu.net/icon/utils"
74
"log"
85
"net/http"
96
"path/filepath"
107
"regexp"
118
"runtime"
129
"strings"
10+
11+
"github.com/spf13/cobra"
12+
"golang.org/x/sys/unix"
13+
"legendu.net/icon/utils"
1314
)
1415

1516
func getGolangVersion() string {

cmd/dev/pytype.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package dev
22

33
import (
4+
"log"
5+
"path/filepath"
6+
47
"github.com/elliotchance/orderedmap/v2"
58
"github.com/pelletier/go-toml/v2"
69
"github.com/spf13/cobra"
710
"legendu.net/icon/utils"
8-
"log"
9-
"path/filepath"
1011
)
1112

1213
// Install and configure pytype.

cmd/filesystem/rip.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package filesystem
22

33
import (
4+
"runtime"
5+
46
"github.com/spf13/cobra"
57
"legendu.net/icon/utils"
6-
"runtime"
78
)
89

910
// Install and configure rip (rm-improved).

cmd/ide/helix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package ide
22

33
import (
4+
"runtime"
5+
46
"github.com/spf13/cobra"
57
"legendu.net/icon/utils"
6-
"runtime"
78
)
89

910
// Install and configure helix.

0 commit comments

Comments
 (0)