Skip to content

Meta: Switch from Prettier to dprint for formatting #7372

Closed as not planned
Closed as not planned

Description

@g-plane

Are there any considerations about switching the formatter from Prettier to dprint? dprint is a plugins-based formatter, and it's written in Rust so it's fast.

But speed and performance isn't the most important factor, dprint is highly configurable while Prettier is opinionated. So, code styles can be easily customized to get satisfication.

The reason why I recommend dprint is that I've noticed you opened an issue about the bug of formatting CSS selectors with comments in Prettier: prettier/prettier#15356 . dprint doesn't have official plugins for formatting CSS at this moment, but here is a third-party one: Malva.

Malva is also highly configurable and customizable, and it provides more options than Prettier. Also, it works with comments better than Prettier. For the bug you caught in Prettier, Malva works well: Malva playground. Malva also fixes some other bugs in Prettier, such as prettier/prettier#16232 (comment) .

Feedback is welcomed.

Activity

  1. Jayllyz commented on May 23, 2024

    @Jayllyz

    Biome could replace both prettier and eslint 👀 (+ some stylelint rules soon)

  2. fregante commented on May 23, 2024

    @fregante
    Member

    Thank you but prettier is good enough for now.

    Biome doesn't have compatibility with eslint plugins, which we have a lot of.

  3. fregante commented on Jul 16, 2024

    @fregante
    Member

    I gave it a try in 6210d1e but I think it's a downgrade in a few spots, especially with comments being wrapped to the next line, or moved before the selector. :is() and :has() are particularly troublesome as they're just one-lined. Quotes are also broken I think:

    Screenshot 5

    This was done for #7553

  4. g-plane commented on Jul 16, 2024

    @g-plane
    ContributorAuthor

    Quotes can be configured.

  5. fregante commented on Jul 26, 2024

    @fregante
    Member

    Would you be open to send a PR? Last week I had two issues:

    • :has(), :is() wrapping
    • comments position

    If the first one can be fixed to maintain what we expect, we can probably figure something out with the comments positioning. Biome actually moved some comments before the comma and that made sense, for example.

    - a, /* comment */
    + a /* comment */,
    b {
    
    }

    But in the last dprint PR, the formatting in this case was changed to this instead, which isn't what we expect:

    a,
    /* comment */ b {
    
    }
  6. fregante commented on Jul 26, 2024

    @fregante
    Member

    We're only using Prettier for CSS and GQL for now. I think GQL would still need Prettier because I don't see it (via dprint plugin)

    https://dprint.dev/plugins/

  7. g-plane commented on Jul 26, 2024

    @g-plane
    ContributorAuthor
    • Can you give me some examples about :has() and :is()? (expected results)
    • Recently I'm fixing comments problems.
    • dprint has a Biome plugin and Biome supports GraphQL, so we can format GraphQL indirectly.
    • dprint also has a Prettier plugin. If you don't like Biome, you can still use Prettier to format GraphQL. Compared to using Prettier directly, running Prettier in dprint will be faster because files will be formatted in parallel.
  8. fregante commented on Jul 27, 2024

    @fregante
    Member
    • the expected result is what we have now, more or less. The wrong result is when multiple long selectors are on a single line inside is(), as shown in my screenshot a few comments back
    • yes GQL would need to use biome or prettier, I had also set biome for GQL without issues in my PR. Prettier would be preferred since it's part of our dependencies anyway (via XO)
  9. g-plane commented on Jul 27, 2024

    @g-plane
    ContributorAuthor

    Just enable "linebreakInPseudoParens" option, and the result of :is() and :where() can be better. playground

  10. g-plane commented on Aug 1, 2024

    @g-plane
    ContributorAuthor

    Malva v0.6.0 has been published with many comments improvements. Would you like to try it again? Don't forget to configure Malva as the dprint.json example below:

    {
      "malva": {
        "quotes": "preferSingle",
        "blockSelectorLinebreak": "always",
        "linebreakInPseudoParens": true
      }
    }
  11. eveeifyeve commented on Aug 7, 2024

    @eveeifyeve
    • Can you give me some examples about :has() and :is()? (expected results)
    • Recently I'm fixing comments problems.
    • dprint has a Biome plugin and Biome supports GraphQL, so we can format GraphQL indirectly.
    • dprint also has a Prettier plugin. If you don't like Biome, you can still use Prettier to format GraphQL. Compared to using Prettier directly, running Prettier in dprint will be faster because files will be formatted in parallel.

    I had a look at this comment unfortunatly it seems like graph ql formatter is unreleased for biome so dprint can't support as it's not released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions