Skip to content

enable linter on repository #1088

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

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: golangci-lint
on:
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.24
- name: golangci-lint
run: make lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/
.bin
/test/bin/
/*.tar.gz*
ci.env
Expand Down
27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "2"
run:
tests: true
# build-tags:
# - journald
linters:
default: none
enable:
- ineffassign
exclusions:
generated: lax
paths:
- vendor
- third_party
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: gitleaks
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
rev: v2.3.1
hooks:
- id: golangci-lint
- repo: https://github.com/jumanjihouse/pre-commit-hooks
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Build the node-problem-detector image.

.PHONY: all \
vet fmt version test e2e-test \
lint vet fmt version test e2e-test \
build-binaries build-container build-tar build \
docker-builder build-in-docker \
push-container push-tar push release clean depup \
Expand Down Expand Up @@ -113,6 +113,18 @@ else
LOGCOUNTER=*dont-include-log-counter
endif

GOLANGCI_LINT_VERSION := v2.2.0
GOLANGCI_LINT := ./.bin/golangci-lint

lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --config .golangci.yml ./...

$(GOLANGCI_LINT):
@echo "golangci-lint not found, downloading..."
@mkdir -p ./.bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./.bin $(GOLANGCI_LINT_VERSION)


vet:
go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \
grep -v "./vendor/*" | \
Expand Down
2 changes: 2 additions & 0 deletions pkg/logcounter/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package types contains the types for log counter.
package types

// LogCounter is the interface for a log counter.
type LogCounter interface {
Count() (int, error)
}
4 changes: 4 additions & 0 deletions pkg/systemstatsmonitor/cpu_collector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (cc *cpuCollector) recordSystemStats() {
}

fs, err := procfs.NewFS(cc.procPath)
if err != nil {
klog.Errorf("Failed to open procfs: %v", err)
return
}
stats, err := fs.Stat()
if err != nil {
klog.Errorf("Failed to retrieve cpu/process stats: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/systemstatsmonitor/net_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, descriptio

func (nc *netCollector) recordNetDev() {
fs, err := procfs.NewFS(nc.procPath)
if err != nil {
klog.Errorf("Failed to open procfs: %v", err)
return
}
stats, err := fs.NetDev()
if err != nil {
klog.Errorf("Failed to retrieve net dev stat: %v", err)
Expand Down