Skip to content

autoformatting using a prettier plugin #667

Open

Description

@wbolster

hi 👋🏼,

it would be great if there was an officially supported way to do autoformatting, preferably as a prettier plugin (see below for rationale).

while this is technically possible as a 3rd party package, that's not ideal (see below). if the current maintainers (hi @eemeli 👋🏼 i guess?) of this project are receptive to the idea (hence this issue), i may work on a pull request to this repo to add a @fluent/prettier-plugin package.

(fwiw, i locally have some hacky proof of concept code to convince myself that the things described below are actually feasible without too much maintenance effort.)

what i would love to see:

  • part of the projectfluent/fluent.js set of JS libraries
  • based on @fluent/syntax, which can parse + serialize, which solves all .ftl syntax technicalities
  • sensible defaults, no configuration
  • based on prettier
    • widely used
    • straight-forward implementation b/c of the plugin system and healthy ecosystem around it
    • many tools integrate with it
    • automatic support for fluent-vue b/c the prettier support for .vue files, which can contain js, html, and css… and <fluent> ftl blocks 😎, can also format embedded languages using any installed prettier plugin
  • strict parsing; invalid syntax causes errors. (prettier has similar behaviour for invalid javascript syntax, for example)
  • entries of type Message and Term sort alphabetically, with terms simply sorting between messages (e.g. example → -some-term → zzz)
  • fluent comments bound to messages stay bound to messages, and stand-alone comments stay in place, effectively becoming group delimiters for sortable blocks in the .ftl file.

prior art:

thoughts welcome!

