Skip to content

Commit

Permalink
chore(linter): change linter from golint to revive (#220)
Browse files Browse the repository at this point in the history
* chore(linter): change linter from golint to revive

* chore: fix commands and update golangci-lint version

* chore: fix goreleaser

* chore: fix lint error
  • Loading branch information
MaineK00n authored Dec 25, 2021
1 parent 0a854f8 commit 8df4f0b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.32
version: v1.42
args: --timeout=10m

# Optional: working directory, useful for monorepos
Expand Down
34 changes: 32 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
name: golang-ci

linters-settings:
errcheck:
revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: true
severity: warning
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
# errcheck:
#exclude: /path/to/file.txt

linters:
disable-all: true
enable:
- goimports
- golint
- revive
- govet
- misspell
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ builds:
goarch:
- amd64
main: .
ldflags: -s -w -X main.version={{.Version}} -X main.revision={{.Commit}}
ldflags: -s -w -X github.com/vulsio/go-cve-dictionary/config.Version={{.Version}} -X github.com/vulsio/go-cve-dictionary/config.Revision={{.Commit}}
binary: go-cve-dictionary
archives:
- name_template: '{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
Expand Down
30 changes: 30 additions & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unused-parameter]
[rule.unreachable-code]
[rule.redefines-builtin-id]
14 changes: 9 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: \
all \
build \
install \
all \
vendor \
lint \
vet \
fmt \
fmtcheck \
Expand Down Expand Up @@ -30,14 +30,18 @@ LDFLAGS := -X 'github.com/vulsio/go-cve-dictionary/config.Version=$(VERSION)' \
GO := GO111MODULE=on go
GO_OFF := GO111MODULE=off go

all: build
all: build test

build: main.go pretest fmt
build: main.go
$(GO) build -ldflags "$(LDFLAGS)" -o go-cve-dictionary $<

install: main.go
$(GO) install -ldflags "$(LDFLAGS)"

lint:
$(GO_OFF) get -u github.com/mgechev/revive
revive -config ./.revive.toml -formatter plain $(PKGS)

vet:
echo $(PKGS) | xargs env $(GO) vet || exit;

Expand All @@ -50,7 +54,7 @@ mlint:
fmtcheck:
$(foreach file,$(SRCS),gofmt -d $(file);)

pretest: vet fmtcheck
pretest: lint vet fmtcheck

test: pretest
$(GO) test -cover -v ./... || exit;
Expand Down
2 changes: 1 addition & 1 deletion commands/fetchjvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
fetchCmd.AddCommand(fetchJvnCmd)
}

func fetchJvn(cmd *cobra.Command, args []string) (err error) {
func fetchJvn(_ *cobra.Command, _ []string) (err error) {
if err := log.SetLogger(viper.GetBool("log-to-file"), viper.GetString("log-dir"), viper.GetBool("debug"), viper.GetBool("log-json")); err != nil {
return xerrors.Errorf("Failed to SetLogger. err: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion commands/fetchnvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
_ = viper.BindPFlag("full", fetchNvdCmd.PersistentFlags().Lookup("full"))
}

func fetchNvd(cmd *cobra.Command, args []string) (err error) {
func fetchNvd(_ *cobra.Command, _ []string) (err error) {
if err := log.SetLogger(viper.GetBool("log-to-file"), viper.GetString("log-dir"), viper.GetBool("debug"), viper.GetBool("log-json")); err != nil {
return xerrors.Errorf("Failed to SetLogger. err: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
_ = viper.BindPFlag("port", serverCmd.PersistentFlags().Lookup("port"))
}

func executeServer(cmd *cobra.Command, args []string) (err error) {
func executeServer(_ *cobra.Command, _ []string) (err error) {
if err := log.SetLogger(viper.GetBool("log-to-file"), viper.GetString("log-dir"), viper.GetBool("debug"), viper.GetBool("log-json")); err != nil {
return xerrors.Errorf("Failed to SetLogger. err: %w", err)
}
Expand Down
12 changes: 3 additions & 9 deletions db/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *RDBDriver) Name() string {
}

// OpenDB opens Database
func (r *RDBDriver) OpenDB(dbType, dbPath string, debugSQL bool, option Option) (locked bool, err error) {
func (r *RDBDriver) OpenDB(dbType, dbPath string, debugSQL bool, _ Option) (locked bool, err error) {
gormConfig := gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
Logger: gormLogger.New(
Expand Down Expand Up @@ -427,10 +427,7 @@ func deleteJvn(tx *gorm.DB) error {
if err := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.JvnReference{}).Error; err != nil {
return err
}
if err := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.JvnCert{}).Error; err != nil {
return err
}
return nil
return tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.JvnCert{}).Error
}

func insertJvn(tx *gorm.DB, cves []models.Jvn, batchSize int) error {
Expand Down Expand Up @@ -550,10 +547,7 @@ func deleteNvd(tx *gorm.DB) error {
if err := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.NvdReference{}).Error; err != nil {
return err
}
if err := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.NvdCert{}).Error; err != nil {
return err
}
return nil
return tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(models.NvdCert{}).Error
}

func insertNvd(tx *gorm.DB, cves []models.Nvd, batchSize int) error {
Expand Down
2 changes: 1 addition & 1 deletion db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *RedisDriver) Name() string {
}

// OpenDB opens Database
func (r *RedisDriver) OpenDB(dbType, dbPath string, debugSQL bool, option Option) (locked bool, err error) {
func (r *RedisDriver) OpenDB(dbType, dbPath string, _ bool, option Option) (locked bool, err error) {
if err = r.connectRedis(dbPath, option); err != nil {
err = xerrors.Errorf("Failed to open DB. dbtype: %s, dbpath: %s, err: %w", dbType, dbPath, err)
}
Expand Down

0 comments on commit 8df4f0b

Please sign in to comment.