Skip to content

Commit

Permalink
Improve linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena committed Jun 3, 2022
1 parent 5675cf5 commit aae4864
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 7 deletions.
82 changes: 82 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 16

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# list of build tags, all linters use it. Default is empty list.
build-tags: []

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- win_eventlog$
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- .*.pb.go
- .*.y.go
- .*.rl.go
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

linters-settings:
goimports:
local-prefixes: github.com/grafana/fire/pkg,github.com/grafana/fire/tools

depguard:
list-type: blacklist
include-go-root: true
packages-with-error-message:
- github.com/go-kit/kit/log: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"

linters:
enable:
- deadcode
- errcheck
- goconst
- gofmt
- goimports
- revive
- ineffassign
- staticcheck
- misspell
- structcheck
- unconvert
- unparam
- varcheck
- govet
- unused
- typecheck
- depguard
- exportloopref

issues:
exclude:
- Error return value of .*log\.Logger\)\.Log\x60 is not checked
- Error return value of .*.Log.* is not checked
- Error return value of `` is not checked
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
.PHONY: build clean go/deps go/bin go/deps go/lint
.PHONY: all
all: lint test build

build: go/bin
.PHONY: lint
lint: go/lint

clean:
rm -rf bin
.PHONY: test
test: go/test

.PHONY: go/test
go/test:
go test -v ./...

.PHONY: build
build: go/bin

.PHONY: go/deps
go/deps:
go mod tidy

.PHONY: go/bin
go/bin:
mkdir -p ./bin
go build -o bin/ ./cmd/fire

.PHONY: go/lint
go/lint:
golangci-lint run

.PHONY: clean
clean:
rm -rf bin
4 changes: 3 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func (a *Agent) running(ctx context.Context) error {
level.Error(a.logger).Log("msg", "error running discovery manager", "err", err)
}
}()
a.manager.ApplyConfig(a.jobs)
if err := a.manager.ApplyConfig(a.jobs); err != nil {
return nil
}

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (tg *TargetGroup) targetsFromGroup(group *targetgroup.Group) ([]*Target, er
}
lbls, origLabels, err := populateLabels(lset, tg.config)
if err != nil {
return nil, fmt.Errorf("instance %d in group %s: %s", i, tg, err)
return nil, fmt.Errorf("instance %d in group %s: %s", i, group, err)
}
if lbls != nil || origLabels != nil {
params := tg.config.Params
Expand Down
3 changes: 2 additions & 1 deletion pkg/fire/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/services"
"github.com/grafana/fire/pkg/agent"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/server"
"github.com/weaveworks/common/user"

"github.com/grafana/fire/pkg/agent"
)

// The various modules that make up Fire.
Expand Down

0 comments on commit aae4864

Please sign in to comment.