Skip to content

Commit 45da6ef

Browse files
authored
Merge pull request #1242 from cloudflare/exhaustruct
Enable exhaustruct linter
2 parents f8ebbcd + efb669e commit 45da6ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+272
-209
lines changed

.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ linters:
2727
- exptostd
2828
- nilnesserr
2929
- usetesting
30+
- exhaustruct
3031

3132
issues:
3233
max-same-issues: 0
34+
exclude-rules:
35+
- path: ^.*_test\.go$
36+
linters:
37+
- exhaustruct
3338

3439
linters-settings:
3540
goimports:
@@ -40,3 +45,23 @@ linters-settings:
4045
enable-all: true
4146
nakedret:
4247
max-func-lines: 0
48+
exhaustruct:
49+
exclude:
50+
- net/http\..+
51+
- crypto/tls\..+
52+
- encoding/xml\..+
53+
- .+/checks\.badMatcher
54+
- .+/checks\.Problem
55+
- .+/checks\.exprProblem
56+
- .+/checks\..+Settings
57+
- .+/config\.Match
58+
- .+/discovery\.Entry
59+
- .+/parser\.Rule
60+
- .+/parser\.ParseError
61+
- .+/parser\.VectorSelector
62+
- .+/promapi\.MetricTimeRange
63+
- github.com/prometheus/.+\..+
64+
- github.com/urfave/cli/.+
65+
- gitlab.com/gitlab-org/api/.+
66+
- github.com/google/go-github/.+
67+
- github.com/hashicorp/hcl/.+

cmd/pint/ci.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,45 +285,20 @@ func logSeverityCounters(src map[checks.Severity]int) (attrs []any) {
285285
}
286286

287287
func detectCI(cfg *config.CI) *config.CI {
288-
var isNil, isDirty bool
289-
290-
if cfg == nil {
291-
isNil = true
292-
cfg = &config.CI{}
293-
}
294-
295288
if bb := os.Getenv("GITHUB_BASE_REF"); bb != "" {
296-
isDirty = true
297289
cfg.BaseBranch = bb
298290
slog.Debug("got base branch from GITHUB_BASE_REF env variable", slog.String("branch", bb))
299291
}
300-
301-
if isNil && !isDirty {
302-
return nil
303-
}
304292
return cfg
305293
}
306294

307295
func detectRepository(cfg *config.Repository) *config.Repository {
308-
var isNil, isDirty bool
309-
310-
if cfg == nil {
311-
isNil = true
312-
cfg = &config.Repository{}
313-
}
314-
315296
if os.Getenv("GITHUB_ACTION") != "" {
316-
isDirty = true
317297
cfg.GitHub = detectGithubActions(cfg.GitHub)
318298
}
319-
320299
if cfg != nil && cfg.GitHub != nil && cfg.GitHub.MaxComments == 0 {
321300
cfg.GitHub.MaxComments = 50
322301
}
323-
324-
if isNil && !isDirty {
325-
return nil
326-
}
327302
return cfg
328303
}
329304