Activity

  1. eemeli commented on Jun 7, 2026

    @eemeli
    Member

    Having good Prettier support for Fluent would be great, but having multiple such also sounds a bit concerning -- especially if/as they are liable to end up disagreeing on some parts of the formatting.

    Would you and @luca-iachini be amenable on collaborating on a "canonical" plugin for Fluent? Especially with multiple maintainers I'd be happier to let it get published under the @fluent npm org.

  2. wbolster commented on Jun 7, 2026

    @wbolster
    Author

    the good news is that @fluent/syntax (part of this project) has built-in .serialize() and it handles formatting already (see source), including whitespace normalisation and comments spacing. that should settle 99% of the ‘what is the ideal format?’ debate.

    (the formatting code in luca-iachini/prettier-plugin-fluent seems wholly redundant, unless it is specifically aiming for a different formatting style, but in in the fluent.js project the @fluent/syntax serialization is obviously the correct formatting, by definition.)

    as i see it, the only ‘debatable’ questions are:

    1. should entries be sorted?

      • my opinion: yes, always, deterministic output is good. also good for producing small diffs and reducing merge conflicts.
    2. how should messages (message) and terms (-term) be sorted?

      • my opinion: terms simply sorting between messages (e.g. example → -some-term → zzz). (again, @fluent/syntax makes this trivial b/c it has Identifier.name for this already)

    here are some examples. note that apart from sorting, this is just a @fluent/syntax showcase:

    examples

    simple messages and placeables:

    example = This is an example.
    welcome = Welcome, { $name }, to { -brand-name }!

    multiline message (based on the fluent guide):

    multi =
        Text can also span multiple lines as long as
        each new line is indented by at least one space.
        Because all lines in this message are indented
        by the same amount, all indentation will be
        removed from the final value.
    with-indents =
        Indentation common to all indented lines is removed
        from the final text value.
          This line has 2 spaces in front of it.

    sorting:

    bar = Bar
    -example-term = Example term
    foo = Foo

    variants and attributes:

    message-count =
        { $count ->
            [one] { $count } message
           *[other] { $count } messages
        }
    user =
        .label = Example label
        .placeholder = hello, { $name }
  3. added 3 commits that reference this issue on Jun 8, 2026
    3edce9c
    7d72bd6
    52b705a
  4. wbolster commented on Jun 9, 2026

    @wbolster
    Author

    quoting @eemeli in #668:

    Let's hold off on jumping to a solution right away -- it's only been a few days since the discussion on this even started. As I mention in #667 (comment), we should work towards having just one Prettier plugin for Fluent.

    One additional reason I'd prefer to have @luca-iachini on board with the work here is to ensure that any new code we might add to this repo will also be maintained, and that's always easier with multiple maintainers.

    as i see it, a fluent prettier plugin is a very small and rather simple (sub)project.

    just trying to get this sorted once and for all. i hope that @luca-iachini @timstallmann @slbls can all agree that it would be nice to have this as part of fluent.js proper. i understand y'all being busy, so if any of you read this, maybe just type ‘go ahead’ and enjoy your day 😌.

    i've been involved in i18n/l10n since decades already (gnome). i already contributed to the fluent ecosystem (and tons of other OSS), e.g. improving fluent-vue docs fluent-vue/docs#8 and fluent-vue/docs#9, and getting an upstream prettier plugin is just another contribution from my side.

    in the end this is just a handful lines of glue code: prettier plugin api is 20 lines of filling in the template, the actual formatting is literally two statements thanks to the @fluent/syntax parsing and serialization api (yay), and sorting the messages another 20. all of all very boring and straight-forward, a good thing!

    the actual work is the rather dreadful stuff around it: build infra, testing, packaging, docs, etc. the prior art (see below) is lacking here b/c it is thankless boring work that tends to quickly evaporate b/c of various things like ecosystem, ci, package registry, etc. getting outdated. the existing packages are clearly not passion projects but quick hacks to address the need for autoformatting.

    that's why i believe the fluent.js is the right home for it. shoulders of giants and so on 🙃.

    prior art 1: desmosinc

    prior art 2: luca-iachini

  5. timstallmann commented on Jun 9, 2026

    @timstallmann

    Integrating this into fluent.js proper seems great! We would be very happy to no longer rely on a (very basic) plugin created primarily for internal use

  6. wbolster commented on Jun 29, 2026

    @wbolster
    Author

    hey @eemeli 👋🏼, earlier you seemed a bit worried that i was going a bit too fast when i opened this @fluent/prettier-plugin pull request.

    it's been 3 weeks now, and i'd really like this to move ahead.

    regarding the existing two projects, both of which are not actively maintained (see my earlier message):

    • @timstallmann (maintainer of the demosinc prior art) likes the idea

    • no word from @luca-iachini, unfortunately. apart from pinging here on github, i also reached out over private email; full messages below for transparency.

    so, what do you think of getting #668 in? i'd say it's in a good shape, definitely not a proof of concept but fully integrated into this project's build infra, docs, tooling, etc.

    of course i can help out with maintenance, though the actual amount of code is just a few lines of gluing together two pretty stable APIs (prettier plugin and fluent-syntax)

    thanks for your consideration!

    my first email message to @luca-iachini, sent 2026-06-09

    hi Luca 👋🏼,

    i found your mail address in the git log of your prettier-plugin-repo at https://github.com/luca-iachini/prettier-plugin-fluent. hope you don't mind me mailing you directly.

    i'm trying to get the official fluent.js to include a prettier plugin. i hope you agree that would be the best place for it! would save everyone effort and unnecessary npm package maintenance pain 😅

    details here:

    it would be great if you could reply there and say this is a good idea, because one of the fluent.js maintainer seems to be a bit relucant b/c you also published a plugin for this.

    thanks in advance! ciao!

    – wouter

    follow-up email message to @luca-iachini, sent 2026-06-18

    hey!

    it would be great to get your thumbs up on having an upstream fluent prettier plugin. see my earlier message below.

    a simple ‘good idea’ in the github comment would be enough!

    thanks!

    cheers, wouter

  7. NoahTheDuke commented on Jun 29, 2026

    @NoahTheDuke

    i wrote a dead simple formatter for my Clojure library fluent-clj which wraps fluent.js. i am very interested in an official standard format, regardless of the delivery method (plugin or function or whatever), so users of my library can match the rest of the ecosystem.

  8. wbolster commented on Jun 29, 2026

    @wbolster
    Author

    interested in an official standard format, regardless of the delivery method (plugin or function or whatever), so users of my library can match the rest of the ecosystem.

    good news, @NoahTheDuke: that exists already in @fluent/syntax which can both parse and serialize with deterministic formatting, and the prettier plugin in #668 does exactly that.

    (sorting is the only opinionated extra behaviour. see rationale in comment above for my opinion on sorting.)

  9. wbolster commented on Jul 15, 2026

    @wbolster
    Author

    gentle ping @eemeli 👋🏼. can i help move this forward somehow?

  10. added a commit that references this issue on Jul 24, 2026
    c63abf2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions