cljfmt
cljfmt copied to clipboard
Feature request: a mode to read from stdin
For editor integration it would be useful to have a mode that reads from stdin, formats, and writes to stdout.
I think a separate command, say pipe, would be ideal. E.g. cljfmt pipe < foo.clj
Alternatively this could be accomplished by accepting - as an input to fix or check, but that might not play well with having multiple path arguments. The advantage would be that it can check stdin, but I personally wouldn't use that, and since the output probably isn't useful for linting this might not be an important use case.
Let's use -, as it's the usual convention.
I've written a draft of that, but it cuts quite deeply into the way path arguments are processed. Also, the reporting for fix with multiple arguments must not write to stdout if there's an stdin argument, because that's where the fixed stdin data will go. Errors still need to be written to stderr. Both of these are done with print-file-status, which muddies the water a bit.
Before I go too deep on trying to work around these issues: it seems like multiple files mixed with - for stdin would be a strange use case. What do you think about only accepting - on its own for stdin processing? i.e. cljfmt check - and cljfmt fix -, and more file arguments would result in an error.
I think that keeps things tidy and simple.
I think it's fine to raise an error saying that STDIN and files cannot be processed at the same time.