Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint action #380

Merged
merged 3 commits into from
Oct 26, 2023
Merged

Commits on Jun 1, 2023

  1. fix golangci-lint issues

    golangci-lint v1.52.2 in its default configuration pointed out several issues
    that are worth fixing:
    
        internal/verbosity/verbosity_test.go:26:18: Error return value of `vs.verbosity.Set` is not checked (errcheck)
        	vs.verbosity.Set("2")
        	                ^
        internal/verbosity/verbosity_test.go:41:16: Error return value of `vs.vmodule.Set` is not checked (errcheck)
        	vs.vmodule.Set("verbosity_test=2")
        	              ^
        internal/verbosity/verbosity_test.go:84:16: Error return value of `vs.vmodule.Set` is not checked (errcheck)
        	vs.vmodule.Set(pat)
        	              ^
        internal/verbosity/verbosity.go:291:2: S1017: should replace this if statement with an unconditional strings.TrimSuffix (gosimple)
        	if strings.HasSuffix(file, ".go") {
        	^
        textlogger/options.go:140:19: Error return value of `(flag.Value).Set` is not checked (errcheck)
        	c.Verbosity().Set(strconv.FormatInt(int64(c.co.verbosityDefault), 10))
        	                 ^
        textlogger/textlogger.go:137:26: Error return value of `l.config.co.output.Write` is not checked (errcheck)
        	l.config.co.output.Write(b.Bytes())
        	                        ^
        textlogger/textlogger.go:141:26: Error return value of `l.config.co.output.Write` is not checked (errcheck)
        	l.config.co.output.Write(data)
        	                        ^
        ktesting/options.go:163:18: Error return value of `(flag.Value).Set` is not checked (errcheck)
        	c.vstate.V().Set(strconv.FormatInt(int64(c.co.verbosityDefault), 10))
        	                ^
        klogr/calldepth-test/call_depth_main_test.go:21:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("v", "10")
        	                    ^
        klogr/calldepth-test/call_depth_main_test.go:22:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("skip_headers", "false")
        	                    ^
        klogr/calldepth-test/call_depth_main_test.go:23:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("logtostderr", "false")
        	                    ^
        klog.go:903:34: Error return value of `(io.Writer).Write` is not checked (errcheck)
        			l.file[severity.InfoLog].Write(data)
        			                              ^
        klog.go:913:20: Error return value of `(io.Writer).Write` is not checked (errcheck)
        				l.file[s].Write(data)
        				               ^
        klog.go:917:37: Error return value of `(io.Writer).Write` is not checked (errcheck)
        					l.file[severity.FatalLog].Write(data)
        					                               ^
        klog.go:952:12: Error return value of `f.Write` is not checked (errcheck)
        				f.Write(trace)
        				       ^
        klog.go:1208:13: Error return value of `file.Sync` is not checked (errcheck)
        			file.Sync()  // ignore error
        			         ^
        klog_file.go:113:14: Error return value of `os.Symlink` is not checked (errcheck)
        			os.Symlink(name, symlink) // ignore err
        			          ^
        klog_test.go:328:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("2")
        	                     ^
        klog_test.go:343:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set("klog_test=2")
        	                   ^
        klog_test.go:367:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set("notthisfile=2")
        	                   ^
        klog_test.go:459:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set(pat)
        	                   ^
        klog_test.go:807:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("0")
        	                     ^
        klog_test.go:878:9: Error return value of `fs1.Set` is not checked (errcheck)
        	fs1.Set("log_dir", "/test1")
        	       ^
        klog_test.go:879:9: Error return value of `fs1.Set` is not checked (errcheck)
        	fs1.Set("log_file_max_size", "1")
        	       ^
        klog_test.go:885:9: Error return value of `fs2.Set` is not checked (errcheck)
        	fs2.Set("log_file_max_size", "2048")
        	       ^
        klog_test.go:1173:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("2")
        	                     ^
        klogr.go:35:2: field `level` is unused (unused)
        	level     int
        	^
        klog.go:1287:2: S1017: should replace this if statement with an unconditional strings.TrimSuffix (gosimple)
        	if strings.HasSuffix(file, ".go") {
        	^
        klog.go:521:2: S1001: should use copy(to, from) instead of a loop (gosimple)
        	for i := range s.vmodule.filter {
        	^
        klog_test.go:79:2: S1001: should copy arrays using assignment instead of using a loop (gosimple)
        	for i, w := range writers {
        	^
        klogr/klogr.go:118:16: Error return value of `encoder.Encode` is not checked (errcheck)
        	encoder.Encode(value)
        	              ^
        klogr/klogr_test.go:208:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("skip_headers", "true")
        	      ^
        klogr/klogr.go:119:27: S1030: should use buffer.String() instead of string(buffer.Bytes()) (gosimple)
        	return strings.TrimSpace(string(buffer.Bytes()))
        	                         ^
        ktesting/testinglogger_test.go:176:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("alsologtostderr", "false")
        	      ^
        ktesting/testinglogger_test.go:177:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("logtostderr", "false")
        	      ^
        internal/buffer/buffer.go:40:2: field `next` is unused (unused)
        	next *Buffer
        	^
        internal/clock/clock.go:122:9: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck)
        	return time.Tick(d)
        	       ^
        exit_test.go:31:16: Error return value of `flag.Set` is not checked (errcheck)
        	defer flag.Set("skip_headers", "false")
        	              ^
        format_test.go:46:5: S1003: should use strings.Contains(str, "kind is config") instead (gosimple)
        	if strings.Index(str, "kind is config") >= 0 {
        	   ^
    pohly committed Jun 1, 2023
    Configuration menu
    Copy the full SHA
    a4f9060 View commit details
    Browse the repository at this point in the history

Commits on Oct 26, 2023

  1. fix revive issues

    In golangci-lint and upstream, revive has replaced golint because golint is no
    longer maintained. revive finds some more issues that need to be fixed before
    it can be used:
    
        ktesting/testinglogger.go:81:20: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
        func (n NopTL) Log(args ...interface{}) {}
                           ^
        klogr/klogr_test.go:23:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := func() logr.Logger {
        		switch format {
        		case formatNew:
        			return New()
        		case formatDefault:
        			return NewWithOptions()
        		default:
        			return NewWithOptions(WithFormat(Format(format)))
        		}
        	}
        internal/clock/testing/fake_clock.go:261:29: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) After(d time.Duration) <-chan time.Time {
                                    ^
        internal/clock/testing/fake_clock.go:267:32: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) NewTimer(d time.Duration) clock.Timer {
                                       ^
        internal/clock/testing/fake_clock.go:273:33: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) AfterFunc(d time.Duration, f func()) clock.Timer {
                                        ^
        textlogger/textlogger.go:148:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := *l
        	^
        textlogger/textlogger.go:157:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := *l
        	^
        textlogger/textlogger.go:91:24: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *tlogger) Info(level int, msg string, kvList ...interface{}) {
                               ^
        klog_test.go:2204:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
        	copy := settings.deepCopy()
        	^
        klog_test.go:95:48: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
        func contains(s severity.Severity, str string, t *testing.T) bool {
                                                       ^
        klog_test.go:378:28: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
        func TestSetOutputDataRace(t *testing.T) {
                                   ^
        klog_test.go:1807:25: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Info(level int, msg string, keysAndValues ...interface{}) {
                                ^
        klog_test.go:1828:25: unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Init(info logr.RuntimeInfo)             {}
                                ^
        klog_test.go:1829:28: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Enabled(level int) bool                 { return true }
                                   ^
        klog_test.go:1833:34: unused-parameter: parameter 'depth' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) WithCallDepth(depth int) logr.LogSink   { return l }
                                         ^
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    ef25537 View commit details
    Browse the repository at this point in the history
  2. github: run golangci-lint via action

    The main advantage is that issues get posted as annotations, which makes them
    easier to find when looking at a diff for a PR.
    
    While at it, golangci-lint gets invoked so that it runs in its default
    configuration plus the linters that were enabled explicitly before (misspell,
    gofmt, revive as replacement for golint).
    
    It also gets applied to the examples package.
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    1a0dfc5 View commit details
    Browse the repository at this point in the history