Skip to content

Commit 9370d08

Browse files
authored
Use hk to run linters (#3412)
This updates our linting set up to use `hk` as the tool runner for our various linters. `hk` is a new tool that is designed to run commands as part of a Git commit, and through that it can be used to run linting tools. It's a proposed alternative to `pre-commit` with some specific goals around running linters in parallel and being highly performant. This is proposed as an alternative to #3001 to avoid the need to add Python to our project, specifically `hk` is provided as a binary and can be included in `.tool-versions` installed by Mise. On the other hand, compared to `pre-commit`, `hk` is a new project and not yet fully supported (there's a warning that things may change in each release on the project website), so we may choose to put this off until a time when `hk` becomes more mature. This comes with similar advantages to `pre-commit`, such as having a standard approach to configuring our linting tools, and for those who wish to, it allows you to integrate the linting with `git commit`. In this PR, I've converting our existing GitHub Actions workflow to a single linting workflow which calls `hk check`. This does mean we lose granularity of individual linters, and if we'd prefer to stick with our existing approach that can be done by using `hk check --linter <linter>`.
2 parents cd31e21 + 20d61b0 commit 9370d08

File tree

9 files changed

+356
-350
lines changed

9 files changed

+356
-350
lines changed

.github/workflows/lint.yml

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ name: Lint
33
on:
44
pull_request:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
7-
prettier:
8-
name: Prettier
10+
lint:
11+
name: Lint
912
runs-on: ubuntu-latest
1013

1114
steps:
@@ -15,71 +18,12 @@ jobs:
1518
bundler-cache: true
1619
- uses: actions/setup-node@v4
1720
with:
18-
node-version-file: .tool-versions
1921
cache: yarn
20-
- run: yarn install --immutable --immutable-cache --check-cache
21-
- run: yarn prettier --check --ignore-unknown '**/*'
22-
23-
rubocop:
24-
name: Rubocop
25-
runs-on: ubuntu-latest
26-
27-
steps:
28-
- uses: actions/checkout@v4
29-
- uses: ruby/setup-ruby@v1
30-
with:
31-
bundler-cache: true
32-
- uses: actions/setup-node@v4
33-
with:
3422
node-version-file: .tool-versions
35-
cache: yarn
3623
- run: yarn install --immutable --immutable-cache --check-cache
37-
- run: bin/bundle exec rubocop
38-
39-
rufo:
40-
name: Rufo
41-
runs-on: ubuntu-latest
42-
43-
steps:
44-
- uses: actions/checkout@v4
45-
- uses: ruby/setup-ruby@v1
46-
with:
47-
bundler-cache: true
48-
- run: bin/bundle exec rufo --check app
49-
50-
brakeman:
51-
name: Brakeman
52-
runs-on: ubuntu-latest
53-
54-
steps:
55-
- uses: actions/checkout@v4
56-
- uses: ruby/setup-ruby@v1
57-
with:
58-
bundler-cache: true
59-
- run: bin/bundle exec brakeman
60-
61-
terraform-fmt:
62-
name: Terraform fmt
63-
runs-on: ubuntu-latest
64-
65-
steps:
66-
- uses: actions/checkout@v4
67-
- name: Install terraform
68-
uses: hashicorp/setup-terraform@v3
69-
with:
70-
terraform_version: 1.10.5
71-
- name: Check formatting
72-
run: terraform fmt -check -recursive
73-
74-
tflint:
75-
name: TFLint
76-
runs-on: ubuntu-latest
77-
78-
steps:
79-
- uses: actions/checkout@v4
24+
- uses: hashicorp/setup-terraform@v3
8025
- uses: terraform-linters/setup-tflint@v4
81-
- name: Run TFLint
82-
working-directory: terraform
83-
run: |
84-
tflint --init
85-
tflint --recursive
26+
- uses: jdx/mise-action@v2
27+
with:
28+
install_args: hk pkl
29+
- run: hk check

.rubocop.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ Layout/EmptyLineAfterMagicComment:
2020

2121
Layout/LineLength:
2222
AllowedPatterns: [idx_on]
23+
Exclude:
24+
- db/schema.rb
2325

2426
Lint/PercentStringArray:
2527
Exclude:
2628
- spec/models/dps_export_spec.rb
2729

30+
Rails/CreateTableWithTimestamps:
31+
Exclude:
32+
- db/schema.rb
33+
2834
Rails/LexicallyScopedActionFilter:
2935
Exclude:
3036
- app/controllers/users/sessions_controller.rb
@@ -56,6 +62,12 @@ RSpec/VerifiedDoubles:
5662
Style/FrozenStringLiteralComment:
5763
Enabled: true
5864
EnforcedStyle: always_true
65+
Exclude:
66+
- db/schema.rb
67+
68+
Style/NumericLiterals:
69+
Exclude:
70+
- db/schema.rb
5971

6072
Rails/ApplicationController:
6173
Exclude:

.rufo

Lines changed: 0 additions & 1 deletion
This file was deleted.

.tool-versions

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
nodejs 22.5.1
2-
postgres 17.2
3-
ruby 3.4.3
4-
awscli 2.13.31
5-
terraform 1.10.5
6-
tflint 0.55.1
1+
nodejs 22.5.1
2+
postgres 17.2
3+
ruby 3.4.3
4+
awscli 2.13.31
5+
terraform 1.10.5
6+
tflint 0.55.1
7+
pkl 0.28.1
8+
hk 0.8.5

0 commit comments

Comments
 (0)