Skip to content

tools: adopt llformat formatting targets#1136

Open
hieblmi wants to merge 4 commits into
lightninglabs:masterfrom
hieblmi:codex/llformat-flow
Open

tools: adopt llformat formatting targets#1136
hieblmi wants to merge 4 commits into
lightninglabs:masterfrom
hieblmi:codex/llformat-flow

Conversation

@hieblmi
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi commented May 5, 2026

Summary

Adopt llformat as the repository formatting path while keeping the formatter invocation equivalent to vanilla llformat defaults. The Makefile only passes -w so files are written in place; all formatting behavior remains owned by llformat itself.

This PR is split into four commits:

  • tools: add llformat formatting targets
    • pins github.com/bhandras/llformat/cmd/llformat in the tools module
    • adds make fmt for all handwritten Go files
    • adds make fmt-changed for branch, staged, unstaged, and untracked Go changes
    • centralizes generated-file/vendor/testdata exclusions in scripts/llformat-files.sh
  • tools: tune lint for llformat adoption
    • disables the whitespace linter rule that conflicts with llformat-owned vertical spacing
  • format: apply llformat baseline
    • applies the baseline make fmt result across handwritten Go files
  • liquidity: fix duplicate sweep label
    • fixes an existing duplicate word that became visible to dupword after llformat joined adjacent string fragments

Validation

  • make fmt
  • make fmt-changed base=upstream/master
  • make mod-check
  • make build tags=dev
  • make lint
  • GOCACHE=/private/tmp/loop-go-build-cache make unit

Notes

The file-selection helper excludes generated Go outputs, vendor, third_party, and testdata paths before invoking llformat. It does not pass any non-default formatter options.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces llformat as the standard Go code formatter for the repository. It includes the necessary tooling setup, Makefile targets for formatting, and adjustments to existing linting configurations to ensure compatibility. A baseline formatting pass has been applied to the codebase, and a minor bug fix was included to address a duplicate word issue surfaced by the new formatting.

Highlights

  • Adopt llformat: Adopted llformat as the repository's Go code formatter, including pinning the tool in the tools module and adding make fmt and make fmt-changed targets.
  • Linting adjustments: Disabled the whitespace linter rule in .golangci.yml to prevent conflicts with llformat's vertical spacing rules.
  • Codebase formatting: Applied the baseline llformat formatting across all handwritten Go files.
  • Bug fix: Fixed a duplicate word in the liquidity package that was exposed by llformat's string fragment handling.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces llformat as the new tool for managing vertical whitespace in handwritten Go code, updating the project's configuration, Makefile, and CI tools accordingly. The review identified a performance improvement for the fmt target in the Makefile, a typo in the daemon startup error message, and a robustness issue in the file listing script regarding filenames with special characters.

Comment thread Makefile
fmt: $(LLFORMAT_BIN)
@$(call print, "Formatting all handwritten Go source.")
@./scripts/llformat-files.sh all | \
xargs -0 -n 1 $(LLFORMAT_BIN) -w
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Invoking the formatter with xargs -n 1 is inefficient as it forks a new process for every single file. Formatter tools like llformat typically support multiple file arguments, so you should allow xargs to pass as many files as possible in a single invocation to improve performance.

		xargs -0 $(LLFORMAT_BIN) -w

Comment thread loopd/daemon.go
"(standalone or embedded in lightning-terminal) is"+
"running", err)
"(standalone or embedded in lightning-terminal) "+
"isrunning", err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The word isrunning appears to be a typo introduced while attempting to fix a duplicate word. It should be separated into two words: is running.

Suggested change
"isrunning", err)
"is running", err)

Comment thread scripts/llformat-files.sh
Comment on lines +50 to +54
git diff --name-only --diff-filter=ACMR "$base"...HEAD
git diff --name-only --diff-filter=ACMR
git diff --cached --name-only --diff-filter=ACMR
git ls-files --others --exclude-standard
} | sort -u | while IFS= read -r file; do
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The list_changed function is not as robust as list_all because it relies on newline-separated output from git and sort. While rare in Go projects, filenames containing spaces or special characters could cause issues. It is safer to use null-terminated strings throughout the pipeline, especially since the output is eventually consumed by xargs -0.

