Skip to content

autoformatting using a prettier plugin #667

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-termzzz)
  • 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!

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