No error on formatting a directory with no Elm files
- Dominant language
- Haskell
- Stars
- 1.3k
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
_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:
> Could not find any .elm files on the specified paths:
> /var/www/html/elm/projector
> Please check the given paths.
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`)
``` sh
#!/bin/sh
#
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# create a temporary file for the errors
TMP="$(mktemp)"
# find the absolute path to the repository
ROOT="$(git rev-parse --show-toplevel)"
# try to format the whole directory
elm-format --yes "$ROOT" >"$TMP" 2>/dev/null || {
echo '[PRE-COMMIT HOOK] elm-format failed:'
cat "$TMP"
rm -f "$TMP"
exit 1
}
# delete the temporary errors file
rm -f "$TMP"
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the shown `elm-format --yes` command against an empty directory and compare its exit status with a directory containing `.elm` files. Done means the directory case exits successfully when there is nothing to format, while the issue's file and STDIN cases retain their current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, shell
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100