Skip to content

chore(lint): enable forcetypeassert in golangci-lint - #1821

Merged
SaidAltury-ibm merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:lint-wave8-forcetypeassert
Sep 14, 2026
Merged

SaidAltury-ibm merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:lint-wave8-forcetypeassert

Conversation

@mbrandenburger

@mbrandenburger mbrandenburger commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Enable the forcetypeassert linter, which flags unchecked type assertions (x.(T) without the , ok form).
  • Fix every flagged production-code site with a checked assertion: errors.Errorf for error-returning functions, panic(errors.Errorf(...)) for non-error-returning functions, restructured predicates for if v, ok := x.(T); ok && ... conditions, and collapsed a few redundant double-assertions into one.
  • Add a pkg/utils/proto.CloneOf helper and use it in platform/fabric/core/generic/discovery/client.go in place of proto.Clone(x).(*T) + assertion.
  • Exclude forcetypeassert for integration/, _test.go, _test_utils.go, and fake/ — hand-written test doubles and the integration harness aren't attacker-reachable, so an unchecked assertion there is a test bug at worst.

This is part of #1755

Test plan

  • go build ./...
  • golangci-lint run --enable-only forcetypeassert ./... — 0 issues
  • make checks across all 5 modules

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Hey @mbrandenburger 👋 thanks for the PR!
I'm your friendly PR Helper Bot 🤖 and I'll be riding shotgun on this one, keeping track of your PR's status to help you get it approved and merged.

This comment updates automatically as you push changes -- think of it as your PR's live scoreboard!
Here's the latest:


PR Checks

✅ DCO Sign-off -- All commits have valid sign-offs. Nice work!


❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:

  • 1441db3 lint: enable forcetypeassert and fix every flagged unchecked type assertion

You'll need to sign your commits with GPG (e.g. git commit -S). See the Signing Guide for a step-by-step walkthrough.


✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing!


❌ Issue Link -- This PR is not linked to any issue.

Please reference an issue using a closing keyword (e.g. Fixes #123) and ensure the issue is assigned to you. Every PR needs a home!


⏳ All checks must pass before this PR can be reviewed. You've got this!

@github-actions github-actions Bot added the status: needs revision The pull request requires changes from the author before it can be reviewed or merged label Sep 14, 2026
@mbrandenburger mbrandenburger added this to the 26Q3 milestone Sep 14, 2026

@SaidAltury-ibm SaidAltury-ibm 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.

thank you @mbrandenburger , LGTM

…ertion

Every production-code finding (100 across 33 packages when the linter was
enabled) is fixed with a checked assertion: an error return for functions
that already report errors, panic for the ones that don't, and either
propagated to satisfy loop or bool-predicate conditions. Test fixtures and
the nwo integration harness are excluded since a mismatch there is a test
bug, not a security concern.

Also uses proto.CloneOf, a new generic panic-safe clone helper, in place of
proto.Clone(x).(*T) where that pattern showed up among the fixes.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@SaidAltury-ibm
SaidAltury-ibm force-pushed the lint-wave8-forcetypeassert branch from 8616ac4 to 1441db3 Compare September 14, 2026 11:34
@mergify

mergify Bot commented Sep 14, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@SaidAltury-ibm
SaidAltury-ibm merged commit c92403c into hyperledger-labs:main Sep 14, 2026
45 checks passed
@mbrandenburger
mbrandenburger deleted the lint-wave8-forcetypeassert branch September 14, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs revision The pull request requires changes from the author before it can be reviewed or merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants