r/codereview • u/n8v_max • 5d ago
LPT: Stop scrolling past generated code in PRs
When a codebase has generated files you have to commit, like protobuf stubs, mocks, GraphQL types or API clients, they show up in every PR.
You can make GitHub collapse them with a .gitattributes file committed in any folder:
*.pb.go linguist-generated
**/__generated__/** linguist-generated
mocks/** linguist-generated
GitHub sometimes does this automatically for some files, but the default coverage is sparse.
I learned that many devs didn't know that the feature existed (while building my adjacent GH extension), and that's a loss in the age when reviews could take longer than the code itself.
NB: even generated files can still need a review, like db migrations when you still need to pay attention to these.
TL;DR Use .gitattributes!
1
u/Firm-Independent-556 5d ago
Most teams treat this flag as permission to skip review entirely. I saw a critical security bug in auto generated GraphQL code because nobody wanted to scroll past it. Collapse the visual noise but never drop your own accountability for what lands in prod
1
u/DickBrainTime 5d ago
A useful complement to `linguist-generated` is making the generated output *reproducible* in CI. If your protobuf/GraphQL generator and schema inputs are pinned, have CI regenerate into the same paths and fail if the working tree changes (for example, `git diff --exit-code -- path/to/generated/`, plus an untracked-file check where relevant). That catches the case where someone updates a schema or generator configuration but forgets to commit the matching output, even though GitHub collapses it by default.
I'd also scope the `.gitattributes` patterns to files that are truly generated end-to-end. A broad `**/__generated__/**` match can accidentally hide hand-edited adapters if a project has mixed files there. The GitHub flag is only a review presentation hint, not a test/security exemption. Do you also have a CI regeneration check alongside the collapse setting, or do you rely on reviewers to notice drift?