Skip to content

Commit 3d3db39

Browse files
authored
Enable revive rules (#823)
* Enable revive rule early-return * Enable revive rule increment-decrement * Enable revive rule receiver-naming * Enable revive rule unexported-return * Enable revive rule unused-receiver * Enable revive rule var-declaration * Enable revive rule var-naming --------- Signed-off-by: Arve Knudsen <[email protected]>
1 parent 7937ffb commit 3d3db39

File tree

12 files changed

+55
-46
lines changed

12 files changed

+55
-46
lines changed

.golangci.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ linters:
121121
# Allow functions with test or bench signatures.
122122
- allowTypesBefore: '*testing.T,testing.TB'
123123
- name: context-keys-type
124-
#- name: dot-imports
125-
#- name: early-return
126-
# arguments:
127-
# - "preserveScope"
124+
- name: dot-imports
125+
- name: early-return
126+
arguments:
127+
- "preserveScope"
128128
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
129129
# See https://github.com/mgechev/revive/issues/386
130130
- name: empty-block
@@ -133,27 +133,27 @@ linters:
133133
- name: error-return
134134
- name: error-strings
135135
- name: errorf
136-
#- name: exported
137-
#- name: increment-decrement
138-
#- name: indent-error-flow
139-
# arguments:
140-
# - "preserveScope"
136+
- name: exported
137+
- name: increment-decrement
138+
- name: indent-error-flow
139+
arguments:
140+
- "preserveScope"
141141
- name: package-comments
142142
# TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them.
143143
disabled: true
144144
- name: range
145-
#- name: receiver-naming
145+
- name: receiver-naming
146146
- name: redefines-builtin-id
147147
- name: superfluous-else
148148
arguments:
149149
- "preserveScope"
150150
- name: time-naming
151-
#- name: unexported-return
151+
- name: unexported-return
152152
- name: unreachable-code
153153
- name: unused-parameter
154-
#- name: unused-receiver
155-
#- name: var-declaration
156-
#- name: var-naming
154+
- name: unused-receiver
155+
- name: var-declaration
156+
- name: var-naming
157157
testifylint:
158158
enable-all: true
159159
disable:

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Secret string
3030
// MarshalSecretValue if set to true will expose Secret type
3131
// through the marshal interfaces. Useful for outside projects
3232
// that load and marshal the Prometheus config.
33-
var MarshalSecretValue bool = false
33+
var MarshalSecretValue = false
3434

3535
// MarshalYAML implements the yaml.Marshaler interface for Secrets.
3636
func (s Secret) MarshalYAML() (interface{}, error) {

config/http_config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func nonZeroCount[T comparable](values ...T) int {
346346
var zero T
347347
for _, value := range values {
348348
if value != zero {
349-
count += 1
349+
count++
350350
}
351351
}
352352
return count
@@ -542,8 +542,14 @@ func (s *secretManagerOption) applyToTLSConfigOptions(opts *tlsConfigOptions) {
542542
opts.secretManager = s.secretManager
543543
}
544544

545+
// SecretManagerOption is an option for providing a SecretManager.
546+
type SecretManagerOption interface {
547+
TLSConfigOption
548+
HTTPClientOption
549+
}
550+
545551
// WithSecretManager allows setting the secret manager.
546-
func WithSecretManager(manager SecretManager) *secretManagerOption {
552+
func WithSecretManager(manager SecretManager) SecretManagerOption {
547553
return &secretManagerOption{
548554
secretManager: manager,
549555
}
@@ -726,11 +732,11 @@ func (s *InlineSecret) Fetch(context.Context) (string, error) {
726732
return s.text, nil
727733
}
728734

729-
func (s *InlineSecret) Description() string {
735+
func (*InlineSecret) Description() string {
730736
return "inline"
731737
}
732738

733-
func (s *InlineSecret) Immutable() bool {
739+
func (*InlineSecret) Immutable() bool {
734740
return true
735741
}
736742

@@ -754,7 +760,7 @@ func (s *FileSecret) Description() string {
754760
return "file " + s.file
755761
}
756762

757-
func (s *FileSecret) Immutable() bool {
763+
func (*FileSecret) Immutable() bool {
758764
return false
759765
}
760766

@@ -772,7 +778,7 @@ func (s *refSecret) Description() string {
772778
return "ref " + s.ref
773779
}
774780

775-
func (s *refSecret) Immutable() bool {
781+
func (*refSecret) Immutable() bool {
776782
return false
777783
}
778784

expfmt/expfmt.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ const (
3636
ProtoType = `application/vnd.google.protobuf`
3737
ProtoProtocol = `io.prometheus.client.MetricFamily`
3838
// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead.
39-
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
40-
OpenMetricsType = `application/openmetrics-text`
39+
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
40+
OpenMetricsType = `application/openmetrics-text`
41+
//nolint:revive // Allow for underscores.
4142
OpenMetricsVersion_0_0_1 = "0.0.1"
43+
//nolint:revive // Allow for underscores.
4244
OpenMetricsVersion_1_0_0 = "1.0.0"
4345

4446
// The Content-Type values for the different wire protocols. Do not do direct
@@ -54,8 +56,10 @@ const (
5456
// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead.
5557
FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text`
5658
// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead.
59+
//nolint:revive // Allow for underscores.
5760
FmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
5861
// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead.
62+
//nolint:revive // Allow for underscores.
5963
FmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
6064
)
6165

@@ -188,8 +192,8 @@ func (f Format) FormatType() FormatType {
188192
// Format contains a escaping=allow-utf-8 term, it will select NoEscaping. If a valid
189193
// "escaping" term exists, that will be used. Otherwise, the global default will
190194
// be returned.
191-
func (format Format) ToEscapingScheme() model.EscapingScheme {
192-
for _, p := range strings.Split(string(format), ";") {
195+
func (f Format) ToEscapingScheme() model.EscapingScheme {
196+
for _, p := range strings.Split(string(f), ";") {
193197
toks := strings.Split(p, "=")
194198
if len(toks) != 2 {
195199
continue

expfmt/text_parse.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@ func (p *TextParser) startLabelName() stateFn {
381381
labels := make(map[string]struct{})
382382
for _, l := range p.currentLabelPairs {
383383
lName := l.GetName()
384-
if _, exists := labels[lName]; !exists {
385-
labels[lName] = struct{}{}
386-
} else {
384+
if _, exists := labels[lName]; exists {
387385
p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
388386
p.currentLabelPairs = nil
389387
return nil
390388
}
389+
labels[lName] = struct{}{}
391390
}
392391
return p.startLabelValue
393392
}

model/labelset.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func (ls LabelSet) Clone() LabelSet {
114114
}
115115

116116
// Merge is a helper function to non-destructively merge two label sets.
117-
func (l LabelSet) Merge(other LabelSet) LabelSet {
118-
result := make(LabelSet, len(l))
117+
func (ls LabelSet) Merge(other LabelSet) LabelSet {
118+
result := make(LabelSet, len(ls))
119119

120-
for k, v := range l {
120+
for k, v := range ls {
121121
result[k] = v
122122
}
123123

@@ -140,7 +140,7 @@ func (ls LabelSet) FastFingerprint() Fingerprint {
140140
}
141141

142142
// UnmarshalJSON implements the json.Unmarshaler interface.
143-
func (l *LabelSet) UnmarshalJSON(b []byte) error {
143+
func (ls *LabelSet) UnmarshalJSON(b []byte) error {
144144
var m map[LabelName]LabelValue
145145
if err := json.Unmarshal(b, &m); err != nil {
146146
return err
@@ -153,6 +153,6 @@ func (l *LabelSet) UnmarshalJSON(b []byte) error {
153153
return fmt.Errorf("%q is not a valid label name", ln)
154154
}
155155
}
156-
*l = LabelSet(m)
156+
*ls = LabelSet(m)
157157
return nil
158158
}

model/metric.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (s ValidationScheme) IsValidLabelName(labelName string) bool {
205205
}
206206

207207
// Type implements the pflag.Value interface.
208-
func (s ValidationScheme) Type() string {
208+
func (ValidationScheme) Type() string {
209209
return "validationScheme"
210210
}
211211

model/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (d *Duration) Set(s string) error {
178178
}
179179

180180
// Type implements pflag.Value.
181-
func (d *Duration) Type() string {
181+
func (*Duration) Type() string {
182182
return "duration"
183183
}
184184

model/value.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ func (m Matrix) Len() int { return len(m) }
350350
func (m Matrix) Less(i, j int) bool { return m[i].Metric.Before(m[j].Metric) }
351351
func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
352352

353-
func (mat Matrix) String() string {
354-
matCp := make(Matrix, len(mat))
355-
copy(matCp, mat)
353+
func (m Matrix) String() string {
354+
matCp := make(Matrix, len(m))
355+
copy(matCp, m)
356356
sort.Sort(matCp)
357357

358358
strs := make([]string, len(matCp))

model/value_histogram.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ func (s *HistogramBucket) Equal(o *HistogramBucket) bool {
8686
return s == o || (s.Boundaries == o.Boundaries && s.Lower == o.Lower && s.Upper == o.Upper && s.Count == o.Count)
8787
}
8888

89-
func (b HistogramBucket) String() string {
89+
func (s HistogramBucket) String() string {
9090
var sb strings.Builder
91-
lowerInclusive := b.Boundaries == 1 || b.Boundaries == 3
92-
upperInclusive := b.Boundaries == 0 || b.Boundaries == 3
91+
lowerInclusive := s.Boundaries == 1 || s.Boundaries == 3
92+
upperInclusive := s.Boundaries == 0 || s.Boundaries == 3
9393
if lowerInclusive {
9494
sb.WriteRune('[')
9595
} else {
9696
sb.WriteRune('(')
9797
}
98-
fmt.Fprintf(&sb, "%g,%g", b.Lower, b.Upper)
98+
fmt.Fprintf(&sb, "%g,%g", s.Lower, s.Upper)
9999
if upperInclusive {
100100
sb.WriteRune(']')
101101
} else {
102102
sb.WriteRune(')')
103103
}
104-
fmt.Fprintf(&sb, ":%v", b.Count)
104+
fmt.Fprintf(&sb, ":%v", s.Count)
105105
return sb.String()
106106
}
107107

0 commit comments

Comments
 (0)