Skip to content

Commit 54160f6

Browse files
chore(deps): bump golangci/golangci-lint-action from 6 to 7 (#2166)
* chore(deps): bump golangci/golangci-lint-action from 6 to 7 Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 7. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](golangci/golangci-lint-action@v6...v7) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * chore: fix lint error --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: MaineK00n <[email protected]>
1 parent f6cc8c2 commit 54160f6

Some content is hidden

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

46 files changed

+269
-237
lines changed

.github/workflows/golangci.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
branches:
77
- master
88
pull_request:
9-
permissions:
10-
contents: read
9+
permissions:
10+
contents: read
1111
jobs:
1212
golangci:
1313
name: lint
@@ -20,7 +20,6 @@ jobs:
2020
with:
2121
go-version-file: go.mod
2222
- name: golangci-lint
23-
uses: golangci/golangci-lint-action@v6
23+
uses: golangci/golangci-lint-action@v7
2424
with:
25-
version: v1.64.7
26-
args: --timeout=10m
25+
version: v2.0.2

.golangci.yml

+54-45
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
1-
run:
2-
timeout: 10m
3-
4-
linters-settings:
5-
revive:
6-
# see https://github.com/mgechev/revive#available-rules for details.
7-
ignore-generated-header: true
8-
severity: warning
9-
confidence: 0.8
10-
rules:
11-
- name: blank-imports
12-
- name: context-as-argument
13-
- name: context-keys-type
14-
- name: dot-imports
15-
- name: error-return
16-
- name: error-strings
17-
- name: error-naming
18-
- name: exported
19-
- name: if-return
20-
- name: increment-decrement
21-
- name: var-naming
22-
- name: var-declaration
23-
- name: package-comments
24-
- name: range
25-
- name: receiver-naming
26-
- name: time-naming
27-
- name: unexported-return
28-
- name: indent-error-flow
29-
- name: errorf
30-
- name: empty-block
31-
- name: superfluous-else
32-
- name: unused-parameter
33-
- name: unreachable-code
34-
- name: redefines-builtin-id
35-
staticcheck:
36-
# https://staticcheck.io/docs/options#checks
37-
checks: ["all", "-SA1019"]
38-
# errcheck:
39-
#exclude: /path/to/file.txt
1+
version: "2"
402

413
linters:
42-
disable-all: true
4+
default: none
435
enable:
44-
- goimports
45-
- revive
6+
- errcheck
467
- govet
8+
- ineffassign
479
- misspell
48-
- errcheck
49-
- staticcheck
5010
- prealloc
51-
- ineffassign
11+
- revive
12+
- staticcheck
13+
settings:
14+
revive: # https://golangci-lint.run/usage/linters/#revive
15+
rules:
16+
- name: blank-imports
17+
- name: context-as-argument
18+
- name: context-keys-type
19+
- name: dot-imports
20+
- name: empty-block
21+
- name: error-naming
22+
- name: error-return
23+
- name: error-strings
24+
- name: errorf
25+
- name: exported
26+
- name: if-return
27+
- name: increment-decrement
28+
- name: indent-error-flow
29+
- name: package-comments
30+
disabled: true
31+
- name: range
32+
- name: receiver-naming
33+
- name: redefines-builtin-id
34+
- name: superfluous-else
35+
- name: time-naming
36+
- name: unexported-return
37+
- name: unreachable-code
38+
- name: unused-parameter
39+
- name: var-declaration
40+
- name: var-naming
41+
staticcheck: # https://golangci-lint.run/usage/linters/#staticcheck
42+
checks:
43+
- all
44+
- -ST1000 # at least one file in a package should have a package comment
45+
- -ST1005 # error strings should not be capitalized
46+
exclusions:
47+
rules:
48+
- source: "defer .+\\.Close\\(\\)"
49+
linters:
50+
- errcheck
51+
- source: "defer os.Remove\\(.+\\)"
52+
linters:
53+
- errcheck
54+
55+
formatters:
56+
enable:
57+
- goimports
58+
59+
run:
60+
timeout: 10m

cache/bolt_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func TestSetupBolt(t *testing.T) {
5454
}
5555
return nil
5656
})
57-
5857
}
5958

