Skip to content

Commit a411832

Browse files
enable linter on repository
1 parent dea6d70 commit a411832

File tree

8 files changed

+67
-2
lines changed

8 files changed

+67
-2
lines changed

.github/workflows/lint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
jobs:
5+
golangci:
6+
name: lint
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Set up Go
11+
uses: actions/setup-go@v3
12+
with:
13+
go-version: 1.24
14+
- name: golangci-lint
15+
run: make lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/bin/
2+
.bin
23
/test/bin/
34
/*.tar.gz*
45
ci.env

.golangci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: "2"
2+
run:
3+
tests: true
4+
# build-tags:
5+
# - journald
6+
linters:
7+
default: none
8+
enable:
9+
- ineffassign
10+
exclusions:
11+
generated: lax
12+
paths:
13+
- vendor
14+
- third_party
15+
- third_party$
16+
- builtin$
17+
- examples$
18+
issues:
19+
max-issues-per-linter: 0
20+
max-same-issues: 0
21+
formatters:
22+
exclusions:
23+
generated: lax
24+
paths:
25+
- third_party$
26+
- builtin$
27+
- examples$

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: gitleaks
66
- repo: https://github.com/golangci/golangci-lint
7-
rev: v1.52.2
7+
rev: v2.3.1
88
hooks:
99
- id: golangci-lint
1010
- repo: https://github.com/jumanjihouse/pre-commit-hooks

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Build the node-problem-detector image.
1616

1717
.PHONY: all \
18-
vet fmt version test e2e-test \
18+
lint vet fmt version test e2e-test \
1919
build-binaries build-container build-tar build \
2020
docker-builder build-in-docker \
2121
push-container push-tar push release clean depup \
@@ -113,6 +113,18 @@ else
113113
LOGCOUNTER=*dont-include-log-counter
114114
endif
115115

116+
GOLANGCI_LINT_VERSION := v2.2.0
117+
GOLANGCI_LINT := ./.bin/golangci-lint
118+
119+
lint: $(GOLANGCI_LINT)
120+
$(GOLANGCI_LINT) run --config .golangci.yml ./...
121+
122+
$(GOLANGCI_LINT):
123+
@echo "golangci-lint not found, downloading..."
124+
@mkdir -p ./.bin
125+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./.bin $(GOLANGCI_LINT_VERSION)
126+
127+
116128
vet:
117129
go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \
118130
grep -v "./vendor/*" | \

pkg/logcounter/types/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package types contains the types for log counter.
1718
package types
1819

20+
// LogCounter is the interface for a log counter.
1921
type LogCounter interface {
2022
Count() (int, error)
2123
}

pkg/systemstatsmonitor/cpu_collector_unix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (cc *cpuCollector) recordSystemStats() {
6262
}
6363

6464
fs, err := procfs.NewFS(cc.procPath)
65+
if err != nil {
66+
klog.Errorf("Failed to open procfs: %v", err)
67+
return
68+
}
6569
stats, err := fs.Stat()
6670
if err != nil {
6771
klog.Errorf("Failed to retrieve cpu/process stats: %v", err)

pkg/systemstatsmonitor/net_collector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, descriptio
219219

220220
func (nc *netCollector) recordNetDev() {
221221
fs, err := procfs.NewFS(nc.procPath)
222+
if err != nil {
223+
klog.Errorf("Failed to open procfs: %v", err)
224+
return
225+
}
222226
stats, err := fs.NetDev()
223227
if err != nil {
224228
klog.Errorf("Failed to retrieve net dev stat: %v", err)

0 commit comments

Comments
 (0)