Skip to content

oxfmt: Support stdin and --stdin-filepath #14720

@KieranP

Description

@KieranP

Prettier supports stdin and has an option called --stdin-filepath that allows prettier to infer the file type. It then returns the formatted output to stdout, instead of writing the changes to the disk.

This is helpful for editors, where you can trigger the formatter command on an unsaved file, the editor will call prettier, passing the current unsaved file contents via stdin, provide the current filename to stdin-filepath, prettier then uses these to format accordingly, the formatted content is returned to stdout, and editor updates the unsaved file.

oxfmt currently does not support this, making it difficult to use in editors. If I have an unsaved file, and trigger oxfmt on the file path, it overwrites the file in disk, and the editors contents remain unchanged, forcing me to reload the file and lose any changes. Obviously not ideal.

An option to pass code via stdin and return the formatted code to stdout for the editor to them use would be helpful.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions