Skip to content

Commit a917801

Browse files
authored
improve golangci-lint config (polarismesh#103)
* feat: improve golangci.yml and upgrade package version * feat: improve golangci-lint config * fix * feat: go mod tidy * modify go version * Version rollback * test: modify local regex spread time * feat: improve code and comment
1 parent 0cadab4 commit a917801

File tree

44 files changed

+379
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+379
-203
lines changed

.github/workflows/golangci-lint.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Tencent is pleased to support the open source community by making Polaris available.
2+
#
3+
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
#
5+
# Licensed under the BSD 3-Clause License (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://opensource.org/licenses/BSD-3-Clause
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
16+
name: golangci-lint
17+
on:
18+
push:
19+
branches:
20+
- main
21+
- release*
22+
- feature/**
23+
pull_request:
24+
branches:
25+
- main
26+
- release*
27+
- feature/**
28+
29+
jobs:
30+
golangci:
31+
strategy:
32+
matrix:
33+
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
34+
name: golangci-lint
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/setup-go@v3
38+
- uses: actions/checkout@v3
39+
- name: golangci-lint
40+
uses: golangci/[email protected]
41+
with:
42+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
43+
version: latest

.github/workflows/revive.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Tencent is pleased to support the open source community by making Polaris available.
2+
#
3+
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
#
5+
# Licensed under the BSD 3-Clause License (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://opensource.org/licenses/BSD-3-Clause
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
16+
name: revive
17+
on:
18+
push:
19+
branches:
20+
- main
21+
- release*
22+
- feature/**
23+
pull_request:
24+
branches:
25+
- main
26+
- release*
27+
- feature/**
28+
29+
jobs:
30+
reviveci:
31+
strategy:
32+
matrix:
33+
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
34+
name: Run Revive Action
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/setup-go@v3
38+
- uses: actions/checkout@v3
39+
- name: Run Revive Action
40+
uses: morphy2k/revive-action@v2
41+
with:
42+
# Path to your Revive config within the repo (optional)
43+
config: revive.toml

.github/workflows/testing.yml

+16-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# Tencent is pleased to support the open source community by making Polaris available.
2+
#
3+
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
#
5+
# Licensed under the BSD 3-Clause License (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://opensource.org/licenses/BSD-3-Clause
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
16+
117
name: Go
218

319
on:
@@ -18,36 +34,6 @@ env:
1834
GO111MODULE: on
1935

2036
jobs:
21-
22-
golangci:
23-
strategy:
24-
matrix:
25-
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
26-
name: golangci-lint
27-
runs-on: ubuntu-latest
28-
steps:
29-
- uses: actions/setup-go@v3
30-
- uses: actions/checkout@v3
31-
- name: golangci-lint
32-
uses: golangci/[email protected]
33-
with:
34-
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
35-
version: latest
36-
Reviveci:
37-
strategy:
38-
matrix:
39-
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
40-
name: Run Revive Action
41-
runs-on: ubuntu-latest
42-
steps:
43-
- uses: actions/setup-go@v3
44-
- uses: actions/checkout@v3
45-
- name: Run Revive Action
46-
uses: morphy2k/revive-action@v2
47-
with:
48-
# Path to your Revive config within the repo (optional)
49-
config: revive.toml
50-
5137
build:
5238
runs-on: ubuntu-latest
5339
# strategy set

.golangci.yml

+84-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
run:
33
issues-exit-code: 1 #Default
44
tests: true #Default
5+
skip-dirs: # 设置要忽略的目录
6+
- test
7+
- .*~
8+
- api/swagger/docs
9+
skip-files: # 设置不需要检查的go源码文件,支持正则匹配
10+
- ".*.my.go$"
11+
- ".*.pb.go$"
12+
- _test.go
513

614
linters:
715
# Disable everything by default so upgrades to not include new "default
@@ -11,16 +19,17 @@ linters:
1119
enable:
1220
# - deadcode
1321
# - errcheck
14-
# - funlen
15-
# - gocritic
16-
# - gofmt
22+
- funlen
23+
- gocritic
24+
- gocyclo
25+
- gofmt
1726
- goimports
18-
# - gosimple
27+
- gosimple
1928
- govet
2029
- godot
2130
# - ineffassign
2231
- misspell
23-
# - revive
32+
- revive
2433
# - staticcheck
2534
# - structcheck
2635
- typecheck
@@ -76,9 +85,33 @@ linters-settings:
7685
- name: atomic
7786
- name: line-length-limit
7887
severity: error
79-
arguments: [195]
88+
arguments: [180]
8089
- name: unhandled-error
81-
arguments : ["fmt.Printf", "myFunction"]
90+
arguments : ["fmt.Printf", "myFunction", "builder.WriteString","buf.WriteByte","buf.WriteRune","buf.WriteString","buf.WriteTo","buf.Write","fmt.Println","iteratorInstancesProc","buffer.Write","buffer.WriteString","h.Write","fmt.Fprintf","io.WriteString","e.reportAPIStat","f.Close"]
91+
severity: warning
92+
- name: var-naming
93+
severity: warning
94+
disabled: true
95+
arguments:
96+
- [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url","maxQps","ErrorCodeRpcError","ErrorCodeRpcTimeout","Ttl"] # AllowList
97+
- [ "VM" ] # DenyList
98+
- name: string-format
99+
severity: warning
100+
disabled: false
101+
arguments:
102+
- - 'core.WriteError[1].Message'
103+
- '/^([^A-Z]|$)/'
104+
- must not start with a capital letter
105+
- - 'fmt.Errorf[0]'
106+
- '/(^|[^\.!?])$/'
107+
- must not end in punctuation
108+
- - panic
109+
- '/^[^\n]*$/'
110+
- must not contain line breaks
111+
- name: function-result-limit
112+
severity: warning
113+
disabled: false
114+
arguments: [ 4 ]
82115
funlen:
83116
# Checks the number of lines in a function.
84117
# If lower than 0, disable the check.
@@ -87,8 +120,50 @@ linters-settings:
87120
# Checks the number of statements in a function.
88121
# If lower than 0, disable the check.
89122
# Default: 40
90-
statements: 40
123+
statements: -1
91124
goconst:
125+
# Minimal length of string constant.
126+
# Default: 3
127+
min-len: 2
128+
# Minimum occurrences of constant string count to trigger issue.
129+
# Default: 3
130+
# For subsequent optimization, the value is reduced.
131+
min-occurrences: 3
92132
# Ignore test files.
93133
# Default: false
94-
ignore-tests: true
134+
ignore-tests: true
135+
# Look for existing constants matching the values.
136+
# Default: true
137+
match-constant: false
138+
# Search also for duplicated numbers.
139+
# Default: false
140+
numbers: true
141+
# Minimum value, only works with goconst.numbers
142+
# Default: 3
143+
min: 3
144+
# Maximum value, only works with goconst.numbers
145+
# Default: 3
146+
max: 3
147+
# Ignore when constant is not used as function argument.
148+
# Default: true
149+
ignore-calls: false
150+
gocritic:
151+
disabled-checks:
152+
- ifElseChain
153+
- assignOp
154+
- appendAssign
155+
- singleCaseSwitch
156+
- badCall
157+
- underef
158+
gocyclo:
159+
# Minimal code complexity to report.
160+
# Default: 30 (but we recommend 10-20)
161+
min-complexity: 30
162+
gosimple:
163+
# Select the Go version to target.
164+
# Default: 1.13
165+
# Deprecated: use the global `run.go` instead.
166+
go: "1.15"
167+
# Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
168+
# Default: ["*"]
169+
checks: ["all","-S1001","-S1000","-S1025"]

api/README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
#### 配置初始化
66

77
```go
8-
//使用默认配置对象来初始化配置,连接默认的北极星埋点域名
8+
// 使用默认配置对象来初始化配置,连接默认的北极星埋点域名
99
cfg := api.NewConfiguration()
1010
```
1111

1212
#### 修改北极星后端集群名
1313

1414
```go
15-
//先初始化配置
15+
// 先初始化配置
1616
cfg := api.NewConfiguration()
17-
//修改发现server集群名
17+
// 修改发现server集群名
1818
cfg.GetGlobal().GetSystem().GetDiscoverCluster().SetService("polaris-server")
19-
//修改心跳server集群名
19+
// 修改心跳server集群名
2020
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("healthcheck")
21-
//修改监控server集群名
21+
// 修改监控server集群名
2222
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("polaris.monitor")
2323
```
2424

@@ -28,7 +28,7 @@ cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("polaris.monitor"
2828

2929
```go
3030
if err := api.SetLoggersDir("/tmp/polaris/log"); err != nil {
31-
//do error handle
31+
// do error handle
3232
}
3333
```
3434

@@ -38,18 +38,19 @@ if err := api.SetLoggersDir("/tmp/polaris/log"); err != nil {
3838

3939
```go
4040
if err := api.SetLoggersLevel(api.InfoLog); err != nil {
41-
//do error handle
41+
// do error handle
4242
}
4343
```
4444

4545
日志级别支持NoneLog, TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog, FatalLog,设置成NoneLog,则不打印任何日志
4646

4747
#### 同时修改北极星日志路径及日志级别
4848

49-
polaris-go启动后,默认会在程序运行的当前目录创建polaris/log目录,用于存放运行过程中的日志。因此用户需要保证当前目录有写权限 假如需要修改北极星的日志打印目录以及日志级别,可以按照以下方式进行修改
49+
polaris-go启动后,默认会在程序运行的当前目录创建polaris/log目录,用于存放运行过程中的日志。因此用户需要保证当前目录有写权限
50+
假如需要修改北极星的日志打印目录以及日志级别,可以按照以下方式进行修改
5051

5152
```go
5253
if err := api.ConfigLoggers("/tmp/polaris/log", api.InfoLog); err != nil {
53-
//do error handle
54+
// do error handle
5455
}
5556
```

0 commit comments

Comments
 (0)