cljfmt icon indicating copy to clipboard operation
cljfmt copied to clipboard

Feature request: a mode to read from stdin

Open or opened this issue 3 years ago • 3 comments
trafficstars

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.

or avatar May 02 '22 14:05 or

Let's use -, as it's the usual convention.

weavejester avatar May 08 '22 23:05 weavejester

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.

or avatar May 09 '22 08:05 or

I think it's fine to raise an error saying that STDIN and files cannot be processed at the same time.

weavejester avatar May 09 '22 13:05 weavejester