prettier / prettier/prettier

Introduce `Prettier` class

Open
#10,155 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:needs discussion type:refactor
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Motivation:

Currently we save everything, include .originalText, .tokens in options, and pass through all functions.

Idea:

Add Prettier class,

  • Prettier#constructor(text, options):
    Save all original input, strip BOM, strip hashbang, strip frontMatter, etc

  • Prettier#parse():
    get a ParseResult, not only ast, but also text(different with originalText, the text actually pass to parser),comments, tokens, parseService, traverse, visitorKeys etc, and save to Prettier instance.

  • Prettier#attachComments():
    get AttachedComments, with attach information, stop saving to AST.

  • Prettier#format():
    async version of Prettier#formatSync(), replaces Prettier#formatSync() when we are ready to turn everything into async.

  • Prettier#formatSync():
    same as current prettier.formatWithCursor, we may consider split it into two steps ast-to-doc, doc-to-text.


Just some basic idea, maybe we can also have Language class

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the current prettier.formatWithCursor flow and how originalText, tokens, and options pass through the parsing and formatting functions. Review the proposed Prettier lifecycle and ParseResult contents, then clarify the design and confirm that the completed work preserves parsing metadata, comment attachment, and sync/async formatting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.