@@ -342,7 +317,7 @@ func detectGithubActions(gh *config.GitHub) *config.GitHub {
342317

343318
if gh == nil {
344319
isNil = true
345-
gh = &config.GitHub{Timeout: time.Minute.String()}
320+
gh = &config.GitHub{Timeout: time.Minute.String()} // nolint:exhaustruct
346321
}
347322

348323
if repo := os.Getenv("GITHUB_REPOSITORY"); repo != "" {

cmd/pint/lint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func verifyOwners(entries []discovery.Entry, allowedOwners []*regexp.Regexp) (re
192192
Path: entry.Path,
193193
ModifiedLines: entry.ModifiedLines,
194194
Rule: entry.Rule,
195+
Owner: "",
195196
Problem: checks.Problem{
196197
Lines: entry.Rule.Lines,
197198
Reporter: discovery.RuleOwnerComment,
@@ -211,6 +212,7 @@ func verifyOwners(entries []discovery.Entry, allowedOwners []*regexp.Regexp) (re
211212
Path: entry.Path,
212213
ModifiedLines: entry.ModifiedLines,
213214
Rule: entry.Rule,
215+
Owner: "",
214216
Problem: checks.Problem{
215217
Lines: entry.Rule.Lines,
216218
Reporter: discovery.RuleOwnerComment,

cmd/pint/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.Pr
102102
checkList := cfg.GetChecksForEntry(ctx, gen, entry)
103103
for _, check := range checkList {
104104
checkIterationChecks.Inc()
105-
if check.Meta().IsOnline {
105+
if check.Meta().Online {
106106
onlineChecksCount.Inc()
107107
} else {
108108
offlineChecksCount.Inc()

cmd/pint/tests/0025_config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ level=INFO msg="Loading configuration file" path=.pint.hcl
1212
"maxCommits": 20
1313
},
1414
"parser": {},
15+
"repository": {},
1516
"checks": {
1617
"enabled": [
1718
"alerts/absent",

cmd/pint/tests/0083_github_action.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@ groups:
6161

6262
-- src/.pint.hcl --
6363
repository {}
64-

cmd/pint/tests/0113_config_env_expand.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ level=INFO msg="Loading configuration file" path=.pint.hcl
1717
".*"
1818
]
1919
},
20+
"repository": {},
2021
"checks": {
2122
"enabled": [
2223
"alerts/absent",

cmd/pint/tests/0122_lint_owner_allowed.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmp stderr stderr.txt
55
-- stderr.txt --
66
level=INFO msg="Loading configuration file" path=.pint.hcl
77
level=INFO msg="Finding all rules to check" paths=["rules"]
8-
level=INFO msg="Checking Prometheus rules" entries=5 workers=10 online=true
8+
level=INFO msg="Checking Prometheus rules" entries=6 workers=10 online=true
99
rules/1.yml:4-5 Bug: `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule. (rule/owner)
1010
4 | - alert: No Owner
1111
5 | expr: up > 0
@@ -14,14 +14,18 @@ rules/1.yml:7-8 Bug: This rule is set as owned by `bob` but `bob` doesn't match
1414
7 | - alert: Invalid
1515
8 | expr: up == 0
1616

17+
rules/1.yml:13-14 Bug: This rule is set as owned by `zed` but `zed` doesn't match any of the allowed owner values. (rule/owner)
18+
13 | - alert: Owner Zed
19+
14 | expr: up < 0
20+
1721
rules/2.yml:4-5 Bug: `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule. (rule/owner)
1822
4 | - alert: No Owner
1923
5 | expr: up > 0
2024

2125
rules/3.yml:1 Bug: This file is set as owned by `ax` but `ax` doesn't match any of the allowed owner values. (rule/owner)
2226
1 | # pint file/owner ax
2327

24-
level=INFO msg="Problems found" Bug=4
28+
level=INFO msg="Problems found" Bug=5
2529
level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher"
2630
-- rules/1.yml --
2731
groups:
@@ -35,6 +39,9 @@ groups:
3539
# pint rule/owner alice
3640
- alert: Owner Alice
3741
expr: up > 0
42+
# pint rule/owner zed
43+
- alert: Owner Zed
44+
expr: up < 0
3845

3946
-- rules/2.yml --
4047
groups:

cmd/pint/watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ type problemCollector struct {
283283
}
284284

285285
func newProblemCollector(cfg config.Config, f pathFinderFunc, minSeverity checks.Severity, maxProblems int) *problemCollector {
286-
return &problemCollector{
286+
return &problemCollector{ // nolint:exhaustruct
287287
finder: f,
288288
cfg: cfg,
289289
fileOwners: map[string]string{},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/cespare/xxhash/v2 v2.3.0
77
github.com/gkampitakis/go-snaps v0.5.8
88
github.com/google/go-cmp v0.6.0
9-
github.com/google/go-github/v63 v63.0.0
9+
github.com/google/go-github/v68 v68.0.0
1010
github.com/hashicorp/hcl/v2 v2.23.0
1111
github.com/klauspost/compress v1.17.11
1212
github.com/neilotoole/slogt v1.1.0

0 commit comments

Comments
 (0)