changed the name of all variables with min/max name (#1606)

* changed the name of all variables with min/max name

Signed-off-by: Parth Lawania <parthlawania@gmail.com>

* removed predeclared ignore condition for min and max identifiers

Signed-off-by: Parth Lawania <parthlawania@gmail.com>

---------

Signed-off-by: Parth Lawania <parthlawania@gmail.com>
Co-authored-by: Parth Lawania <parth.lawania@super.money>
This commit is contained in:
Parth Lawania 2024-09-02 16:11:40 +05:30 committed by GitHub
parent 67683fd07e
commit 850b6c0898
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 25 deletions

View File

@ -66,8 +66,6 @@ linters-settings:
local-prefixes: github.com/prometheus/client_golang local-prefixes: github.com/prometheus/client_golang
gofumpt: gofumpt:
extra-rules: true extra-rules: true
predeclared:
ignore: "min,max"
revive: revive:
rules: rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter

View File

@ -330,11 +330,11 @@ func ExponentialBuckets(start, factor float64, count int) []float64 {
// used for the Buckets field of HistogramOpts. // used for the Buckets field of HistogramOpts.
// //
// The function panics if 'count' is 0 or negative, if 'min' is 0 or negative. // The function panics if 'count' is 0 or negative, if 'min' is 0 or negative.
func ExponentialBucketsRange(min, max float64, count int) []float64 { func ExponentialBucketsRange(minBucket, maxBucket float64, count int) []float64 {
if count < 1 { if count < 1 {
panic("ExponentialBucketsRange count needs a positive count") panic("ExponentialBucketsRange count needs a positive count")
} }
if min <= 0 { if minBucket <= 0 {
panic("ExponentialBucketsRange min needs to be greater than 0") panic("ExponentialBucketsRange min needs to be greater than 0")
} }
@ -342,12 +342,12 @@ func ExponentialBucketsRange(min, max float64, count int) []float64 {
// max = min*growthFactor^(bucketCount-1) // max = min*growthFactor^(bucketCount-1)
// We know max/min and highest bucket. Solve for growthFactor. // We know max/min and highest bucket. Solve for growthFactor.
growthFactor := math.Pow(max/min, 1.0/float64(count-1)) growthFactor := math.Pow(maxBucket/minBucket, 1.0/float64(count-1))
// Now that we know growthFactor, solve for each bucket. // Now that we know growthFactor, solve for each bucket.
buckets := make([]float64, count) buckets := make([]float64, count)
for i := 1; i <= count; i++ { for i := 1; i <= count; i++ {
buckets[i-1] = min * math.Pow(growthFactor, float64(i-1)) buckets[i-1] = minBucket * math.Pow(growthFactor, float64(i-1))
} }
return buckets return buckets
} }

View File

@ -25,14 +25,14 @@ import (
"strings" "strings"
) )
func min(a, b int) int { func minInt(a, b int) int {
if a < b { if a < b {
return a return a
} }
return b return b
} }
func max(a, b int) int { func maxInt(a, b int) int {
if a > b { if a > b {
return a return a
} }
@ -427,12 +427,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
if codes[0].Tag == 'e' { if codes[0].Tag == 'e' {
c := codes[0] c := codes[0]
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2 i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
codes[0] = OpCode{c.Tag, max(i1, i2-n), i2, max(j1, j2-n), j2} codes[0] = OpCode{c.Tag, maxInt(i1, i2-n), i2, maxInt(j1, j2-n), j2}
} }
if codes[len(codes)-1].Tag == 'e' { if codes[len(codes)-1].Tag == 'e' {
c := codes[len(codes)-1] c := codes[len(codes)-1]
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2 i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
codes[len(codes)-1] = OpCode{c.Tag, i1, min(i2, i1+n), j1, min(j2, j1+n)} codes[len(codes)-1] = OpCode{c.Tag, i1, minInt(i2, i1+n), j1, minInt(j2, j1+n)}
} }
nn := n + n nn := n + n
groups := [][]OpCode{} groups := [][]OpCode{}
@ -443,12 +443,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
// there is a large range with no changes. // there is a large range with no changes.
if c.Tag == 'e' && i2-i1 > nn { if c.Tag == 'e' && i2-i1 > nn {
group = append(group, OpCode{ group = append(group, OpCode{
c.Tag, i1, min(i2, i1+n), c.Tag, i1, minInt(i2, i1+n),
j1, min(j2, j1+n), j1, minInt(j2, j1+n),
}) })
groups = append(groups, group) groups = append(groups, group)
group = []OpCode{} group = []OpCode{}
i1, j1 = max(i1, i2-n), max(j1, j2-n) i1, j1 = maxInt(i1, i2-n), maxInt(j1, j2-n)
} }
group = append(group, OpCode{c.Tag, i1, i2, j1, j2}) group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
} }
@ -515,7 +515,7 @@ func (m *SequenceMatcher) QuickRatio() float64 {
// is faster to compute than either .Ratio() or .QuickRatio(). // is faster to compute than either .Ratio() or .QuickRatio().
func (m *SequenceMatcher) RealQuickRatio() float64 { func (m *SequenceMatcher) RealQuickRatio() float64 {
la, lb := len(m.a), len(m.b) la, lb := len(m.a), len(m.b)
return calculateRatio(min(la, lb), la+lb) return calculateRatio(minInt(la, lb), la+lb)
} }
// Convert range to the "ed" format // Convert range to the "ed" format

View File

@ -263,12 +263,12 @@ func TestSummaryConcurrency(t *testing.T) {
ε := objMap[wantQ] ε := objMap[wantQ]
gotQ := *m.Summary.Quantile[i].Quantile gotQ := *m.Summary.Quantile[i].Quantile
gotV := *m.Summary.Quantile[i].Value gotV := *m.Summary.Quantile[i].Value
min, max := getBounds(allVars, wantQ, ε) minBound, maxBound := getBounds(allVars, wantQ, ε)
if gotQ != wantQ { if gotQ != wantQ {
t.Errorf("got quantile %f, want %f", gotQ, wantQ) t.Errorf("got quantile %f, want %f", gotQ, wantQ)
} }
if gotV < min || gotV > max { if gotV < minBound || gotV > maxBound {
t.Errorf("got %f for quantile %f, want [%f,%f]", gotV, gotQ, min, max) t.Errorf("got %f for quantile %f, want [%f,%f]", gotV, gotQ, minBound, maxBound)
} }
} }
return true return true
@ -353,12 +353,12 @@ func TestSummaryVecConcurrency(t *testing.T) {
ε := objMap[wantQ] ε := objMap[wantQ]
gotQ := *m.Summary.Quantile[j].Quantile gotQ := *m.Summary.Quantile[j].Quantile
gotV := *m.Summary.Quantile[j].Value gotV := *m.Summary.Quantile[j].Value
min, max := getBounds(allVars[i], wantQ, ε) minBound, maxBound := getBounds(allVars[i], wantQ, ε)
if gotQ != wantQ { if gotQ != wantQ {
t.Errorf("got quantile %f for label %c, want %f", gotQ, 'A'+i, wantQ) t.Errorf("got quantile %f for label %c, want %f", gotQ, 'A'+i, wantQ)
} }
if gotV < min || gotV > max { if gotV < minBound || gotV > maxBound {
t.Errorf("got %f for quantile %f for label %c, want [%f,%f]", gotV, gotQ, 'A'+i, min, max) t.Errorf("got %f for quantile %f for label %c, want [%f,%f]", gotV, gotQ, 'A'+i, minBound, maxBound)
} }
} }
} }
@ -410,20 +410,20 @@ func TestSummaryDecay(t *testing.T) {
} }
} }
func getBounds(vars []float64, q, ε float64) (min, max float64) { func getBounds(vars []float64, q, ε float64) (minBound, maxBound float64) {
// TODO(beorn7): This currently tolerates an error of up to 2*ε. The // TODO(beorn7): This currently tolerates an error of up to 2*ε. The
// error must be at most ε, but for some reason, it's sometimes slightly // error must be at most ε, but for some reason, it's sometimes slightly
// higher. That's a bug. // higher. That's a bug.
n := float64(len(vars)) n := float64(len(vars))
lower := int((q - 2*ε) * n) lower := int((q - 2*ε) * n)
upper := int(math.Ceil((q + 2*ε) * n)) upper := int(math.Ceil((q + 2*ε) * n))
min = vars[0] minBound = vars[0]
if lower > 1 { if lower > 1 {
min = vars[lower-1] minBound = vars[lower-1]
} }
max = vars[len(vars)-1] maxBound = vars[len(vars)-1]
if upper < len(vars) { if upper < len(vars) {
max = vars[upper-1] maxBound = vars[upper-1]
} }
return return
} }