Suggested change
git diff --name-only --diff-filter=ACMR "$base"...HEAD
git diff --name-only --diff-filter=ACMR
git diff --cached --name-only --diff-filter=ACMR
git ls-files --others --exclude-standard
} | sort -u | while IFS= read -r file; do
{
git diff --name-only -z --diff-filter=ACMR "$base"...HEAD
git diff --name-only -z --diff-filter=ACMR
git diff --cached --name-only -z --diff-filter=ACMR
git ls-files -z --others --exclude-standard
} | sort -z -u | while IFS= read -r -d '' file; do

@hieblmi hieblmi requested a review from bhandras May 5, 2026 11:11
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented May 5, 2026

@claude please review the changes to the code that are introduced in this PR. Can you confirm this the changes are style and formatting changes only? Or are there any logic or behavioral changes introduced?

@claude
Copy link
Copy Markdown

claude Bot commented May 5, 2026

Code Review: tools: adopt llformat formatting targets

Overview

This PR adopts llformat as the project's canonical formatter, replacing gosimports + gofmt, adds two Makefile targets (fmt / fmt-changed), centralizes file-selection logic in a shell helper, disables the now-redundant whitespace linter, applies the baseline formatting pass, and fixes a pre-existing duplicate-word bug exposed by the new linter setup. The scope and structure are clear.


Tooling Infrastructure

Positive:

  • Installing llformat to $(CURDIR)/$(TOOLS_DIR)/llformat (not $GOPATH/bin) keeps it scoped to this repo and reproducible across machines. Good hygiene.
  • The tool directive in tools/go.mod is the right Go 1.24+ approach to pinning tool dependencies; the corresponding go.sum entry makes the version hermetic.
  • fmt-changed with a configurable base= override and a sensible origin/master default is a nice ergonomic addition for day-to-day use.
  • Null-terminated output (-print0 / printf '%s\0') in list_all + xargs -0 correctly handles filenames containing spaces.

