Skip to content

Commit 9ad7b85

Browse files
committed
chore: re-enable golangci-lint checks and fix violations
Re-enable staticcheck linters that were disabled in a previous commit and fix all resulting violations: - Remove deprecated // +build lines (23 files) - only //go:build needed - Fix ST1005: lowercase error strings (24 issues across multiple files) - Fix ST1016: consistent receiver names in collector/util.go - Fix ST1023: remove redundant type in variable declaration Keep disabled: ST1003 (naming would break public API), ST1020/ST1021/ST1022 (comment format - too many issues, not worth the churn). Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 0cbb7e7 commit 9ad7b85

37 files changed

+37
-58
lines changed

.golangci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ linters:
1414
settings:
1515
govet:
1616
disable:
17-
- fieldalignment
18-
- buildtag # old +build lines still present alongside //go:build
17+
- fieldalignment # too noisy, requires significant refactoring
1918
errcheck:
2019
exclude-functions:
2120
- (io.Closer).Close
@@ -32,8 +31,12 @@ linters:
3231
staticcheck:
3332
checks:
3433
- "all"
35-
- "-ST*" # disable all style checks (ST1000, ST1003, ST1005, etc.)
36-
- "-QF*" # disable all quickfix suggestions
34+
- "-ST1000" # package comments - too noisy for existing codebase
35+
- "-ST1003" # naming conventions (e.g., CrioId vs CrioID) - would break public API
36+
- "-ST1020" # comment format on exported methods - too many to fix
37+
- "-ST1021" # comment format on exported types - too many to fix
38+
- "-ST1022" # comment format on exported consts - too many to fix
39+
- "-QF*" # disable quickfix suggestions
3740
exclusions:
3841
rules:
3942
# Exclude errcheck in test files for cleaner test code
@@ -52,6 +55,7 @@ linters:
5255
formatters:
5356
enable:
5457
- gofmt
58+
- goimports
5559

5660
issues:
5761
max-issues-per-linter: 0

client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ func (c *Client) getEventStreamingData(url string, einfo chan *v1.Event) error {
211211
return err
212212
}
213213
if resp.StatusCode != http.StatusOK {
214-
return fmt.Errorf("Status code is not OK: %v (%s)", resp.StatusCode, resp.Status)
214+
return fmt.Errorf("status code is not OK: %v (%s)", resp.StatusCode, resp.Status)
215215
}
216216

217217
dec := json.NewDecoder(resp.Body)
218-
var m *v1.Event = &v1.Event{}
218+
m := &v1.Event{}
219219
for {
220220
err := dec.Decode(m)
221221
if err != nil {

cmd/internal/storage/influxdb/influxdb_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
//go:build influxdb_test
16-
// +build influxdb_test
1716

1817
// To run unit test: go test -tags influxdb_test
1918

collector/generic_collector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
6767
// TODO : Add checks for validity of config file (eg : Accurate JSON fields)
6868

6969
if len(configInJSON.MetricsConfig) == 0 {
70-
return nil, fmt.Errorf("No metrics provided in config")
70+
return nil, fmt.Errorf("no metrics provided in config")
7171
}
7272

7373
minPollFrequency := time.Duration(0)
@@ -83,7 +83,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
8383

8484
regexprs[ind], err = regexp.Compile(metricConfig.Regex)
8585
if err != nil {
86-
return nil, fmt.Errorf("Invalid regexp %v for metric %v", metricConfig.Regex, metricConfig.Name)
86+
return nil, fmt.Errorf("invalid regexp %v for metric %v", metricConfig.Regex, metricConfig.Name)
8787
}
8888
}
8989

@@ -94,7 +94,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
9494
}
9595

9696
if len(configInJSON.MetricsConfig) > metricCountLimit {
97-
return nil, fmt.Errorf("Too many metrics defined: %d limit: %d", len(configInJSON.MetricsConfig), metricCountLimit)
97+
return nil, fmt.Errorf("too many metrics defined: %d limit: %d", len(configInJSON.MetricsConfig), metricCountLimit)
9898
}
9999

100100
return &GenericCollector{
@@ -173,10 +173,10 @@ func (collector *GenericCollector) Collect(metrics map[string][]v1.MetricVal) (t
173173
}
174174

175175
} else {
176-
errorSlice = append(errorSlice, fmt.Errorf("Unexpected value of 'data_type' for metric '%v' in config ", metricConfig.Name))
176+
errorSlice = append(errorSlice, fmt.Errorf("unexpected value of 'data_type' for metric '%v' in config ", metricConfig.Name))
177177
}
178178
} else {
179-
errorSlice = append(errorSlice, fmt.Errorf("No match found for regexp: %v for metric '%v' in config", metricConfig.Regex, metricConfig.Name))
179+
errorSlice = append(errorSlice, fmt.Errorf("no match found for regexp: %v for metric '%v' in config", metricConfig.Regex, metricConfig.Name))
180180
}
181181
}
182182
return nextCollectionTime, metrics, compileErrors(errorSlice)

