Skip to content

Add a flag for overriding the filename of files passed through stdin #263

@pluiedev

Description

@pluiedev

Description

Tools that automatically format files (e.g. Neovim, Jujutsu with jj fix, etc.) often work by calling a formatter like Nixfmt by passing a file's contents to stdin and then getting the formatted result via stdout, which has the benefit that the caller would have complete control over the original file, instead of having the formatter potentially overwriting it.

However, a drawback is that when there is a formatting error, all context around the filename is lost, which could be frustrating when dozens of files are involved:

$ jj fix
<stdin>:71:3:
   |
71 |   '';
   |   ^
unexpected '''
expecting expression

Some other formatters like clang-format allow the user to supply the actual filename via an CLI option (e.g. --assume-filename) while still accepting input via stdin, and I think it would be great if Nixfmt would have something similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions