Skip to content

Commit ae4a77b

Browse files
Add sentinel fmt hook (gruntwork-io#89)
1 parent eee43be commit ae4a77b

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@
110110
entry: ./hooks/check_skip_env.py
111111
language: script
112112
files: \.go$
113+
114+
- id: sentinel-fmt
115+
name: Sentinel fmt
116+
description: Rewrites all Sentinel configuration files to a canonical format
117+
entry: hooks/sentinel-fmt.sh
118+
language: script
119+
files: \.sentinel$
120+
require_serial: true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ supported hooks are:
1818
* **helmlint** Automatically run [`helm lint`](https://helm.sh/docs/helm/helm_lint/) on your Helm chart files. [See caveats here](#helm-lint-caveats).
1919
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on
2020
markdown doc files.
21+
* **sentinel-fmt**: Automatically run `sentinel fmt` on all Sentinel code (`*.sentinel.*` files).
22+
2123

2224

2325

hooks/sentinel-fmt.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
#!/usr/bin/env bash
3+
4+
set -e
5+
6+
# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
7+
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
8+
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
9+
original_path=$PATH
10+
export PATH=$PATH:/usr/local/bin
11+
12+
# Store and return last failure from fmt so this can validate every directory passed before exiting
13+
FMT_ERROR=0
14+
15+
for file in "$@"; do
16+
sentinel fmt -diff -check "$file" || FMT_ERROR=$?
17+
done
18+
19+
# reset path to the original value
20+
export PATH=$original_path
21+
22+
exit ${FMT_ERROR}

0 commit comments

Comments
 (0)