- Codebase analysis: find patterns, prop usages, component instances
- Migration tracking: record what your codemod rewrote, grouped by the shape of the change
- Read-only codemods: gather insights without modifying code
When to return data
For standalone JSSG tests, the data is snapshotted in
data.json next to the fixtures (see Testing).
Basic usage
Return{ edit, data } instead of a string:
edit: the new file content, ornull/missing to leave the file unchanged. Returning a plain string ornullstill works.data: any JSON value, includingnull. To skip a file’s data, leavedataout or set it toundefined.- Data that isn’t JSON (a function, a
BigInt) is an error, and so are other keys on the result, so a typo doesn’t go unnoticed.
In a workflow
Inworkflow.ts, per-file logic is a forEachFile callback, and what it returns is collected into the step’s outputs, in path order, leaving out files that returned nothing:
{ edit, data } is what codemod jssg run and codemod jssg test report, and what workflow.yaml’s js-ast-grep steps collect into their outputs.
Testing
codemod jssg test snapshots the data next to input and expected as data.json, in the same [{ file, data }] shape. A missing data.json is written on the first run; --update-snapshots rewrites a changed one.
In Codemod 2.0,
useMetricAtom from codemod/metrics and the CLI’s metric totals were removed. Return what you counted and add it up in the workflow.