Skip to content

Commit b588475

Browse files
authored
Merge pull request #380 from pohly/golangci-lint-action
golangci-lint action
2 parents edee20c + 1a0dfc5 commit b588475

File tree

33 files changed

+225
-184
lines changed

33 files changed

+225
-184
lines changed

.github/workflows/lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run lint
2+
3+
on: [ push, pull_request ]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
lint:
10+
strategy:
11+
matrix:
12+
path:
13+
- .
14+
- examples
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
- name: Lint
20+
uses: golangci/golangci-lint-action@v2
21+
with:
22+
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
23+
version: latest
24+
working-directory: ${{ matrix.path }}

.github/workflows/test.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ jobs:
2020
go test -v -race ./...
2121
- name: Test examples
2222
run: cd examples && go test -v -race ./...
23-
lint:
24-
runs-on: ubuntu-latest
25-
steps:
26-
- name: Install Go
27-
uses: actions/setup-go@v1
28-
- name: Checkout code
29-
uses: actions/checkout@v2
30-
- name: Lint
31-
run: |
32-
docker run --rm -v `pwd`:/go/src/k8s.io/klog -w /go/src/k8s.io/klog \
33-
golangci/golangci-lint:v1.50.1 golangci-lint run --disable-all -v \
34-
-E govet -E misspell -E gofmt -E ineffassign -E golint
3523
apidiff:
3624
runs-on: ubuntu-latest
3725
if: github.base_ref

.golangci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
linters:
2+
disable-all: true
3+
enable: # sorted alphabetical
4+
- gofmt
5+
- misspell
6+
- revive

examples/benchmarks/benchmarks_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"go.uber.org/zap"
2828
"go.uber.org/zap/zapcore"
2929

30+
"k8s.io/klog/examples/util/require"
3031
"k8s.io/klog/v2"
3132
)
3233

@@ -38,11 +39,11 @@ func init() {
3839
// klog gets configured so that it writes to a single output file that
3940
// will be set during tests with SetOutput.
4041
klog.InitFlags(nil)
41-
flag.Set("v", fmt.Sprintf("%d", verbosityThreshold))
42-
flag.Set("log_file", "/dev/null")
43-
flag.Set("logtostderr", "false")
44-
flag.Set("alsologtostderr", "false")
45-
flag.Set("stderrthreshold", "10")
42+
require.NoError(flag.Set("v", fmt.Sprintf("%d", verbosityThreshold)))
43+
require.NoError(flag.Set("log_file", "/dev/null"))
44+
require.NoError(flag.Set("logtostderr", "false"))
45+
require.NoError(flag.Set("alsologtostderr", "false"))
46+
require.NoError(flag.Set("stderrthreshold", "10"))
4647
}
4748

4849
type testcase struct {

examples/coexist_glog/coexist_glog.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"flag"
55

66
"github.com/golang/glog"
7+
"k8s.io/klog/examples/util/require"
78
"k8s.io/klog/v2"
89
)
910

1011
func main() {
11-
flag.Set("alsologtostderr", "true")
12+
require.NoError(flag.Set("alsologtostderr", "true"))
1213
flag.Parse()
1314

1415
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
@@ -19,7 +20,7 @@ func main() {
1920
f2 := klogFlags.Lookup(f1.Name)
2021
if f2 != nil {
2122
value := f1.Value.String()
22-
f2.Value.Set(value)
23+
require.NoError(f2.Value.Set(value))
2324
}
2425
})
2526

examples/flushing/flushing_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"testing"
66

77
"go.uber.org/goleak"
8+
9+
"k8s.io/klog/examples/util/require"
810
"k8s.io/klog/v2"
911
)
1012

@@ -13,8 +15,8 @@ func main() {
1315

1416
// By default klog writes to stderr. Setting logtostderr to false makes klog
1517
// write to a log file.
16-
flag.Set("logtostderr", "false")
17-
flag.Set("log_file", "myfile.log")
18+
require.NoError(flag.Set("logtostderr", "false"))
19+
require.NoError(flag.Set("log_file", "myfile.log"))
1820
flag.Parse()
1921

2022
// Info writes the first log message. When the first log file is created,

examples/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module example
1+
module k8s.io/klog/examples
22

33
go 1.13
44

examples/klogr/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"flag"
55

6+
"k8s.io/klog/examples/util/require"
67
"k8s.io/klog/v2"
78
"k8s.io/klog/v2/klogr"
89
)
@@ -17,7 +18,7 @@ func (e myError) Error() string {
1718

1819
func main() {
1920
klog.InitFlags(nil)
20-
flag.Set("v", "3")
21+
require.NoError(flag.Set("v", "3"))
2122
flag.Parse()
2223
log := klogr.New().WithName("MyName").WithValues("user", "you")
2324
log.Info("hello", "val1", 1, "val2", map[string]int{"k": 1})

examples/log_file/usage_log_file.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package main
33
import (
44
"flag"
55

6+
"k8s.io/klog/examples/util/require"
67
"k8s.io/klog/v2"
78
)
89

910
func main() {
1011
klog.InitFlags(nil)
1112
// By default klog writes to stderr. Setting logtostderr to false makes klog
1213
// write to a log file.
13-
flag.Set("logtostderr", "false")
14-
flag.Set("log_file", "myfile.log")
14+
require.NoError(flag.Set("logtostderr", "false"))
15+
require.NoError(flag.Set("log_file", "myfile.log"))
1516
flag.Parse()
1617
klog.Info("nice to meet you")
1718
klog.Flush()

examples/output_test/output_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434
"k8s.io/klog/v2/textlogger"
3535
)
3636

37-
func newLogger(out io.Writer, v int, vmodule string) logr.Logger {
37+
// newLogger is a test.OutputConfig.NewLogger callback which creates a zapr
38+
// logger. The vmodule parameter is ignored because zapr does not support that.
39+
func newLogger(out io.Writer, v int, _ string) logr.Logger {
3840
return newZaprLogger(out, v)
3941
}
4042

0 commit comments

Comments
 (0)