Skip to content

Commit 22ea56b

Browse files
committed
Enable exhaustruct linter
1 parent f8ebbcd commit 22ea56b

Some content is hidden

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

54 files changed

+213
-186
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func detectCI(cfg *config.CI) *config.CI {
289289

290290
if cfg == nil {
291291
isNil = true
292-
cfg = &config.CI{}
292+
cfg = &config.CI{} // nolint:exhaustruct
293293
}
294294

295295
if bb := os.Getenv("GITHUB_BASE_REF"); bb != "" {
@@ -309,7 +309,7 @@ func detectRepository(cfg *config.Repository) *config.Repository {
309309

310310
if cfg == nil {
311311
isNil = true
312-
cfg = &config.Repository{}
312+
cfg = &config.Repository{} // nolint:exhaustruct
313313
}
314314

315315
if os.Getenv("GITHUB_ACTION") != "" {
@@ -342,7 +342,7 @@ func detectGithubActions(gh *config.GitHub) *config.GitHub {
342342

343343
if gh == nil {
344344
isNil = true
345-
gh = &config.GitHub{Timeout: time.Minute.String()}
345+
gh = &config.GitHub{Timeout: time.Minute.String()} // nolint:exhaustruct
346346
}
347347

348348
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/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/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

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
6969
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7070
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
7171
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
72-
github.com/google/go-github/v63 v63.0.0 h1:13xwK/wk9alSokujB9lJkuzdmQuVn2QCPeck76wR3nE=
73-
github.com/google/go-github/v63 v63.0.0/go.mod h1:IqbcrgUmIcEaioWrGYei/09o+ge5vhffGOcxrO0AfmA=
72+
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
73+
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
7474
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
7575
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
7676
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

internal/checks/alerts_absent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func (c AlertsAbsentCheck) Meta() CheckMeta {
3737
discovery.Modified,
3838
discovery.Moved,
3939
},
40-
IsOnline: true,
40+
Online: true,
41+
AlwaysEnabled: false,
4142
}
4243
}
4344

0 commit comments

Comments
 (0)