JoshuaKGoldberg / JoshuaKGoldberg/create-typescript-app
🚀 Feature: Use Prettier when outputting files instead of JSON.stringify
- Dominant language
- TypeScript
- Stars
- 1.4k
- Forks
- 89
- Avg merge
- 1m
- Merged PRs (30d)
- 3
Description
### Feature Request Checklist
- [x] I have pulled the latest `main` branch of the repository.
- [x] I have [searched for related issues](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aissue) and found none that matched my issue.
### Overview
I'm finding it annoyingly difficult to read snapshots of generated `package.json` files:
https://github.com/JoshuaKGoldberg/create-typescript-app/blob/2396960cb7a23acc6a9952040f203a8543cc2266/src/blocks/blockPackageJson.test.ts#L53
It'd be nice to use [`@prettier/sync`](https://www.npmjs.com/package/@prettier/sync) when producing file creations. That way their test snapshots look human-readable.
They're formatted at runtime with Prettier anyway if the user doesn't disable `blockPrettier`. I've never seen a user disable that block. But it's theoretically possible.
### Additional Info
Previously filed as https://github.com/JoshuaKGoldberg/create-typescript-app/issues/2044. The problem with `JSON.stringify` is:
1. It adds `\n`s in many more cases than Prettier
2. Prettier will pick up on those cases and preserve them in its own formatting
3. As a result, some output files have unnecessary `\n`s that make them take more lines than needed
Contributor guide
Research direction
Start with src/blocks/blockPackageJson.test.ts, especially the snapshot around the linked lines, and trace how generated file contents currently use JSON.stringify. Review the @prettier/sync and blockPrettier context before running the relevant block tests. Done means generated package.json snapshots are human-readable without unnecessary newlines while existing formatting behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100