Skip to content

Commit 3b16e36

Browse files
committed
chore: fix lint error
1 parent 21669dc commit 3b16e36

45 files changed

Lines changed: 224 additions & 188 deletions

Some content is hidden

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

.golangci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ linters:
2727
- name: increment-decrement
2828
- name: indent-error-flow
2929
- name: package-comments
30+
disabled: true
3031
- name: range
3132
- name: receiver-naming
3233
- name: redefines-builtin-id
@@ -38,7 +39,18 @@ linters:
3839
- name: var-declaration
3940
- name: var-naming
4041
staticcheck: # https://golangci-lint.run/usage/linters/#staticcheck
41-
checks: ["all", "-SA1019"]
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
4254

4355
formatters:
4456
enable:

cache/bolt_test.go

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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)

0 commit comments

Comments
 (0)