6059
func TestEnsureBuckets(t *testing.T) {

config/config_v1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func convertToLatestConfig(pathToToml string) error {
133133
if err := toml.NewEncoder(&buf).Encode(c); err != nil {
134134
return xerrors.Errorf("Failed to encode to toml: %w", err)
135135
}
136-
str := strings.Replace(buf.String(), "\n [", "\n\n [", -1)
136+
str := strings.ReplaceAll(buf.String(), "\n [", "\n\n [")
137137
str = fmt.Sprintf("%s\n\n%s",
138138
"# See README for details: https://vuls.io/docs/en/config.toml.html",
139139
str)

config/scanmodule.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s ScanModule) IsScanPort() bool {
5656

5757
// IsZero return the struct value are all false
5858
func (s ScanModule) IsZero() bool {
59-
return !(s.IsScanOSPkg() || s.IsScanWordPress() || s.IsScanLockFile() || s.IsScanPort())
59+
return !s.IsScanOSPkg() && !s.IsScanWordPress() && !s.IsScanLockFile() && !s.IsScanPort()
6060
}
6161

6262
func (s *ScanModule) ensure() error {

config/slackconf.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ func (c *SlackConf) Validate() (errs []error) {
3232
if len(c.Channel) == 0 {
3333
errs = append(errs, xerrors.New("slack.channel must not be empty"))
3434
} else {
35-
if !(strings.HasPrefix(c.Channel, "#") ||
36-
c.Channel == "${servername}") {
37-
errs = append(errs, xerrors.Errorf(
38-
"channel's prefix must be '#', channel: %s", c.Channel))
35+
if !strings.HasPrefix(c.Channel, "#") && c.Channel != "${servername}" {
36+
errs = append(errs, xerrors.Errorf("channel's prefix must be '#', channel: %s", c.Channel))
3937
}
4038
}
4139

contrib/future-vuls/pkg/config/config.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
package config
33

44
const (
5-
DiscoverTomlFileName = "discover_list.toml"
6-
SnmpVersion = "v2c"
7-
FvulsDomain = "vuls.biz"
8-
Community = "public"
5+
// DiscoverTomlFileName ...
6+
DiscoverTomlFileName = "discover_list.toml"
7+
// SnmpVersion ...
8+
SnmpVersion = "v2c"
9+
// FvulsDomain ...
10+
FvulsDomain = "vuls.biz"
11+
// Community ...
12+
Community = "public"
13+
// DiscoverTomlTimeStampFormat ...
914
DiscoverTomlTimeStampFormat = "20060102150405"
1015
)
1116

contrib/future-vuls/pkg/discover/discover.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ func executeSnmp2cpe(addr string, snmpVersion string, community string) (cpes ma
113113
if _, err := stdin.Write(result); err != nil {
114114
return nil, fmt.Errorf("failed to write to stdIn. err: %v", err)
115115
}
116-
stdin.Close()
116+
if err := stdin.Close(); err != nil {
117+
return nil, fmt.Errorf("failed to close stdIn. err: %v", err)
118+
}
117119
output, err := cmd.Output()
118120
if err != nil {
119121
return nil, fmt.Errorf("failed to convert snmp2cpe result. err: %v", err)

contrib/snmp2cpe/pkg/cmd/version/version.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/pkg/errors"
78
"github.com/spf13/cobra"
89

910
"github.com/future-architect/vuls/config"
@@ -15,8 +16,11 @@ func NewCmdVersion() *cobra.Command {
1516
Use: "version",
1617
Short: "Print the version",
1718
Args: cobra.NoArgs,
18-
Run: func(_ *cobra.Command, _ []string) {
19-
fmt.Fprintf(os.Stdout, "snmp2cpe %s %s\n", config.Version, config.Revision)
19+
RunE: func(_ *cobra.Command, _ []string) error {
20+
if _, err := fmt.Fprintf(os.Stdout, "snmp2cpe %s %s\n", config.Version, config.Revision); err != nil {
21+
return errors.Wrap(err, "failed to print version")
22+
}
23+
return nil
2024
},
2125
}
2226
return cmd

contrib/trivy/pkg/converter.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
154154
}
155155

156156
// --list-all-pkgs flg of trivy will output all installed packages, so collect them.
157-
if trivyResult.Class == types.ClassOSPkg {
157+
switch trivyResult.Class {
158+
case types.ClassOSPkg:
158159
for _, p := range trivyResult.Packages {
159160
pv := p.Version
160161
if p.Release != "" {
@@ -186,7 +187,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
186187
v.AddBinaryName(p.Name)
187188
srcPkgs[p.SrcName] = v
188189
}
189-
} else if trivyResult.Class == types.ClassLangPkg {
190+
case types.ClassLangPkg:
190191
libScanner := uniqueLibraryScannerPaths[trivyResult.Target]
191192
libScanner.Type = trivyResult.Type
192193
for _, p := range trivyResult.Packages {
@@ -198,6 +199,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
198199
})
199200
}
200201
uniqueLibraryScannerPaths[trivyResult.Target] = libScanner
202+
default:
201203
}
202204
}
203205

detector/cti.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package detector
44

55
import (
66
"encoding/json"
7+
"errors"
78
"net/http"
89
"time"
910

@@ -212,7 +213,7 @@ func newCTIDB(cnf config.VulnDictInterface) (ctidb.DB, error) {
212213
}
213214
driver, err := ctidb.NewDB(cnf.GetType(), path, cnf.GetDebugSQL(), ctidb.Option{})
214215
if err != nil {
215-
if xerrors.Is(err, ctidb.ErrDBLocked) {
216+
if errors.Is(err, ctidb.ErrDBLocked) {
216217
return nil, xerrors.Errorf("Failed to init cti DB. SQLite3: %s is locked. err: %w", cnf.GetSQLite3Path(), err)
217218
}
218219
return nil, xerrors.Errorf("Failed to init cti DB. DB Path: %s, err: %w", path, err)

detector/cve_client.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package detector
44

55
import (
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"net/http"
910
"time"
@@ -68,15 +69,13 @@ func (client goCveDictClient) fetchCveDetails(cveIDs []string) (cveDetails []cve
6869
tasks := util.GenWorkers(concurrency)
6970
for range cveIDs {
7071
tasks <- func() {
71-
select {
72-
case cveID := <-reqChan:
73-
url, err := util.URLPathJoin(client.baseURL, "cves", cveID)
74-
if err != nil {
75-
errChan <- err
76-
} else {
77-
logging.Log.Debugf("HTTP Request to %s", url)
78-
httpGet(cveID, url, resChan, errChan)
79-
}
72+
cveID := <-reqChan
73+
url, err := util.URLPathJoin(client.baseURL, "cves", cveID)
74+
if err != nil {
75+
errChan <- err
76+
} else {
77+
logging.Log.Debugf("HTTP Request to %s", url)
78+
httpGet(cveID, url, resChan, errChan)
8079
}
8180
}
8281
}
@@ -214,7 +213,7 @@ func newCveDB(cnf config.VulnDictInterface) (cvedb.DB, error) {
214213
}
215214
driver, err := cvedb.NewDB(cnf.GetType(), path, cnf.GetDebugSQL(), cvedb.Option{})
216215
if err != nil {
217-
if xerrors.Is(err, cvedb.ErrDBLocked) {
216+
if errors.Is(err, cvedb.ErrDBLocked) {
218217
return nil, xerrors.Errorf("Failed to init CVE DB. SQLite3: %s is locked. err: %w", cnf.GetSQLite3Path(), err)
219218
}
220219
return nil, xerrors.Errorf("Failed to init CVE DB. DB Path: %s, err: %w", path, err)

detector/detector.go

-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ func FillCweDict(r *models.ScanResult) {
754754
dict[id] = entry
755755
}
756756
r.CweDict = dict
757-
return
758757
}
759758

760759
func fillCweRank(entry *models.CweDictEntry, id string) {

detector/exploitdb.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package detector
44

55
import (
66
"encoding/json"
7+
"errors"
78
"net/http"
89
"time"
910

@@ -248,7 +249,7 @@ func newExploitDB(cnf config.VulnDictInterface) (exploitdb.DB, error) {
248249
}
249250
driver, err := exploitdb.NewDB(cnf.GetType(), path, cnf.GetDebugSQL(), exploitdb.Option{})
250251
if err != nil {
251-
if xerrors.Is(err, exploitdb.ErrDBLocked) {
252+
if errors.Is(err, exploitdb.ErrDBLocked) {
252253
return nil, xerrors.Errorf("Failed to init exploit DB. SQLite3: %s is locked. err: %w", cnf.GetSQLite3Path(), err)
253254
}
254255
return nil, xerrors.Errorf("Failed to init exploit DB. DB Path: %s, err: %w", path, err)

detector/kevuln.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package detector
44

55
import (
66
"encoding/json"
7+
"errors"
78
"net/http"
89
"time"
910

@@ -90,7 +91,7 @@ func FillWithKEVuln(r *models.ScanResult, cnf config.KEVulnConf, logOpts logging
9091
KnownRansomwareCampaignUse: k.KnownRansomwareCampaignUse,
9192
DateAdded: k.DateAdded,
9293
DueDate: func() *time.Time {
93-
if k.DueDate == time.Date(1000, time.January, 1, 0, 0, 0, 0, time.UTC) {
94+
if k.DueDate.Equal(time.Date(1000, time.January, 1, 0, 0, 0, 0, time.UTC)) {
9495
return nil
9596
}
9697
return &k.DueDate
@@ -174,7 +175,7 @@ func FillWithKEVuln(r *models.ScanResult, cnf config.KEVulnConf, logOpts logging
174175
KnownRansomwareCampaignUse: k.KnownRansomwareCampaignUse,
175176
DateAdded: k.DateAdded,
176177
DueDate: func() *time.Time {
177-
if k.DueDate == time.Date(1000, time.January, 1, 0, 0, 0, 0, time.UTC) {
178+
if k.DueDate.Equal(time.Date(1000, time.January, 1, 0, 0, 0, 0, time.UTC)) {
178179
return nil
179180
}
180181
return &k.DueDate
@@ -343,7 +344,7 @@ func newKEVulnDB(cnf config.VulnDictInterface) (kevulndb.DB, error) {
343344
}
344345
driver, err := kevulndb.NewDB(cnf.GetType(), path, cnf.GetDebugSQL(), kevulndb.Option{})
345346
if err != nil {
346-
if xerrors.Is(err, kevulndb.ErrDBLocked) {
347+
if errors.Is(err, kevulndb.ErrDBLocked) {
347348
return nil, xerrors.Errorf("Failed to init kevuln DB. SQLite3: %s is locked. err: %w", cnf.GetSQLite3Path(), err)
348349
}
349350
return nil, xerrors.Errorf("Failed to init kevuln DB. DB Path: %s, err: %w", path, err)

detector/msf.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package detector
44

55
import (
66
"encoding/json"
7+
"errors"
78
"net/http"
89
"time"
910

@@ -234,7 +235,7 @@ func newMetasploitDB(cnf config.VulnDictInterface) (metasploitdb.DB, error) {
234235
}
235236
driver, err := metasploitdb.NewDB(cnf.GetType(), path, cnf.GetDebugSQL(), metasploitdb.Option{})
236237
if err != nil {
237-
if xerrors.Is(err, metasploitdb.ErrDBLocked) {
238+
if errors.Is(err, metasploitdb.ErrDBLocked) {
238239
return nil, xerrors.Errorf("Failed to init metasploit DB. SQLite3: %s is locked. err: %w", cnf.GetSQLite3Path(), err)
239240
}
240241
return nil, xerrors.Errorf("Failed to init metasploit DB. DB Path: %s, err: %w", path, err)

detector/wordpress.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ func detectWordPressCves(r *models.ScanResult, cnf config.WpScanConf) (int, erro
7878
return 0, nil
7979
}
8080
// Core
81-
ver := strings.Replace(r.WordPressPackages.CoreVersion(), ".", "", -1)
81+
ver := strings.ReplaceAll(r.WordPressPackages.CoreVersion(), ".", "")
8282
if ver == "" {
83-
return 0, errof.New(errof.ErrFailedToAccessWpScan,
84-
fmt.Sprintf("Failed to get WordPress core version."))
83+
return 0, errof.New(errof.ErrFailedToAccessWpScan, "Failed to get WordPress core version.")
8584
}
8685
url := fmt.Sprintf("https://wpscan.com/api/v3/wordpresses/%s", ver)
8786
wpVinfos, err := wpscan(url, ver, cnf.Token, true)

0 commit comments

Comments
 (0)