Open lassik opened 5 years ago
I re-read the above and it seems like a brittle solution to infer anything based on the current directory when --stdin
is used. Seems quite likely that the cwd will be arbitrary and the programmer didn't think of changing into any particular directory before calling elm-format
. A --stdin-filepath
option would be much more robust.
(Continued from #561)
What to do in case of
--stdin
is a good question.Editor plugins are easiest to implement using
--stdin
for multiple reasons. The main one is that people often format code in the editor before saving the file, in which case the file contents would not up be to date. In Emacs, I launch theelm-format
subprocess so that its current directory (cwd) is the directory where the formatted.elm
file resides, so looking upelm.json
/elm-package.json
based on the cwd would work fine. Not sure what is done by other editor plugins.The best alternative might be to have a command line flag like this (copy-pasted from here):
If
--stdin
is given, you could have an error message like this:As a final twist in the tale, people should be able to format code in temp buffers that don't have a filename associated with them. In that case I don't think there is anything sensible that can be done apart from requiring a manual
--elm-version
flag along with--stdin
. The concept of a current directory is dubious for a temp buffer.