From 72f939f39ec08786686d413e520ae0e78a1adae9 Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Tue, 4 Nov 2025 13:40:03 -0600 Subject: [PATCH 1/2] Add modernize linter to .golangci.yml; apply fixes Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- .golangci.yml | 1 + pkg/compile/compile_test.go | 22 +++++++++------------- pkg/render/tea.go | 10 +++++----- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89028d58f..81732164b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,6 +26,7 @@ linters: - ineffassign - makezero - misspell + - modernize - nakedret - nestif - nilerr diff --git a/pkg/compile/compile_test.go b/pkg/compile/compile_test.go index 215c363e7..81fb0df79 100644 --- a/pkg/compile/compile_test.go +++ b/pkg/compile/compile_test.go @@ -267,8 +267,7 @@ func BenchmarkRecursive(b *testing.B) { ctx := context.Background() fss := getAllRuleFS() - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := Recursive(ctx, fss) if err != nil { b.Fatalf("Compilation failed: %v", err) @@ -284,8 +283,7 @@ func BenchmarkRecursiveCachedFirstRun(b *testing.B) { ctx := context.Background() fss := getAllRuleFS() - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := Recursive(ctx, fss) if err != nil { b.Fatalf("Compilation failed: %v", err) @@ -306,8 +304,7 @@ func BenchmarkRecursiveCachedSubsequentRuns(b *testing.B) { b.Fatalf("Failed to populate cache: %v", err) } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := RecursiveCached(ctx, fss) if err != nil { b.Fatalf("Cached compilation failed: %v", err) @@ -323,8 +320,7 @@ func BenchmarkGetRulesHash(b *testing.B) { ctx := context.Background() realFS := getAllRuleFS() - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { hash, err := getRulesHash(ctx, realFS) if err != nil { b.Fatalf("Hash calculation failed: %v", err) @@ -349,7 +345,7 @@ func BenchmarkCacheOperations(b *testing.B) { cacheFile := filepath.Join(tempDir, "benchmark-rules.cache") b.Run("Save", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { testFile := filepath.Join(tempDir, "test-"+string(rune('a'+i%26))+".cache") err := saveCachedRules(rules, testFile) if err != nil { @@ -364,7 +360,7 @@ func BenchmarkCacheOperations(b *testing.B) { } b.Run("Load", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { loadedRules, err := loadCachedRules(cacheFile) if err != nil { b.Fatalf("Failed to load rules: %v", err) @@ -382,7 +378,7 @@ func BenchmarkCompareCompilation(b *testing.B) { fss := getAllRuleFS() b.Run("Uncached", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := Recursive(ctx, fss) if err != nil { b.Fatalf("Uncached compilation failed: %v", err) @@ -394,7 +390,7 @@ func BenchmarkCompareCompilation(b *testing.B) { }) b.Run("CachedFirstRun", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := Recursive(ctx, fss) if err != nil { b.Fatalf("Compilation failed: %v", err) @@ -414,7 +410,7 @@ func BenchmarkCompareCompilation(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { rules, err := RecursiveCached(ctx, fss) if err != nil { b.Fatalf("Cached compilation failed: %v", err) diff --git a/pkg/render/tea.go b/pkg/render/tea.go index 2823012e3..e4c15ed76 100644 --- a/pkg/render/tea.go +++ b/pkg/render/tea.go @@ -237,19 +237,19 @@ func (m *mainModel) performSearch() { if strings.Contains(lowerLine, term) { foundMatch = true lastIndex := 0 - resultLine := "" + var resultLine strings.Builder for { index := strings.Index(strings.ToLower(line[lastIndex:]), term) if index == -1 { - resultLine += line[lastIndex:] + resultLine.WriteString(line[lastIndex:]) break } - resultLine += line[lastIndex : lastIndex+index] + resultLine.WriteString(line[lastIndex : lastIndex+index]) matchText := line[lastIndex+index : lastIndex+index+len(term)] - resultLine += matchStyle.Render(matchText) + resultLine.WriteString(matchStyle.Render(matchText)) lastIndex += index + len(term) } - matchedLines = append(matchedLines, resultLine) + matchedLines = append(matchedLines, resultLine.String()) } else if foundMatch { matchedLines = append(matchedLines, line) foundMatch = false From a6659313c33bf12b15b8e4838591ada465d31dfa Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Tue, 4 Nov 2025 13:43:39 -0600 Subject: [PATCH 2/2] Bump golangci-lint to v2.6.1 for good measure Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 010e9d9ea..67f63e10a 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ LINTERS := FIXERS := GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml -GOLANGCI_LINT_VERSION ?= v2.6.0 +GOLANGCI_LINT_VERSION ?= v2.6.1 GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) $(GOLANGCI_LINT_BIN): mkdir -p $(LINT_ROOT)/out/linters