Skip to content

refactor: improve code readability by removing unnecessary parentheses - #5684

Open
akrem-chabchoub wants to merge 1 commit into
masterfrom
fix/format
Open

akrem-chabchoub wants to merge 1 commit into
masterfrom
fix/format

Conversation

@akrem-chabchoub

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have added or updated fuzz targets for any code handling untrusted input.
  • I have filled out the description and linked the related issues.

Description

Problem

Running make format changed ~60 files, mostly by shuffling imports. Two reasons:

  1. Broken gci command. The Makefile used $(go list -m), which Make treats as an (empty) Make variable, not a shell command. So gci got -local <first file path> instead of the module name. It treated our own github.com/ethersphere/bee/v2 imports as third-party and merged them with everything else.
  2. Unpinned tools. gofumpt@latest meant every developer could get a different version and different output.

Changes

Makefile

  • make format now runs only gofumpt. It no longer reorders imports.
  • New optional make format-imports target, with a corrected gci command (gci write -s standard -s default -s "prefix(<module>)").
  • Pinned versions: GOFUMPT_VERSION ?= v0.11.0, GCI_VERSION ?= v0.14.0.
  • install-formatters now uses go install instead of go get, so it no longer modifies go.mod.

Docs

  • AGENTS.md and CODINGSTYLE.md now describe the new make format / make format-imports behavior.

Code (output of make format, 13 files)

  • Removed redundant parentheses, e.g. if (len(args)) != 1 → if len(args) != 1, *(headers.LookaheadBufferSize) → *headers.LookaheadBufferSize, &(pruneImpl) → &pruneImpl.
  • Minor gofumpt tidy-ups: var x = … → x := … (safe_test.go), a stray blank line (status_test.go), blank lines between one-line funcs (snapshot_test.go).

No behavior changes. All edits are formatting only.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

@akrem-chabchoub akrem-chabchoub self-assigned this Nov 4, 2026
@akrem-chabchoub akrem-chabchoub added this to the 2026 milestone Nov 4, 2026
@akrem-chabchoub akrem-chabchoub changed the title chore: update formatting commands and dependencies in Makefile and documentation chore: update formatting commands and dependencies in Makefile Nov 4, 2026
@akrem-chabchoub

Copy link
Copy Markdown
Contributor Author

Not sure if we need to run make format-imports, that wil generate +300 file changes for just imports re-ordering !

@akrem-chabchoub akrem-chabchoub changed the title chore: update formatting commands and dependencies in Makefile refactor: improve code readability by removing unnecessary parentheses Nov 4, 2026
@sbackend123

Copy link
Copy Markdown
Contributor

make format runs gofumpt on *.pb.go and splits their imports into two groups. make protobuf regenerates them as one group, so the two targets keep rewriting the same imports. format-imports already skips *.pb.go; gofumpt should too.

@akrem-chabchoub

Copy link
Copy Markdown
Contributor Author

make format runs gofumpt on *.pb.go and splits their imports into two groups. make protobuf regenerates them as one group, so the two targets keep rewriting the same imports. format-imports already skips *.pb.go; gofumpt should too.

@sbackend123 Not sure I understood correctly. *.pb.go files have the // Code generated … DO NOT EDIT. header, and gofumpt skips those when it formats a folder (it only touches them if you pass the file directly). When I run make format on this branch, no .pb.go files change.

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.

3 participants