Skip to content

chore: improve golangci-lint configuration#1258

Open
flemzord wants to merge 9 commits intomainfrom
chore/improve-golangci-lint-config
Open

chore: improve golangci-lint configuration#1258
flemzord wants to merge 9 commits intomainfrom
chore/improve-golangci-lint-config

Conversation

@flemzord
Copy link
Copy Markdown
Member

@flemzord flemzord commented Feb 9, 2026

Summary

  • Configure tagliatelle linter with goCamel convention following Effective Go naming rules (json, yaml, xml, bson, env tags)
  • Exclude pkg/client (generated SDK code) from linting
  • Suppress gocyclo false positives on string mapping table, AST visitor, and bytecode interpreter
  • Fix unconvert unnecessary type conversions
  • Add nolint:unparam directives where parameters are intentionally kept for API consistency
  • Fix errchkjson unchecked json.Marshal error
  • Add missing t.Parallel() calls to satisfy tparallel linter (27 test functions)
  • Enable usetesting linter and replace context.Background()/context.TODO() with t.Context() in tests

Test plan

  • just lint passes with 0 issues
  • go test -race ./... passes all unit tests

Enable tagliatelle linter to enforce Effective Go naming conventions
on struct tags (json, yaml, xml, bson, env). Exclude generated SDK
code in pkg/client from linting. Add nolint directives for targetId
fields to preserve JSON API backward compatibility.
…positives

Exclude pkg/client from golangci-lint analysis as it contains generated
SDK code. Add nolint:gocyclo directives on three functions where high
cyclomatic complexity is structural (string mapping, AST visitor,
bytecode interpreter) rather than indicative of actual logic complexity.
Remove unnecessary type conversions for RuntimeType and string casts.
Add nolint:unparam directives where parameters are intentionally kept
for API consistency, recursive propagation, or test flexibility.
Handle the error return from json.Marshal instead of silently
discarding it. Panic on failure as DocID contains only basic types
that cannot fail to marshal.
Add t.Parallel() to test functions and subtests where it was missing,
ensuring both parent tests and their subtests call t.Parallel()
consistently across API v1, API v2, VM, replication, storage, and
accounts test files.
Enable usetesting linter and replace context.Background() and
context.TODO() with t.Context() (or b.Context()) in test files.
This ensures test contexts are properly cancelled when tests finish,
preventing resource leaks.
@flemzord flemzord requested a review from a team as a code owner February 9, 2026 12:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f5c87316-17c6-4001-a4a6-510cb75f4f4d

📥 Commits

Reviewing files that changed from the base of the PR and between fb703b4 and 744c323.

⛔ Files ignored due to path filters (1)
  • internal/README.md is excluded by !internal/README.md
📒 Files selected for processing (1)
  • internal/replication/drivers/batcher_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/replication/drivers/batcher_test.go

Walkthrough

Added many test parallelizations and test-context migrations; sprinkled lint-suppression annotations; minor runtime changes: new controller event-handling path, parser selection tweak, and stricter JSON error handling in an Elasticsearch driver.

Changes