Concerns:

  1. GOIMPORTS_BIN / GOIMPORTS_PKG / $(GOIMPORTS_BIN) are now dead code in the Makefile. The fmt target no longer depends on them and gosimports is no longer invoked. Unless these are needed elsewhere (e.g., an IDE integration target I didn't spot), removing them would reduce noise and avoid confusion for future contributors.

  2. list_changed uses newline-delimited git output, not null-terminated. This is fine in practice (Go filenames never contain newlines), but it creates a subtle inconsistency with list_all. Consider adding -- to guard against accidentally treating flags as filenames:

    git diff --name-only --diff-filter=ACMR -- "$base"...HEAD
  3. xargs -0 -n 1 without -r / --no-run-if-empty: On GNU xargs (Linux) the behavior when stdin is empty is to not invoke the command, which is the desired behaviour. However, POSIX xargs is implementation-defined for empty input. Since CI runs on Linux this is fine, but a comment noting the intent (or adding -r explicitly) would avoid future confusion.

  4. fmt target silently drops gofmt -s simplification. The old target ran gofmt -l -w -s; the -s flag applies source simplifications (e.g. s[a:len(s)]s[a:]). If llformat does not apply equivalent simplifications, this is a capability regression. The PR description doesn't mention this explicitly — worth verifying.


Linter Configuration

Positive:

  • The comment explaining why whitespace is disabled ("llformat now owns vertical whitespace...") is exactly the right level of documentation for a non-obvious decision. Future contributors will understand the trade-off without having to dig through history.
  • Keeping wsl_v5 disabled while dropping whitespace is consistent; wsl_v5 covers different rules than the blanket whitespace linter.

Concern:

  1. gofmt and goimports are still listed as enabled linters (lines 119–120 in the current .golangci.yml). After the baseline reformatting pass, these checks should still pass — but only because llformat's output is gofmt-compatible. It's worth calling out in the PR description (or a comment in .golangci.yml) that this compatibility is load-bearing: if a future llformat release diverges from gofmt, the CI lint job will catch it, but silently changing llformat options could break the build in a confusing way.

Bug Fix: Duplicate "sweep" in liquidity/parameters.go

This is a genuine correctness fix:

// Before (buggy):
"rules: %v, failure backoff: %v, sweep " +
"sweep conf target: %v, ..."
// → "... sweep sweep conf target: ..."

// After (correct):
"rules: %v, failure backoff: %v, sweep conf " +
"target: %v, ..."

The fix is correct. One minor nit: the format string still has ..., htlc conf target: %v,fees: %v, ... (missing space after the comma before fees). This was pre-existing and is not introduced by this PR, but since the string is being touched anyway, it would be a low-cost improvement to fix it here:

"target: %v, htlc conf target: %v, fees: %v, auto budget: %v, ..."
//                                 ^

Formatting Baseline (bulk of additions/deletions)

The formatting changes are machine-generated and look consistent with llformat's style. A few observations on the style choices worth confirming are intentional:

  • Multi-arg function calls are broken one-argument-per-line when they don't fit on one line. This is standard and correct.
  • Blank lines are added after early-return guards in some cases (e.g. DefaultTapdConfig). This matches common Go style for separating setup from the return.
  • Blank lines before early returns are removed in a few places (e.g. parameters.go validation). This is the reverse of the above — ensure llformat's rules are consistent here across the codebase.
  • The cloneParameters function sees its make(map[...], len(...)) call un-split to one line, while the default-params initializer has it split. These are different lengths, so the difference is justified by line-length rules.

Summary

Category Assessment
Correctness ✅ The duplicate-word bug fix is correct and well-scoped
Tooling ✅ Solid — minor dead-code and portability nits
Linter config ✅ Change is well-justified; gofmt compatibility dependency worth noting
Formatting baseline ✅ Machine-generated; no logic changes
Test coverage N/A — pure tooling/formatting PR
Security N/A

Suggested action items before merging:

  1. Remove or comment the now-unused GOIMPORTS_BIN / GOIMPORTS_PKG / $(GOIMPORTS_BIN) targets from the Makefile (or document why they're kept).
  2. Confirm llformat applies the gofmt -s simplifications, or document the delta.
  3. Fix the pre-existing missing space (, fees:) in liquidity/parameters.go while the string is already being touched.
  4. Consider adding -- to git diff invocations in scripts/llformat-files.sh.

@hieblmi hieblmi marked this pull request as ready for review May 5, 2026 13:06
@lightninglabs-deploy
Copy link
Copy Markdown

@hieblmi, remember to re-request review from reviewers when ready

Comment thread tools/go.mod Outdated
github.com/ashanbrown/forbidigo/v2 v2.3.0 // indirect
github.com/ashanbrown/makezero/v2 v2.1.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bhandras/llformat v0.0.0-20260505085734-44b3ea10b9bb // indirect
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've added a bunch of fixes, could you pls update to v0.1.1-beta and regenerate the baseline?

@hieblmi hieblmi force-pushed the codex/llformat-flow branch from 28fa32e to 9d589b4 Compare May 12, 2026 14:37
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented May 12, 2026

Addressed #1136 (comment). Updated/regenerated the branch with github.com/bhandras/llformat v0.1.1-beta, rebased it onto current upstream/master.

@hieblmi hieblmi force-pushed the codex/llformat-flow branch from 9d589b4 to c0f1972 Compare May 12, 2026 14:45
@hieblmi hieblmi requested a review from bhandras May 12, 2026 14:48
Comment thread assets/client.go
// assets daemon.
func DefaultTapdConfig() *TapdConfig {
defaultConf := tapcfg.DefaultConfig()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you pls regenerate this commit with only the baseline and then add the lint diff as a separate commit? This'd help with just mechanical validation that the diff is indeed created with llformat.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This now contains the lint-diff only.

@hieblmi hieblmi force-pushed the codex/llformat-flow branch from c0f1972 to c2998aa Compare May 12, 2026 18:11
@bhandras bhandras self-requested a review May 12, 2026 18:25
Copy link
Copy Markdown
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

Verified that the first commit and make fmt produces the second commit (apart from a small diff that is an llformat quirk we'll need to fix).

LGTM, thank you! 🎉

@hieblmi hieblmi requested a review from starius May 12, 2026 19:07
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.

4 participants