Skip to content

Bad behavior when running ormolu on a file and piping to that file itself #1181

@regr4

Description

@regr4

I can't have been the only one who (missing the -i flag on the help page) has tried ormolu FILE.hs > FILE.hs to format a file in place. However, when you do that, ormolu overwrites the file with nothing.

I'm not sure if it's possible to detect this situation, but if so, it would be nice to warn the user and somehow avoid destroying the contents (e.g. make a backup to /tmp/ or dump the original contents of the file to stderr).

To reproduce:

echo "module Example where" > Example.hs
ormolu Example.hs > Example.hs
cat Example.hs # empty

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions