Skip to content

refactor: extract shared calleeObject helper in lint cops#3396

Merged
dgageot merged 1 commit into
docker:mainfrom
dgageot:worktree-board-3ba911ae6bd2a5ea
Jul 2, 2026
Merged

refactor: extract shared calleeObject helper in lint cops#3396
dgageot merged 1 commit into
docker:mainfrom
dgageot:worktree-board-3ba911ae6bd2a5ea

Conversation

@dgageot

@dgageot dgageot commented Jul 1, 2026

Copy link
Copy Markdown
Member

Both constructor_command_exec.go and constructor_network_io.go contained nearly identical type-switch blocks to extract the callee object from a call expression — handling both bare *ast.Ident and selector-expression *ast.SelectorExpr cases, then resolving the corresponding types.Object from type info. The duplication made each cop harder to read and meant any future fix had to be applied twice.

This change extracts that logic into a single calleeObject helper in constructor_command_exec.go and updates constructor_network_io.go to call it, removing around 20 lines of duplicated branching with no change in behaviour.

No breaking changes. Both cops produce identical diagnostics before and after.

Deduplicate callee-object resolution between ConstructorCommandExec and
ConstructorNetworkIO by pulling the switch into a single calleeObject helper.

Assisted-By: docker/docker-agent
@dgageot dgageot requested a review from a team as a code owner July 1, 2026 22:25

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

This refactoring correctly extracts the duplicated callee-resolution type-switch into a single calleeObject helper. The behaviour is identical to the original code in both callers:

  • Nil-safety preserved: calleeObject guards info == nil exactly as the old if p.Info != nil blocks did. Both osExecFuncName and networkIOFuncName use the safe comma-ok type assertion (obj.(*types.Func)), so passing nil is well-defined and returns the zero/false pair — no panic risk.
  • Map-lookup semantics unchanged: info.Uses[fun.Sel] and info.Uses[fun] return nil (the zero value for the types.Object interface) on a missing key, which both downstream functions already handle correctly.
  • Fallthrough paths intact: The cop.CallTo fallback in commandConstructorCall and the two cop.CallTo checks in networkIOCall are untouched and still reachable.
  • Type-switch coverage identical: The helper covers exactly the same *ast.SelectorExpr and *ast.Ident cases as the original inline blocks, with an explicit default: return nil that is semantically equivalent to not entering the switch.

@aheritier aheritier added area/ci CI/CD workflows and pipeline kind/refactor PR refactors code without behavior change labels Jul 1, 2026
@dgageot dgageot merged commit 3ad35c7 into docker:main Jul 2, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci CI/CD workflows and pipeline kind/refactor PR refactors code without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants