-
Notifications
You must be signed in to change notification settings - Fork 46
Add a Stdin Specification #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This completes step 1 of numtide#573 (comment).
|
||
When in stdin mode, the formatter: | ||
|
||
1. **MUST** print the formatted file to stdout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lie: it's OK for the formatter to fail to format, but it probably should (must?):
- Print an explanation why to stderr
- Exit non-zero
This made me realize the current formatter specification doesn't have anything to say about subprocess exit codes, but treefmt does check the exit code of the formatter it invokes. We should probably mention this in the spec?
@@ -60,3 +60,54 @@ outputs. | |||
### 4. Reliable | |||
|
|||
We expect the formatter to be reliable and not break the semantics of the formatted files. | |||
|
|||
## Stdin Specification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I actually promote this to a top level file? That is, docs/site/reference/stdin-spec.md
?
Example: | ||
|
||
``` | ||
$ echo "{}" | nixfmt --stdin path/to/file.nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bad example, as nixfmt doesn't actually behave this way yet.
Do folks know if there's an existing formatter (besides treefmt itself) that implements this spec?
@brianmcgee @zimbatm, is there anything I can do to help move this forward? |
It's unclear to me if this documents the current behaviour or the desired behaviour. If it's the desired behaviour, isn't there some work needing to be done in |
Yes, treefmt needs changes to support this. I'm happy to implement that (in this PR or a separate one). I just don't want to put in the effort until I know we like this approach. |
I'll try to put my brain on this in the next few days. Been a busy few weeks 😫 |
This completes step 1 of
#573 (comment).