Skip to content

fix: use grep -F for baseline lookup to handle Go pointer receivers#194

Merged
marcusburghardt merged 1 commit intocomplytime:mainfrom
marcusburghardt:fix/crapload-grep-pointer-receivers
Apr 16, 2026
Merged

fix: use grep -F for baseline lookup to handle Go pointer receivers#194
marcusburghardt merged 1 commit intocomplytime:mainfrom
marcusburghardt:fix/crapload-grep-pointer-receivers

Conversation

@marcusburghardt
Copy link
Copy Markdown
Contributor

Summary

Fixes a regex interpretation bug in the CRAPLoad baseline comparison that
causes all Go pointer receiver methods to be misclassified as "new functions."

Line 177 uses grep "^${key}<TAB>" to look up function keys in the baseline
TSV. Go pointer receiver methods have the format (*Type).Method, where (*
is a BRE (Basic Regular Expression) quantifier meaning "zero or more ("
rather than the literal characters (*. This causes the lookup to fail for
every pointer receiver function.

The fix switches grep to grep -F (fixed-string matching). The ^ anchor
is dropped because -F does not support anchors. Collisions are not possible
since keys are fully-qualified file.go:function paths, unique by construction.

Related Issues

Review Hints

  • Single-line change on line 177 of reusable_crapload_analysis.yml: grepgrep -F.

  • Evidence from complytime/complyctl PR #473:
    113 functions flagged as "new" = exactly 113 pointer receiver functions in
    the baseline. 251 functions matched correctly = all non-pointer-receiver
    functions.

  • Reproducible locally:

    # BRE fails on pointer receiver syntax
    key='pkg/foo.go:(*Type).Method'
    echo -e "${key}\t10\t0" | grep "^${key}	"    # NO MATCH
    echo -e "${key}\t10\t0" | grep -F "${key}	"   # MATCH

The baseline comparison uses grep with the function key as the pattern.
Go pointer receiver methods use (*Type).Method syntax, where (* is
interpreted as a BRE quantifier ("zero or more open-parens") instead
of the literal characters. This causes all pointer receiver functions
to fail lookup and be misclassified as "new functions", triggering
false CRAP threshold violations in consuming repositories.

Switching to grep -F (fixed-string mode) ensures literal matching.
The ^ anchor is dropped because -F does not support anchors, but
collisions are not possible since keys are fully-qualified
file:function paths unique by construction.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Copy link
Copy Markdown
Member

@hbraswelrh hbraswelrh left a comment

Choose a reason for hiding this comment

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

LGTM.

@marcusburghardt marcusburghardt merged commit b03120f into complytime:main Apr 16, 2026
13 checks passed
@marcusburghardt marcusburghardt deleted the fix/crapload-grep-pointer-receivers branch April 16, 2026 12:29
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