fix(ci): run linter with all build tags (#17027)

Fix up lint errors that were not previously checked.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
George Krajcsovits 2025-08-08 11:43:41 +02:00 committed by GitHub
parent 1e4144a496
commit 929bd787ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 17 deletions

View File

@ -226,10 +226,22 @@ jobs:
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
- name: Lint with stringlabels
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
args: --verbose
args: --verbose --build-tags=stringlabels
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
version: v2.2.1
- name: Lint with slicelabels
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
args: --verbose --build-tags=slicelabels
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
version: v2.2.1
- name: Lint with dedupelabels
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
args: --verbose --build-tags=dedupelabels
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
version: v2.2.1
fuzzing:

View File

@ -55,7 +55,7 @@ func NewSymbolTable() *SymbolTable {
nameTable: &nameTable{byNum: make([]string, defaultSymbolTableSize)},
byName: make(map[string]int, defaultSymbolTableSize),
}
t.nameTable.symbolTable = t
t.symbolTable = t
return t
}
@ -95,8 +95,8 @@ func (t *SymbolTable) toNumUnlocked(name string) int {
func (t *SymbolTable) checkNum(name string) (int, bool) {
t.mx.Lock()
defer t.mx.Unlock()
i, bool := t.byName[name]
return i, bool
i, ok := t.byName[name]
return i, ok
}
// ToName maps an integer to a string.
@ -117,7 +117,7 @@ func decodeVarint(data string, index int) (int, int) {
}
func decodeVarintRest(b int, data string, index int) (int, int) {
value := int(b & 0x7FFF)
value := b & 0x7FFF
b = int(data[index])
index++
if b < 0x80 {
@ -165,7 +165,7 @@ func (ls Labels) IsZero() bool {
// MatchLabels returns a subset of Labels that matches/does not match with the provided label names based on the 'on' boolean.
// If on is set to true, it returns the subset of labels that match with the provided label names and its inverse when 'on' is set to false.
// TODO: This is only used in printing an error message
// TODO: This is only used in printing an error message.
func (ls Labels) MatchLabels(on bool, names ...string) Labels {
b := NewBuilder(ls)
if on {
@ -506,7 +506,7 @@ func Compare(a, b Labels) int {
return (la - ia) - (lb - ib)
}
// Copy labels from b on top of whatever was in ls previously, reusing memory or expanding if needed.
// CopyFrom copies labels from b on top of whatever was in ls previously, reusing memory or expanding if needed.
func (ls *Labels) CopyFrom(b Labels) {
*ls = b // Straightforward memberwise copy is all we need.
}
@ -552,12 +552,12 @@ func (ls Labels) Validate(f func(l Label) error) error {
}
// InternStrings calls intern on every string value inside ls, replacing them with what it returns.
func (ls *Labels) InternStrings(intern func(string) string) {
func (*Labels) InternStrings(func(string) string) {
// TODO: remove these calls as there is nothing to do.
}
// ReleaseStrings calls release on every string value inside ls.
func (ls Labels) ReleaseStrings(release func(string)) {
func (Labels) ReleaseStrings(func(string)) {
// TODO: remove these calls as there is nothing to do.
}
@ -701,7 +701,7 @@ func encodeVarintSlow(data []byte, offset int, v uint64) int {
return base
}
// Special code for the common case that a value is less than 32768
// Special code for the common case that a value is less than 32768.
func encodeVarint(data []byte, offset, v int) int {
if v < 1<<15 {
offset -= 2
@ -747,7 +747,7 @@ func appendLabelTo(nameNum, valueNum int, buf []byte) []byte {
}
i := sizeRequired
i = encodeVarint(buf, i, valueNum)
i = encodeVarint(buf, i, nameNum)
encodeVarint(buf, i, nameNum)
return buf
}
@ -786,7 +786,7 @@ func (b *ScratchBuilder) Add(name, value string) {
b.add = append(b.add, Label{Name: name, Value: value})
}
// Add a name/value pair, using []byte instead of string to reduce memory allocations.
// UnsafeAddBytes adds a name/value pair, using []byte instead of string to reduce memory allocations.
// The values must remain live until Labels() is called.
func (b *ScratchBuilder) UnsafeAddBytes(name, value []byte) {
b.add = append(b.add, Label{Name: yoloString(name), Value: yoloString(value)})
@ -815,7 +815,7 @@ func (b *ScratchBuilder) Labels() Labels {
return b.output
}
// Write the newly-built Labels out to ls, reusing an internal buffer.
// Overwrite the newly-built Labels out to ls, reusing an internal buffer.
// Callers must ensure that there are no other references to ls, or any strings fetched from it.
func (b *ScratchBuilder) Overwrite(ls *Labels) {
var size int

View File

@ -252,7 +252,7 @@ func (ls Labels) WithoutEmpty() Labels {
// the two string headers size for name and value.
// Slice header size is ignored because it should be amortized to zero.
func (ls Labels) ByteSize() uint64 {
var size uint64 = 0
var size uint64
for _, l := range ls {
size += uint64(len(l.Name)+len(l.Value)) + 2*uint64(unsafe.Sizeof(""))
}
@ -445,7 +445,7 @@ type SymbolTable struct{}
func NewSymbolTable() *SymbolTable { return nil }
func (t *SymbolTable) Len() int { return 0 }
func (*SymbolTable) Len() int { return 0 }
// NewScratchBuilder creates a ScratchBuilder initialized for Labels with n entries.
func NewScratchBuilder(n int) ScratchBuilder {
@ -462,7 +462,7 @@ func NewScratchBuilderWithSymbolTable(_ *SymbolTable, n int) ScratchBuilder {
return NewScratchBuilder(n)
}
func (b *ScratchBuilder) SetSymbolTable(*SymbolTable) {
func (*ScratchBuilder) SetSymbolTable(*SymbolTable) {
// no-op
}