Skip to content

Commit da79b8d

Browse files
authored
Merge pull request #10 from dropdevrahul/ci/lint-and-hooks
ci: fix embed build, add Go + frontend linting and git hooks
2 parents 08b5706 + dd72f71 commit da79b8d

17 files changed

Lines changed: 1672 additions & 16 deletions

File tree

.githooks/pre-commit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# pre-commit: ensure all Go files are gofmt-formatted.
3+
set -e
4+
5+
unformatted=$(gofmt -l $(find . -name '*.go' -not -path './frontend/*') 2>/dev/null)
6+
if [ -n "$unformatted" ]; then
7+
echo "The following Go files are not gofmt-formatted:"
8+
echo "$unformatted"
9+
echo ""
10+
echo "Run: gofmt -w ."
11+
exit 1
12+
fi

.githooks/pre-push

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# pre-push: mirror CI checks locally before pushing.
3+
set -e
4+
5+
echo "==> go vet ./..."
6+
go vet ./...
7+
8+
echo "==> go test ./..."
9+
go test ./...
10+
11+
if command -v golangci-lint > /dev/null 2>&1; then
12+
echo "==> golangci-lint run ./..."
13+
golangci-lint run ./...
14+
else
15+
echo "golangci-lint not found, skipping (install from https://golangci-lint.run)"
16+
fi
17+
18+
echo "==> frontend lint + build"
19+
( cd frontend && npm run lint && npm run build )
20+
21+
echo "All pre-push checks passed."

.github/workflows/ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,21 @@ jobs:
2727
- name: Test
2828
run: go test -race ./...
2929

30+
lint:
31+
name: Go lint
32+
runs-on: ubuntu-22.04
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-go@v5
36+
with:
37+
go-version: '1.22'
38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@v6
40+
with:
41+
version: v1.62.2
42+
3043
frontend:
31-
name: Frontend (build + typecheck)
44+
name: Frontend (lint + build + typecheck)
3245
runs-on: ubuntu-22.04
3346
defaults:
3447
run:
@@ -42,5 +55,7 @@ jobs:
4255
cache-dependency-path: frontend/package-lock.json
4356
- name: Install
4457
run: npm ci
58+
- name: Lint
59+
run: npm run lint
4560
- name: Build (runs tsc)
4661
run: npm run build

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
build/bin
22
node_modules
3-
frontend/dist
3+
# Keep the dir tracked (via .gitkeep) so `//go:embed all:frontend/dist`
4+
# compiles on a clean checkout; ignore the built assets themselves.
5+
frontend/dist/*
6+
!frontend/dist/.gitkeep
47

58
# OS / editor cruft
69
.DS_Store

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
run:
3+
timeout: 5m
4+
5+
linters:
6+
enable:
7+
- errcheck
8+
- gosimple
9+
- govet
10+
- ineffassign
11+
- staticcheck
12+
- unused
13+
- gofmt
14+
- misspell
15+
16+
issues:
17+
exclude-rules:
18+
# Deferred Close() failures are not actionable here.
19+
- linters: [errcheck]
20+
source: "defer .*\\.Close\\(\\)"
21+
# The nested scaffold under frontend/hypr is a separate module artifact.
22+
exclude-dirs:
23+
- frontend

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Cross-platform release workflow that builds macOS/Windows/Linux binaries on `v*` tags.
1818
- Contributor documentation: `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, `SECURITY.md`,
1919
issue/PR templates, and this changelog.
20+
- `golangci-lint` config (`.golangci.yml`) and a dedicated `lint` job in CI.
21+
- ESLint config for the frontend (`frontend/.eslintrc.cjs`); `npm run lint` added to the
22+
frontend CI job and the pre-push hook.
23+
- Git hooks (`.githooks/pre-commit`, `.githooks/pre-push`) that enforce formatting and
24+
mirror CI checks locally; enable with `make hooks`.
25+
- `Makefile` with `hooks`, `setup`, `lint`, `test`, and `build` targets.
2026

2127
### Changed
2228
- cURL import now populates the header rows and request body of the active tab.
2329
- The response view now follows the active request tab.
2430
- The "add header" action moved next to the Request Headers title.
2531

2632
### Fixed
33+
- `//go:embed all:frontend/dist` caused a compile failure on clean checkouts because
34+
`frontend/dist/` was gitignored; fixed by committing a `.gitkeep` and updating
35+
`.gitignore` to track it.
36+
- Exported request headers now include their values; the `Header.value` field was
37+
renamed to `Header.Value` so the JSON marshaller picks it up correctly.
2738
- Request headers were serialized to an empty object and not sent; they are now sent correctly.
2839
- Corrected the application window title (`Hpyr``Hypr`).
2940

CONTRIBUTING.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,41 @@ Before pushing, run the same checks CI runs:
4646
go vet ./...
4747
go test ./...
4848

49-
# Frontend (typecheck + build)
50-
cd frontend && npm ci && npm run build
49+
# Go linting
50+
golangci-lint run ./...
51+
52+
# Frontend (lint + typecheck + build)
53+
cd frontend && npm ci && npm run lint && npm run build
5154
```
5255

5356
CI ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)) runs these on every push and pull request.
5457

58+
### Local git hooks
59+
60+
Enable the repo's git hooks to catch issues before they hit CI:
61+
62+
```bash
63+
make hooks # or: git config core.hooksPath .githooks
64+
```
65+
66+
- `pre-commit` — fails if any Go file is not `gofmt`-formatted.
67+
- `pre-push` — mirrors CI (`go vet`, `go test`, `golangci-lint` if installed, frontend lint + build).
68+
69+
`make setup` runs `make hooks` and installs frontend dependencies in one go.
70+
71+
### Git hooks
72+
73+
The repo ships pre-commit and pre-push hooks in `.githooks/`. Enable them once per clone:
74+
75+
```bash
76+
make hooks
77+
# or manually:
78+
git config core.hooksPath .githooks
79+
```
80+
81+
The **pre-commit** hook rejects any unformatted Go files (`gofmt -w .` to fix).
82+
The **pre-push** hook mirrors the full CI suite locally (go vet, go test, golangci-lint if available, and the frontend lint + build).
83+
5584
## Releasing
5685

5786
Hypr follows [Semantic Versioning](https://semver.org) (`MAJOR.MINOR.PATCH`):

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: hooks setup lint test build
2+
3+
hooks:
4+
git config core.hooksPath .githooks
5+
chmod +x .githooks/*
6+
7+
setup: hooks
8+
cd frontend && npm install
9+
10+
lint:
11+
go vet ./...
12+
golangci-lint run ./...
13+
cd frontend && npm run lint
14+
15+
test:
16+
go test ./...
17+
18+
build:
19+
wails build

app.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (a *App) RunCurl(curl string) RequestResult {
9090

9191
type Header struct {
9292
Key string
93-
value string
93+
Value string
9494
}
9595

9696
// Greet returns a greeting for the given name
@@ -132,7 +132,6 @@ func (a *App) MakeRequest(
132132
}
133133
}
134134

135-
texts := string(b.Bytes())
136-
result.Body = texts
135+
result.Body = b.String()
137136
return result
138137
}

export.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ func (a *App) Export(req Request, reqHeaders [][]Header, reqBodies []string, r R
4949
}
5050

5151
defer f.Close()
52-
f.Write(js)
52+
if _, err := f.Write(js); err != nil {
53+
log.Println(err)
54+
return err
55+
}
5356

5457
return nil
5558
}

0 commit comments

Comments
 (0)