enable linter on repository

This commit is contained in:
Sergey Kanzhelev
2025-08-08 17:29:46 +00:00
parent dea6d70d46
commit a4118329f6
8 changed files with 67 additions and 2 deletions

15
.github/workflows/lint.yml vendored Normal file
View File

@@ -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
.gitignore vendored
View File

@@ -1,4 +1,5 @@
/bin/ /bin/
.bin
/test/bin/ /test/bin/
/*.tar.gz* /*.tar.gz*
ci.env ci.env

27
.golangci.yml Normal file
View File

@@ -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$

View File

@@ -4,7 +4,7 @@ repos:
hooks: hooks:
- id: gitleaks - id: gitleaks
- repo: https://github.com/golangci/golangci-lint - repo: https://github.com/golangci/golangci-lint
rev: v1.52.2 rev: v2.3.1
hooks: hooks:
- id: golangci-lint - id: golangci-lint
- repo: https://github.com/jumanjihouse/pre-commit-hooks - repo: https://github.com/jumanjihouse/pre-commit-hooks

View File

@@ -15,7 +15,7 @@
# Build the node-problem-detector image. # Build the node-problem-detector image.
.PHONY: all \ .PHONY: all \
vet fmt version test e2e-test \ lint vet fmt version test e2e-test \
build-binaries build-container build-tar build \ build-binaries build-container build-tar build \
docker-builder build-in-docker \ docker-builder build-in-docker \
push-container push-tar push release clean depup \ push-container push-tar push release clean depup \
@@ -113,6 +113,18 @@ else
LOGCOUNTER=*dont-include-log-counter LOGCOUNTER=*dont-include-log-counter
endif 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: vet:
go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \ go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \
grep -v "./vendor/*" | \ grep -v "./vendor/*" | \

View File

@@ -14,8 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package types contains the types for log counter.
package types package types
// LogCounter is the interface for a log counter.
type LogCounter interface { type LogCounter interface {
Count() (int, error) Count() (int, error)
} }

View File

@@ -62,6 +62,10 @@ func (cc *cpuCollector) recordSystemStats() {
} }
fs, err := procfs.NewFS(cc.procPath) fs, err := procfs.NewFS(cc.procPath)
if err != nil {
klog.Errorf("Failed to open procfs: %v", err)
return
}
stats, err := fs.Stat() stats, err := fs.Stat()
if err != nil { if err != nil {
klog.Errorf("Failed to retrieve cpu/process stats: %v", err) klog.Errorf("Failed to retrieve cpu/process stats: %v", err)

View File

@@ -219,6 +219,10 @@ func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, descriptio
func (nc *netCollector) recordNetDev() { func (nc *netCollector) recordNetDev() {
fs, err := procfs.NewFS(nc.procPath) fs, err := procfs.NewFS(nc.procPath)
if err != nil {
klog.Errorf("Failed to open procfs: %v", err)
return
}
stats, err := fs.NetDev() stats, err := fs.NetDev()
if err != nil { if err != nil {
klog.Errorf("Failed to retrieve net dev stat: %v", err) klog.Errorf("Failed to retrieve net dev stat: %v", err)