collector/prometheus_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
7272
}
7373

7474
if metricCountLimit < 0 {
75-
return nil, fmt.Errorf("Metric count limit must be greater than or equal to 0")
75+
return nil, fmt.Errorf("metric count limit must be greater than or equal to 0")
7676
}
7777

7878
var metricsSet map[string]bool
@@ -84,7 +84,7 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
8484
}
8585

8686
if len(configInJSON.MetricsConfig) > metricCountLimit {
87-
return nil, fmt.Errorf("Too many metrics defined: %d limit %d", len(configInJSON.MetricsConfig), metricCountLimit)
87+
return nil, fmt.Errorf("too many metrics defined: %d limit %d", len(configInJSON.MetricsConfig), metricCountLimit)
8888
}
8989

9090
// TODO : Add checks for validity of config file (eg : Accurate JSON fields)

collector/util.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ package collector
1616

1717
import "github.com/google/cadvisor/container"
1818

19-
func (endpointConfig *EndpointConfig) configure(containerHandler container.ContainerHandler) {
20-
//If the exact URL was not specified, generate it based on the ip address of the container.
21-
endpoint := endpointConfig
22-
if endpoint.URL == "" {
19+
func (ec *EndpointConfig) configure(containerHandler container.ContainerHandler) {
20+
// If the exact URL was not specified, generate it based on the ip address of the container.
21+
if ec.URL == "" {
2322
ipAddress := containerHandler.GetContainerIPAddress()
24-
endpointConfig.URL = endpoint.URLConfig.Protocol + "://" + ipAddress + ":" + endpoint.URLConfig.Port.String() + endpoint.URLConfig.Path
23+
ec.URL = ec.URLConfig.Protocol + "://" + ipAddress + ":" + ec.URLConfig.Port.String() + ec.URLConfig.Path
2524
}
2625
}

container/containerd/pkg/dialer/dialer_unix.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
//go:build !windows
15-
// +build !windows
1615

1716
/*
1817
Copyright The containerd Authors.

container/crio/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type crioClientImpl struct {
7272

7373
func configureUnixTransport(tr *http.Transport, proto, addr string) error {
7474
if len(addr) > maxUnixSocketPathSize {
75-
return fmt.Errorf("Unix socket path %q is too long", addr)
75+
return fmt.Errorf("unix socket path %q is too long", addr)
7676
}
7777
// No need for compression in local communications.
7878
tr.DisableCompression = true
@@ -149,9 +149,9 @@ func (c *crioClientImpl) ContainerInfo(id string) (*ContainerInfo, error) {
149149
if resp.StatusCode != http.StatusOK {
150150
respBody, err := io.ReadAll(resp.Body)
151151
if err != nil {
152-
return nil, fmt.Errorf("Error finding container %s: Status %d", id, resp.StatusCode)
152+
return nil, fmt.Errorf("error finding container %s: status %d", id, resp.StatusCode)
153153
}
154-
return nil, fmt.Errorf("Error finding container %s: Status %d returned error %s", id, resp.StatusCode, string(respBody))
154+
return nil, fmt.Errorf("error finding container %s: status %d returned error %s", id, resp.StatusCode, string(respBody))
155155
}
156156

157157
if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil {

container/docker/utils/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func DriverStatusValue(status [][2]string, target string) string {
4949
func DockerThinPoolName(info dockersystem.Info) (string, error) {
5050
poolName := DriverStatusValue(info.DriverStatus, DriverStatusPoolName)
5151
if len(poolName) == 0 {
52-
return "", fmt.Errorf("Could not get devicemapper pool name")
52+
return "", fmt.Errorf("could not get devicemapper pool name")
5353
}
5454

5555
return poolName, nil
@@ -78,7 +78,7 @@ func DockerMetadataDevice(info dockersystem.Info) (string, error) {
7878
func DockerZfsFilesystem(info dockersystem.Info) (string, error) {
7979
filesystem := DriverStatusValue(info.DriverStatus, DriverStatusParentDataset)
8080
if len(filesystem) == 0 {
81-
return "", fmt.Errorf("Could not get zfs filesystem")
81+
return "", fmt.Errorf("could not get zfs filesystem")
8282
}
8383

8484
return filesystem, nil

container/libcontainer/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func processStatsFromProcs(rootFs string, cgroupPath string, rootPid int) (info.
311311
func (h *Handler) schedulerStatsFromProcs() (info.CpuSchedstat, error) {
312312
pids, err := h.cgroupManager.GetAllPids()
313313
if err != nil {
314-
return info.CpuSchedstat{}, fmt.Errorf("Could not get PIDs for container %d: %w", h.pid, err)
314+
return info.CpuSchedstat{}, fmt.Errorf("could not get PIDs for container %d: %w", h.pid, err)
315315
}
316316
alivePids := make(map[int]struct{}, len(pids))
317317
for _, pid := range pids {

0 commit comments

Comments
 (0)