Cohort / File(s) Summary
Linting Annotations
internal/api/bulking/elements.go, internal/log.go, pkg/events/message.go
Added //nolint:tagliatelle to TargetID fields and other lint suppression comments; non-functional.
Cyclomatic / Unused Suppressions
internal/machine/script/compiler/source.go, internal/machine/vm/machine.go, internal/tracing/tracing.go, internal/replication/manager.go, internal/storage/ledger/main_test.go
Added //nolint:gocyclo / //nolint:unparam annotations to suppress specific linters; no behavior changes.
Test Parallelization: API v1
internal/api/v1/controllers_accounts_add_metadata_test.go, internal/api/v1/controllers_accounts_count_test.go, internal/api/v1/controllers_accounts_list_test.go, internal/api/v1/controllers_accounts_read_test.go, internal/api/v1/controllers_balances_aggregates_test.go, internal/api/v1/controllers_logs_list_test.go, internal/api/v1/controllers_transactions_count_test.go, internal/api/v1/controllers_transactions_list_test.go
Inserted t.Parallel() into subtests to run table-driven tests concurrently; test logic unchanged.
Test Parallelization: API v2
internal/api/v2/...controllers_*.go
Inserted t.Parallel() into many v2 controller subtests to enable concurrent execution; test expectations unchanged.
Test Parallelization: Misc tests
internal/bus/listener_test.go, internal/machine/vm/machine_test.go, internal/machine/vm/run_test.go, internal/replication/manager_test.go, internal/storage/ledger/logs_test.go, pkg/accounts/account_test.go, test/performance/pkg/read/read_test.go
Added t.Parallel() and adjusted benchmark/test harness to use test-scoped context where applicable.
Context Migration in Tests
internal/bus/listener_test.go, internal/controller/ledger/controller_default_test.go, internal/machine/vm/*_test.go, internal/replication/drivers/*_test.go, internal/storage/ledger/*_test.go, test/performance/pkg/read/read_test.go
Replaced context.Background() / context.TODO() with t.Context() and removed unused imports.
Controller: event handling & parser selection
internal/controller/ledger/controller_with_events.go, internal/controller/ledger/controller_default.go
Added unexported handleEvent to defer/forward event functions depending on transaction state; removed an explicit type conversion when selecting parser in insertSchema.
Elasticsearch driver error handling
internal/replication/drivers/elasticsearch/driver.go
DocID.String() now checks json.Marshal error and panics on failure instead of ignoring the error.
Small test / minor changes
many test files across repo (mostly ..._test.go)
Minor assertion/format adjustments, some nolint comments, and small context / concurrency-related edits.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Caller
participant Controller as ControllerWithEvents
participant Parent as ParentController
participant Commit as CommitProcessor
Note over Controller: handleEvent(ctx, fn)
Caller->>Controller: handleEvent(ctx, fn)
alt no active transaction
Controller->>Caller: execute fn immediately
else has parent with tx
Controller->>Parent: forward handleEvent(ctx, fn)
Parent->>Parent: enqueue or execute per parent state
else active tx and no parent
Controller->>Controller: enqueue fn into atCommit
Note over Commit: on Commit
Commit->>Controller: run all atCommit fns
Controller->>Commit: execute fn(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble on lint and hop through the tests,

Parallel hares now run their small quests.
Context from T keeps the burrow in tune,
Events wait for Commit—then we all sing a tune.
Hooray for small hops that make code feel light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main purpose of the changeset: improving golangci-lint configuration by adding linter directives, replacing context calls, and enabling new linters.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing specific linter improvements, configuration changes, and test updates with a clear test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/improve-golangci-lint-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/controller/ledger/controller_with_events.go (1)

30-42: ⚠️ Potential issue | 🟠 Major

Defer events when a parent transaction is active.

When c.hasTx is false but c.parent.hasTx is true (e.g., a controller returned by LockLedger within a transaction), handleEvent executes immediately and bypasses commit-time dispatch. This breaks the “emit at commit” semantics for nested controllers.

🔧 Suggested fix (prioritize parent tx before immediate execution)
 func (c *ControllerWithEvents) handleEvent(ctx context.Context, fn func()) {
-	if !c.hasTx {
-		fn()
-		return
-	}
-	if c.parent != nil && c.parent.hasTx {
+	if c.parent != nil && c.parent.hasTx {
 		c.parent.handleEvent(ctx, fn)
 		return
 	}
+	if !c.hasTx {
+		fn()
+		return
+	}
 
 	c.atCommit = append(c.atCommit, fn)
 }
🧹 Nitpick comments (1)
internal/storage/ledger/accounts_test.go (1)

327-329: Consider using ctx for consistency within this test.

The test declares ctx := logging.TestingContext() at line 321 and uses it for UpdateAccountsMetadata at line 323, but this call now uses t.Context(). This creates an inconsistency where one operation has the logging context and the other doesn't.

For consistency with both this test function and all other tests in this file, consider using ctx here.

Suggested change
-	account, err := store.Accounts().GetOne(t.Context(), common.ResourceQuery[any]{
+	account, err := store.Accounts().GetOne(ctx, common.ResourceQuery[any]{

gfyrag
gfyrag previously approved these changes Feb 9, 2026
…ontext canceled error

t.Context() is canceled before t.Cleanup runs, causing batcher.Stop()
to fail immediately instead of waiting for graceful shutdown.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.07%. Comparing base (a2b701e) to head (744c323).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
...ternal/replication/drivers/elasticsearch/driver.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1258      +/-   ##
==========================================
- Coverage   82.20%   78.07%   -4.14%     
==========================================
  Files         198      205       +7     
  Lines       10224    10979     +755     
==========================================
+ Hits         8405     8572     +167     
- Misses       1326     1555     +229     
- Partials      493      852     +359     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants