Open Janiczek opened 8 years ago
I think giving an error is the right thing. If a developer or a script is running elm-format then I think it's safe to assume that they expect at least one elm file to be formatted.
Well, the git pre-commit hook is one usecase where you'd want to "format all elm files that you can find" - even if that's zero of them.
Of course, I can change the hook to see if any elm files are there and exit early if there are none. But still, it makes sense to me for elm-format to exit peacefully when there's nothing to do and the command is not invalid.
This is a pre-commit hook that you copy into all your new projects by default?
This is the first time I've used it. But it seems very convenient for Elm projects :)
Nice @Janiczek, I'll borrow your script to use it in my toy project if you don't mind.
I agree giving an error sounds like a good idea.
A bit of motivation: I have a git hook formatting every .elm file before commiting it. As long as there are .elm files it works. But when there's no .elm file, then I get this error:
It's intended, the error message is correct, it's tested, etc. I'm just asking: should it be that way? Shouldn't
elm-format
just exit peacefully when there's nothing to do? (In the directory case. I'm not so sure about file/STDIN case.)The hook: (
.git/hooks/pre-commit
)