Skip to content

🚀 Feature: Use Prettier when outputting files instead of JSON.stringify #2058

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Feature Request Checklist

Overview

I'm finding it annoyingly difficult to read snapshots of generated package.json files:

"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","main":"lib/index.js","files":["README.md","package.json"]}",

It'd be nice to use @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 #2044. The problem with JSON.stringify is:

  1. It adds \ns 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 \ns that make them take more lines than needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsPlease, send a pull request to resolve this!type: featureNew enhancement or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions