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

Reproduce linting checks from the main repo #121

Merged
merged 16 commits into from
Jan 31, 2025
29 changes: 22 additions & 7 deletions .github/workflows/ci-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,47 @@ name: Lint Checks
on:
push:
branches: [main]

pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
cancel-in-progress: true

# See https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
permissions: # added using https://github.com/step-security/secure-workflows
permissions:
contents: read

jobs:
generated-files-check:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7
with:
egress-policy: audit

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
with:
submodules: recursive

- name: Verify Protobuf types are up to date
run: make proto && { if git status --porcelain | grep '??'; then exit 1; else git diff --name-status --exit-code; fi }

- name: Verify Thrift types are up to date
run: make thrift && { if git status --porcelain | grep '??'; then exit 1; else git diff --name-status --exit-code; fi }

lint:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Run lint checks
run: |
make lint





5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.idea/
gen-*/
.fmt.log
.import.log
.proto-gen-polyglot/
.scripts/
.tools/
coverage.txt

118 changes: 118 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters: [gosec, bodyclose, noctx]
- linters: [gocritic]
text: "dupArg"
- linters: [gocritic]
text: "exitAfterDefer"
- linters: [gocritic]
text: "appendAssign"

exclude-dirs-use-default: false
exclude-files:
- ".*.pb.go$"
- "proto-gen/.*"
- "model/v1/prototest/.*"

max-issues-per-linter: 0
max-same-issues: 0

linters:
disable:
- errcheck
enable:
# Plain ASCII identifiers.
- asciicheck

# Checks for dangerous unicode character sequences.
- bidichk

# Checks whether HTTP response body is closed successfully.
# TODO enable this but maybe find a way to disable in tests.
- bodyclose

# Check whether the function uses a non-inherited context.
- contextcheck

# Check declaration order of types, consts, vars and funcs.
- decorder

# Checks if package imports are in a list of acceptable packages (see cfg below).
- depguard

# Check for two durations multiplied together.
- durationcheck

# Checks `Err-` prefix for var and `-Error` suffix for error type.
- errname

# Suggests to use `%w` for error-wrapping.
- errorlint

# Checks for pointers to enclosing loop variables.
- copyloopvar

- gocritic
- gofmt
- gofumpt
- goimports

# Allow or ban replace directives in go.mod
# or force explanation for retract directives.
# Maybe enable once we get rid of old sarama.
# - gomoddirectives

- gosec

# Linter that specializes in simplifying code.
- gosimple
- govet

# Detects when assignments to existing variables are not used.
- ineffassign

- misspell

# Finds naked/bare returns and requires change them.
- nakedret

# Require a bit more explicit returns.
- nilerr

# Finds sending HTTP request without context.Context.
- noctx

# Reports ill-formed or insufficient nolint directives.
- nolintlint

# Checks that fmt.Sprintf can be replaced with a faster alternative.
- perfsprint

# Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- revive

# Checks usage of github.com/stretchr/testify.
- testifylint

# Detects the possibility to use variables/constants from the Go standard library.
- usestdlibvars

# TODO consider adding more linters, cf. https://olegk.dev/go-linters-configuration-the-right-version

linters-settings:
depguard:
rules:
main:
files: ["$all"]
allow:
- "$gostd"
- "github.com/stretchr/testify"
- "github.com/gogo/protobuf"
- "github.com/jaegertracing/jaeger-idl"

run:
go: "1.22"
timeout: 20m
75 changes: 75 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ THRIFT_FILES=agent.thrift jaeger.thrift sampling.thrift zipkincore.thrift crossd
baggage.thrift dependency.thrift aggregation_validator.thrift
THRIFT_GEN_DIR=thrift-gen

# All .go files that are not auto-generated and should be auto-formatted and linted.
ALL_SRC = $(shell find . -name '*.go' \
-not -name '_*' \
-not -name '.*' \
-not -name '*.pb.go' \
-not -path './thrift-gen/*'\
-type f | \
sort)


FMT_LOG=.fmt.log
IMPORT_LOG=.import.log

# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(shell git rev-parse --show-toplevel)
TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
LINT := $(TOOLS_BIN_DIR)/golangci-lint

$(TOOLS_BIN_DIR):
mkdir -p $@

$(LINT): $(TOOLS_BIN_DIR)
cd $(TOOLS_MOD_DIR) && go build -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint

.PHONY: test-code-gen
test-code-gen: thrift-all swagger-validate protocompile proto-all proto-zipkin
git diff --exit-code ./swagger/api_v3/query_service.swagger.json
Expand Down Expand Up @@ -171,6 +196,56 @@ define proto_compile

endef

.PHONY: lint
lint: lint-imports lint-nocommit lint-license lint-go

.PHONY: lint-go
lint-go: $(LINT)
$(LINT) -v run

.PHONY: lint-license
lint-license: setup-lint-scripts
@echo Verifying that all files have license headers
@mkdir -p .scripts/lint
@curl -s -o .scripts/lint/updateLicense.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/updateLicense.py
@chmod +x .scripts/lint/updateLicense.py
@./.scripts/lint/updateLicense.py $(ALL_SRC) $(SCRIPTS_SRC) > $(FMT_LOG)
@[ -s "$(FMT_LOG)" ] || echo "✅ All files have license headers"


.PHONY: lint-nocommit
lint-nocommit:
@if git diff origin/main | grep '@no''commit' ; then \
echo "❌ Cannot merge PR that contains @no""commit string" ; \
false ; \
fi

.PHONY: lint-imports
lint-imports: setup-lint-scripts
@echo Verifying that all files have correctly ordered imports
@./.scripts/lint/import-order-cleanup.py -o stdout -t $(ALL_SRC) > $(IMPORT_LOG)
@[ ! -s "$(IMPORT_LOG)" ] || (echo "Import ordering failures, run 'make fmt'" | cat - $(IMPORT_LOG) && false)
@[ -s "$(IMPORT_LOG)" ] || echo "✅ All files have correctly ordered imports"

.PHONY: setup-lint-scripts
setup-lint-scripts:
@mkdir -p .scripts/lint
@curl -s -o .scripts/lint/import-order-cleanup.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/import-order-cleanup.py
@chmod +x .scripts/lint/import-order-cleanup.py
@curl -s -o .scripts/lint/updateLicense.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/updateLicense.py
@chmod +x .scripts/lint/updateLicense.py

.PHONY: fmt
fmt: setup-lint-scripts $(GOFUMPT)
@echo Running import-order-cleanup on ALL_SRC ...
@./.scripts/lint/import-order-cleanup.py -o inplace -t $(ALL_SRC)
@echo Running gofmt on ALL_SRC ...
@$(GOFMT) -e -s -l -w $(ALL_SRC)
@echo Running gofumpt on ALL_SRC ...
@$(GOFUMPT) -e -l -w $(ALL_SRC)
@echo Running updateLicense.py on ALL_SRC ...
@./.scripts/lint/updateLicense.py $(ALL_SRC) $(SCRIPTS_SRC)

.PHONY: test-ci
test-ci:
go test -v -coverprofile=coverage.txt ./...
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ require (
require (
github.com/apache/thrift v0.21.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
Expand Down
29 changes: 11 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,28 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
go.opentelemetry.io/otel/sdk/metric v1.33.0 h1:Gs5VK9/WUJhNXZgn8MR6ITatvAmKeIuCtNbsP3JkNqU=
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
Loading