Skip to content

Commit d0d55fe

Browse files
Install pre-commit for repository
- Ensure we are formatting properly and consistently - Users can in principle choose to opt out of automatic hooks by not installing the tool in the repo - Simplicity of incluing linting into CI - For stability we run them initially in parallel to existing linting scripts - Scalability and futher development is simple as we can use existing solutions instead of implementing our own linting setup - For current solutions we add them directly to the pre-commit config to ensure stability & consistency
1 parent dcff0e3 commit d0d55fe

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,29 @@ jobs:
5757
with:
5858
bundler-cache: true
5959
- run: bin/bundle exec brakeman
60+
61+
lint:
62+
name: Lint
63+
runs-on: ubuntu-latest
64+
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: actions/setup-node@v4
68+
with:
69+
node-version-file: .tool-versions
70+
cache: yarn
71+
- uses: ruby/setup-ruby@v1
72+
with:
73+
bundler-cache: true
74+
- uses: hashicorp/setup-terraform@v3
75+
with:
76+
terraform_version: 1.10.5
77+
- uses: actions/setup-python@v5
78+
with:
79+
python-version: "3.13"
80+
- uses: terraform-linters/setup-tflint@v4
81+
- run: yarn install --immutable --immutable-cache --check-cache
82+
- name: Install pre-commit
83+
run: pip install pre-commit
84+
- name: Run pre-commit
85+
run: pre-commit run --all-files --hook-stage manual

.pre-commit-config.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
repos:
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.97.3
4+
hooks:
5+
- id: terraform_fmt
6+
files: \.(tf|tfvars|hcl)$
7+
- id: terraform_tflint
8+
stages: [manual]
9+
args:
10+
- --args=--config=__GIT_WORKING_DIR__/terraform/.tflint.hcl
11+
files: \.tf$
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v5.0.0
14+
hooks:
15+
- id: trailing-whitespace
16+
exclude: \.(enc|erb)$
17+
- id: end-of-file-fixer
18+
exclude: \.(enc|erb)$
19+
- id: check-json
20+
- id: check-added-large-files # Default is fail on files larger than 500kB
21+
- id: mixed-line-ending
22+
args: [--fix=lf] # Ensure all line endings are LF
23+
exclude: \.csv$
24+
- repo: local
25+
hooks:
26+
- id: prettier
27+
name: Prettier
28+
entry: |
29+
yarn prettier --check --ignore-unknown '**/*'
30+
language: system
31+
pass_filenames: false
32+
stages: [manual]
33+
- id: rubocop
34+
name: Rubocop
35+
entry: bin/bundle exec rubocop --autocorrect-all $*
36+
language: system
37+
files: ^app/
38+
types: [ruby]
39+
stages: [manual]
40+
- id: rufo
41+
name: Rufo
42+
entry: bin/bundle exec rufo --check app
43+
language: system
44+
pass_filenames: false
45+
stages: [manual]
46+
- id: brakeman
47+
name: Brakeman
48+
entry: bin/bundle exec brakeman --no-pager .
49+
language: system
50+
always_run: true
51+
pass_filenames: false
52+
stages: [manual]

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ aws-copilot 1.34.0
55
awscli 2.13.31
66
terraform 1.10.5
77
tflint 0.55.1
8+
python 3.13.2

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,34 @@ brew install libyaml
309309
# Dependencies for postgres
310310
brew install gcc readline zlib curl ossp-uuid icu4c pkg-config
311311

312+
# Install pre-commit tool
313+
brew install pre-commit
314+
312315
# Env vars for postgres
313316
export OPENSSL_PATH=$(brew --prefix openssl)
314317
export CMAKE_PREFIX_PATH=$(brew --prefix icu4c)
315318
export PATH="$OPENSSL_PATH/bin:$CMAKE_PREFIX_PATH/bin:$PATH"
316319
export LDFLAGS="-L$OPENSSL_PATH/lib $LDFLAGS"
317320
export CPPFLAGS="-I$OPENSSL_PATH/include $CPPFLAGS"
318321
export PKG_CONFIG_PATH="$CMAKE_PREFIX_PATH/lib/pkgconfig"
322+
```
323+
324+
For ubuntu run
325+
326+
```shell
327+
apt install curl libyaml-dev libreadline-dev zlib1g-dev \
328+
libssl-dev libicu-dev cmake pkg-config uuid-dev flex bison \
329+
pre-commit
330+
331+
export OPENSSL_PATH="/usr"
332+
export CMAKE_PREFIX_PATH="/usr"
333+
export PATH="$OPENSSL_PATH/bin:$CMAKE_PREFIX_PATH/bin:$PATH"
334+
export LDFLAGS="-L$OPENSSL_PATH/lib $LDFLAGS"
335+
export CPPFLAGS="-I$OPENSSL_PATH/include $CPPFLAGS"
336+
export PKG_CONFIG_PATH="$CMAKE_PREFIX_PATH/lib/pkgconfig"
337+
```
319338

339+
```shell
320340
# Version manager
321341
brew install mise
322342

@@ -329,6 +349,13 @@ Then to install the required tools (or update, following a change to
329349

330350
```shell
331351
mise install
352+
mise exec python -- pip install pre-commit
353+
```
354+
355+
Next ensure you have the pre-commit hook installed by running
356+
357+
```shell
358+
pre-commit install
332359
```
333360

334361
After installing Postgres via `mise`, run the database in the background, and

terraform/.tflint.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugin "terraform" {
2+
enabled = true
3+
}
4+
5+
plugin "aws" {
6+
enabled = true
7+
version = "0.37.0"
8+
source = "github.com/terraform-linters/tflint-ruleset-aws"
9+
}

0 commit comments

Comments
 (0)