Skip to content

Commit a2ee235

Browse files
authored
Add prettier (#91)
1 parent 3093de1 commit a2ee235

5 files changed

Lines changed: 90 additions & 1 deletion

File tree

.githooks/pre-commit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Pre-commit hook to run lightweight checks and auto-format the code. It's designed
4+
# to be blazingly fast, so it checks only changed files. Run the following command
5+
# to install this hook for yourself. It's a symlink, to make sure it stays always
6+
# up-to-date.
7+
#
8+
# ```bash
9+
# ln -s ../../.githooks/pre-commit .git/hooks/pre-commit
10+
# ```
11+
12+
set -euxo pipefail
13+
14+
function command_exists() {
15+
bin_name=$(basename "$1")
16+
17+
if command -v "$1" &> /dev/null; then
18+
printf "\e[0;32m[INFO] Using %s...\e[0m\n" "$bin_name"
19+
return 0
20+
fi
21+
22+
printf "\e[0;33m[WARN] %s CLI was not found. Ignoring it...\e[0m\n" "$bin_name" >&2
23+
return 1
24+
}
25+
26+
files=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
27+
28+
if [[ -z "$files" ]]; then
29+
echo "No files changed. Exiting the pre-commit hook..."
30+
exit 0
31+
fi
32+
33+
if command_exists typos; then
34+
echo "$files" | xargs typos
35+
fi
36+
37+
if command_exists ./node_modules/.bin/prettier; then
38+
echo "$files" | xargs ./node_modules/.bin/prettier --ignore-unknown --write
39+
fi
40+
41+
# Add the modified/prettified files to staging
42+
echo "$files" | xargs git add
43+
44+
exit 0

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ jobs:
4646

4747
- run: terraform validate
4848
working-directory: ${{ matrix.project }}
49+
50+
prettier:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: actions/setup-node@v4
55+
with:
56+
node-version: "22"
57+
cache: "npm"
58+
- run: npm ci --ignore-scripts
59+
- run: npx prettier --check .

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ This repository contains necessary IaC code to deploy the resources of elastio s
66

77
Elastio terraform modules are published to the public Cloudsmith registry. In order to use them from that registry add this to your [`.terraformrc`](https://developer.hashicorp.com/terraform/cli/config/config-file), which should reside in your home directory (if you are on Linux):
88

9-
109
```hcl
1110
credentials "terraform.cloudsmith.io" {
1211
token = "elastio/public/"

package-lock.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scripts": {
3+
"fmt": "prettier --write ."
4+
},
5+
"devDependencies": {
6+
"prettier": "^3.5.3"
7+
}
8+
}

0 commit comments

Comments
 (0)