Grep like an LLM · part 4 of 6
Follow the data
On this page
When the question is about the data, asking what something is, why it has the wrong value, or where it comes from, the logic is the long way round. The data itself leaves a shorter trail.
Read the types first
The schema is the smallest document in the codebase that explains what a feature actually is:
$ git grep -n 'model Flavour' -- '*.prisma'
packages/van-db/schema.prisma:12:model Flavour {-n adds the line number, and the -- '*.prisma' part limits the search
to schema files, so the hit tells you exactly where to look: line 12. Twenty lines of types will tell you what
a flavour is, with its fields, its relations and what's optional, faster than
two hundred lines of service code that merely use it.
The word, not every substring
A short search term drags in every longer word that contains it:
$ git grep -ci 'van' apps/sundae.shop/components/flavour-card.tsx:9 repositories/FlavourRepository.ts:6 services/jingle/JingleService.ts:2 $ git grep -ciw 'van' services/jingle/JingleService.ts:2
-c counts the matches per file and -i ignores case, the same map as
before. Those first counts are nearly all vanilla. Adding -w matches
whole words only, meaning van stops matching vanilla, and the map
shows the actual van. When a search floods with noise, check whether your term is
hiding inside longer words before reaching for anything cleverer.
Find who writes it
A value might be read in ten places, but it's usually written in one or two, and the write is where its story starts:
$ git grep -n 'soldOutAt =' services/stock/StockService.ts:42: flavour.soldOutAt = now;
Searching for the assignment, the field name followed by =, skips
every read and lands on the source. When something has the wrong value,
start from the write site and work forwards, rather than from the symptom
and backwards.
At your desk
The next time a field holds a value you don't understand, run two searches before stepping through anything: the type definition, then the assignment. Most of the time the answer is in one of those two places.