Skip to content

Commit 057c21f

Browse files
authored
Add modernize linter to .golangci.yml; apply fixes (#1200)
* Add modernize linter to .golangci.yml; apply fixes Signed-off-by: egibs <[email protected]> * Bump golangci-lint to v2.6.1 for good measure Signed-off-by: egibs <[email protected]> --------- Signed-off-by: egibs <[email protected]>
1 parent 8c3e803 commit 057c21f

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ linters:
2626
- ineffassign
2727
- makezero
2828
- misspell
29+
- modernize
2930
- nakedret
3031
- nestif
3132
- nilerr

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LINTERS :=
4242
FIXERS :=
4343

4444
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
45-
GOLANGCI_LINT_VERSION ?= v2.6.0
45+
GOLANGCI_LINT_VERSION ?= v2.6.1
4646
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
4747
$(GOLANGCI_LINT_BIN):
4848
mkdir -p $(LINT_ROOT)/out/linters

pkg/compile/compile_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ func BenchmarkRecursive(b *testing.B) {
267267
ctx := context.Background()
268268
fss := getAllRuleFS()
269269

270-
b.ResetTimer()
271-
for i := 0; i < b.N; i++ {
270+
for b.Loop() {
272271
rules, err := Recursive(ctx, fss)
273272
if err != nil {
274273
b.Fatalf("Compilation failed: %v", err)
@@ -284,8 +283,7 @@ func BenchmarkRecursiveCachedFirstRun(b *testing.B) {
284283
ctx := context.Background()
285284
fss := getAllRuleFS()
286285

287-
b.ResetTimer()
288-
for i := 0; i < b.N; i++ {
286+
for b.Loop() {
289287
rules, err := Recursive(ctx, fss)
290288
if err != nil {
291289
b.Fatalf("Compilation failed: %v", err)
@@ -306,8 +304,7 @@ func BenchmarkRecursiveCachedSubsequentRuns(b *testing.B) {
306304
b.Fatalf("Failed to populate cache: %v", err)
307305
}
308306

309-
b.ResetTimer()
310-
for i := 0; i < b.N; i++ {
307+
for b.Loop() {
311308
rules, err := RecursiveCached(ctx, fss)
312309
if err != nil {
313310
b.Fatalf("Cached compilation failed: %v", err)
@@ -323,8 +320,7 @@ func BenchmarkGetRulesHash(b *testing.B) {
323320
ctx := context.Background()
324321
realFS := getAllRuleFS()
325322

326-
b.ResetTimer()
327-
for i := 0; i < b.N; i++ {
323+
for b.Loop() {
328324
hash, err := getRulesHash(ctx, realFS)
329325
if err != nil {
330326
b.Fatalf("Hash calculation failed: %v", err)
@@ -349,7 +345,7 @@ func BenchmarkCacheOperations(b *testing.B) {
349345
cacheFile := filepath.Join(tempDir, "benchmark-rules.cache")
350346

351347
b.Run("Save", func(b *testing.B) {
352-
for i := 0; i < b.N; i++ {
348+
for i := 0; b.Loop(); i++ {
353349
testFile := filepath.Join(tempDir, "test-"+string(rune('a'+i%26))+".cache")
354350
err := saveCachedRules(rules, testFile)
355351
if err != nil {
@@ -364,7 +360,7 @@ func BenchmarkCacheOperations(b *testing.B) {
364360
}
365361

366362
b.Run("Load", func(b *testing.B) {
367-
for i := 0; i < b.N; i++ {
363+
for b.Loop() {
368364
loadedRules, err := loadCachedRules(cacheFile)
369365
if err != nil {
370366
b.Fatalf("Failed to load rules: %v", err)
@@ -382,7 +378,7 @@ func BenchmarkCompareCompilation(b *testing.B) {
382378
fss := getAllRuleFS()
383379

384380
b.Run("Uncached", func(b *testing.B) {
385-
for i := 0; i < b.N; i++ {
381+
for b.Loop() {
386382
rules, err := Recursive(ctx, fss)
387383
if err != nil {
388384
b.Fatalf("Uncached compilation failed: %v", err)
@@ -394,7 +390,7 @@ func BenchmarkCompareCompilation(b *testing.B) {
394390
})
395391

396392
b.Run("CachedFirstRun", func(b *testing.B) {
397-
for i := 0; i < b.N; i++ {
393+
for b.Loop() {
398394
rules, err := Recursive(ctx, fss)
399395
if err != nil {
400396
b.Fatalf("Compilation failed: %v", err)
@@ -414,7 +410,7 @@ func BenchmarkCompareCompilation(b *testing.B) {
414410
}
415411

416412
b.ResetTimer()
417-
for i := 0; i < b.N; i++ {
413+
for b.Loop() {
418414
rules, err := RecursiveCached(ctx, fss)
419415
if err != nil {
420416
b.Fatalf("Cached compilation failed: %v", err)

pkg/render/tea.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@ func (m *mainModel) performSearch() {
237237
if strings.Contains(lowerLine, term) {
238238
foundMatch = true
239239
lastIndex := 0
240-
resultLine := ""
240+
var resultLine strings.Builder
241241
for {
242242
index := strings.Index(strings.ToLower(line[lastIndex:]), term)
243243
if index == -1 {
244-
resultLine += line[lastIndex:]
244+
resultLine.WriteString(line[lastIndex:])
245245
break
246246
}
247-
resultLine += line[lastIndex : lastIndex+index]
247+
resultLine.WriteString(line[lastIndex : lastIndex+index])
248248
matchText := line[lastIndex+index : lastIndex+index+len(term)]
249-
resultLine += matchStyle.Render(matchText)
249+
resultLine.WriteString(matchStyle.Render(matchText))
250250
lastIndex += index + len(term)
251251
}
252-
matchedLines = append(matchedLines, resultLine)
252+
matchedLines = append(matchedLines, resultLine.String())
253253
} else if foundMatch {
254254
matchedLines = append(matchedLines, line)
255255
foundMatch = false

0 commit comments

Comments
 (0)