Skip to content

Commit 85dae6f

Browse files
authored
Reproduce linting checks from the main repo (#121)
## Which problem is this PR solving? - jaegertracing/jaeger#6570 ## Description of the changes - Reproduce linting checks from the main repo to jaeger-idl repo ## How was this change tested? - ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: danish9039 <[email protected]> Signed-off-by: hippie-danish <[email protected]>
1 parent 5fa35ae commit 85dae6f

15 files changed

+1451
-52
lines changed

.github/workflows/ci-lint-test.yml

+22-7
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,47 @@ name: Lint Checks
66
on:
77
push:
88
branches: [main]
9-
109
pull_request:
1110
branches: [main]
1211

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

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

2119
jobs:
2220
generated-files-check:
2321
runs-on: ubuntu-latest
2422
steps:
25-
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
23+
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7
2624
with:
2725
egress-policy: audit
28-
29-
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
26+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
3027
with:
3128
submodules: recursive
32-
3329
- name: Verify Protobuf types are up to date
3430
run: make proto && { if git status --porcelain | grep '??'; then exit 1; else git diff --name-status --exit-code; fi }
3531

3632
- name: Verify Thrift types are up to date
3733
run: make thrift && { if git status --porcelain | grep '??'; then exit 1; else git diff --name-status --exit-code; fi }
34+
35+
lint:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
39+
with:
40+
egress-policy: audit
41+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.x'
45+
- name: Run lint checks
46+
run: |
47+
make lint
48+
49+
50+
51+
52+

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
.idea/
22
gen-*/
3+
.fmt.log
4+
.import.log
35
.proto-gen-polyglot/
6+
.scripts/
7+
.tools/
48
coverage.txt
9+

.golangci.yaml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
issues:
2+
# Excluding configuration per-path, per-linter, per-text and per-source
3+
exclude-rules:
4+
# Exclude some linters from running on tests files.
5+
- path: _test\.go
6+
linters: [gosec, bodyclose, noctx]
7+
- linters: [gocritic]
8+
text: "dupArg"
9+
- linters: [gocritic]
10+
text: "exitAfterDefer"
11+
- linters: [gocritic]
12+
text: "appendAssign"
13+
14+
exclude-dirs-use-default: false
15+
exclude-files:
16+
- ".*.pb.go$"
17+
- "proto-gen/.*"
18+
- "model/v1/prototest/.*"
19+
20+
max-issues-per-linter: 0
21+
max-same-issues: 0
22+
23+
linters:
24+
disable:
25+
- errcheck
26+
enable:
27+
# Plain ASCII identifiers.
28+
- asciicheck
29+
30+
# Checks for dangerous unicode character sequences.
31+
- bidichk
32+
33+
# Checks whether HTTP response body is closed successfully.
34+
# TODO enable this but maybe find a way to disable in tests.
35+
- bodyclose
36+
37+
# Check whether the function uses a non-inherited context.
38+
- contextcheck
39+
40+
# Check declaration order of types, consts, vars and funcs.
41+
- decorder
42+
43+
# Checks if package imports are in a list of acceptable packages (see cfg below).
44+
- depguard
45+
46+
# Check for two durations multiplied together.
47+
- durationcheck
48+
49+
# Checks `Err-` prefix for var and `-Error` suffix for error type.
50+
- errname
51+
52+
# Suggests to use `%w` for error-wrapping.
53+
- errorlint
54+
55+
# Checks for pointers to enclosing loop variables.
56+
- copyloopvar
57+
58+
- gocritic
59+
- gofmt
60+
- gofumpt
61+
- goimports
62+
63+
# Allow or ban replace directives in go.mod
64+
# or force explanation for retract directives.
65+
# Maybe enable once we get rid of old sarama.
66+
# - gomoddirectives
67+
68+
- gosec
69+
70+
# Linter that specializes in simplifying code.
71+
- gosimple
72+
- govet
73+
74+
# Detects when assignments to existing variables are not used.
75+
- ineffassign
76+
77+
- misspell
78+
79+
# Finds naked/bare returns and requires change them.
80+
- nakedret
81+
82+
# Require a bit more explicit returns.
83+
- nilerr
84+
85+
# Finds sending HTTP request without context.Context.
86+
- noctx
87+
88+
# Reports ill-formed or insufficient nolint directives.
89+
- nolintlint
90+
91+
# Checks that fmt.Sprintf can be replaced with a faster alternative.
92+
- perfsprint
93+
94+
# Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
95+
- revive
96+
97+
# Checks usage of github.com/stretchr/testify.
98+
- testifylint
99+
100+
# Detects the possibility to use variables/constants from the Go standard library.
101+
- usestdlibvars
102+
103+
# TODO consider adding more linters, cf. https://olegk.dev/go-linters-configuration-the-right-version
104+
105+
linters-settings:
106+
depguard:
107+
rules:
108+
main:
109+
files: ["$all"]
110+
allow:
111+
- "$gostd"
112+
- "github.com/stretchr/testify"
113+
- "github.com/gogo/protobuf"
114+
- "github.com/jaegertracing/jaeger-idl"
115+
116+
run:
117+
go: "1.22"
118+
timeout: 20m

Makefile

+75
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ THRIFT_FILES=agent.thrift jaeger.thrift sampling.thrift zipkincore.thrift crossd
3131
baggage.thrift dependency.thrift aggregation_validator.thrift
3232
THRIFT_GEN_DIR=thrift-gen
3333

34+
# All .go files that are not auto-generated and should be auto-formatted and linted.
35+
ALL_SRC = $(shell find . -name '*.go' \
36+
-not -name '_*' \
37+
-not -name '.*' \
38+
-not -name '*.pb.go' \
39+
-not -path './thrift-gen/*'\
40+
-type f | \
41+
sort)
42+
43+
44+
FMT_LOG=.fmt.log
45+
IMPORT_LOG=.import.log
46+
47+
# SRC_ROOT is the top of the source tree.
48+
SRC_ROOT := $(shell git rev-parse --show-toplevel)
49+
TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
50+
TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
51+
LINT := $(TOOLS_BIN_DIR)/golangci-lint
52+
53+
$(TOOLS_BIN_DIR):
54+
mkdir -p $@
55+
56+
$(LINT): $(TOOLS_BIN_DIR)
57+
cd $(TOOLS_MOD_DIR) && go build -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint
58+
3459
.PHONY: test-code-gen
3560
test-code-gen: thrift-all swagger-validate protocompile proto-all proto-zipkin
3661
git diff --exit-code ./swagger/api_v3/query_service.swagger.json
@@ -171,6 +196,56 @@ define proto_compile
171196

172197
endef
173198

199+
.PHONY: lint
200+
lint: lint-imports lint-nocommit lint-license lint-go
201+
202+
.PHONY: lint-go
203+
lint-go: $(LINT)
204+
$(LINT) -v run
205+
206+
.PHONY: lint-license
207+
lint-license: setup-lint-scripts
208+
@echo Verifying that all files have license headers
209+
@mkdir -p .scripts/lint
210+
@curl -s -o .scripts/lint/updateLicense.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/updateLicense.py
211+
@chmod +x .scripts/lint/updateLicense.py
212+
@./.scripts/lint/updateLicense.py $(ALL_SRC) $(SCRIPTS_SRC) > $(FMT_LOG)
213+
@[ -s "$(FMT_LOG)" ] || echo "✅ All files have license headers"
214+
215+
216+
.PHONY: lint-nocommit
217+
lint-nocommit:
218+
@if git diff origin/main | grep '@no''commit' ; then \
219+
echo "❌ Cannot merge PR that contains @no""commit string" ; \
220+
false ; \
221+
fi
222+
223+
.PHONY: lint-imports
224+
lint-imports: setup-lint-scripts
225+
@echo Verifying that all files have correctly ordered imports
226+
@./.scripts/lint/import-order-cleanup.py -o stdout -t $(ALL_SRC) > $(IMPORT_LOG)
227+
@[ ! -s "$(IMPORT_LOG)" ] || (echo "Import ordering failures, run 'make fmt'" | cat - $(IMPORT_LOG) && false)
228+
@[ -s "$(IMPORT_LOG)" ] || echo "✅ All files have correctly ordered imports"
229+
230+
.PHONY: setup-lint-scripts
231+
setup-lint-scripts:
232+
@mkdir -p .scripts/lint
233+
@curl -s -o .scripts/lint/import-order-cleanup.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/import-order-cleanup.py
234+
@chmod +x .scripts/lint/import-order-cleanup.py
235+
@curl -s -o .scripts/lint/updateLicense.py https://raw.githubusercontent.com/jaegertracing/jaeger/main/scripts/lint/updateLicense.py
236+
@chmod +x .scripts/lint/updateLicense.py
237+
238+
.PHONY: fmt
239+
fmt: setup-lint-scripts $(GOFUMPT)
240+
@echo Running import-order-cleanup on ALL_SRC ...
241+
@./.scripts/lint/import-order-cleanup.py -o inplace -t $(ALL_SRC)
242+
@echo Running gofmt on ALL_SRC ...
243+
@$(GOFMT) -e -s -l -w $(ALL_SRC)
244+
@echo Running gofumpt on ALL_SRC ...
245+
@$(GOFUMPT) -e -l -w $(ALL_SRC)
246+
@echo Running updateLicense.py on ALL_SRC ...
247+
@./.scripts/lint/updateLicense.py $(ALL_SRC) $(SCRIPTS_SRC)
248+
174249
.PHONY: test-ci
175250
test-ci:
176251
go test -v -coverprofile=coverage.txt ./...

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ require (
1616
require (
1717
github.com/apache/thrift v0.21.0 // indirect
1818
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
19-
github.com/kr/pretty v0.3.1 // indirect
19+
github.com/kr/text v0.2.0 // indirect
2020
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
21-
github.com/rogpeppe/go-internal v1.13.1 // indirect
22-
go.opentelemetry.io/otel v1.33.0 // indirect
23-
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
2421
golang.org/x/net v0.34.0 // indirect
2522
golang.org/x/sys v0.29.0 // indirect
2623
golang.org/x/text v0.21.0 // indirect

go.sum

+11-18
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,28 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1919
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2020
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
2121
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
22+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
2223
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
23-
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
24-
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2524
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2625
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2726
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2827
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
29-
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
3028
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
3129
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
32-
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
33-
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
34-
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
3530
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3631
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3732
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3833
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
39-
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
40-
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
41-
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
42-
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
43-
go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
44-
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
45-
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
46-
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
47-
go.opentelemetry.io/otel/sdk/metric v1.33.0 h1:Gs5VK9/WUJhNXZgn8MR6ITatvAmKeIuCtNbsP3JkNqU=
48-
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
49-
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
50-
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
34+
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
35+
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
36+
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
37+
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
38+
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
39+
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
40+
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
41+
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
42+
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
43+
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
5144
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
5245
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
5346
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

0 commit comments

Comments
 (0)