Skip to content

Commit 6880f1b

Browse files
committed
ci: run golangci-lint on the Caddy module
Adds a second golangci-lint step scoped to caddy/ on the same job as the root lint. Fixes the pre-existing issues that surfaced: - admin.go: propagate the success() error instead of dropping it - admin_test.go: assert resp.Body.Close() with require.NoError - app.go: rename iniError to errIni (ST1012) - mercure.go: lowercase the leading article in error strings (ST1005)
1 parent 2ac6c41 commit 6880f1b

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ jobs:
9191
if: matrix.php-versions == '8.5'
9292
with:
9393
version: latest
94+
- name: Lint Caddy module Go code
95+
uses: golangci/golangci-lint-action@v9
96+
if: matrix.php-versions == '8.5'
97+
with:
98+
version: latest
99+
working-directory: caddy
94100
- name: Ensure go.mod is tidy
95101
if: matrix.php-versions == '8.5'
96102
run: go mod tidy -diff

caddy/admin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ func (admin *FrankenPHPAdmin) restartWorkers(w http.ResponseWriter, r *http.Requ
4141

4242
frankenphp.RestartWorkers()
4343
caddy.Log().Info("workers restarted from admin api")
44-
admin.success(w, "workers restarted successfully\n")
4544

46-
return nil
45+
return admin.success(w, "workers restarted successfully\n")
4746
}
4847

4948
func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, _ *http.Request) error {

caddy/admin_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/caddyserver/caddy/v2/caddytest"
1616
"github.com/dunglas/frankenphp"
1717
"github.com/stretchr/testify/assert"
18+
"github.com/stretchr/testify/require"
1819
)
1920

2021
func TestRestartWorkerViaAdminApi(t *testing.T) {
@@ -245,7 +246,7 @@ func getAdminResponseBody(t *testing.T, tester *caddytest.Tester, method string,
245246
r, err := http.NewRequest(method, adminUrl+path, nil)
246247
assert.NoError(t, err)
247248
resp := tester.AssertResponseCode(r, http.StatusOK)
248-
defer resp.Body.Close()
249+
defer func() { require.NoError(t, resp.Body.Close()) }()
249250
bytes, err := io.ReadAll(resp.Body)
250251
assert.NoError(t, err)
251252

@@ -319,7 +320,7 @@ func TestAddModuleWorkerViaAdminApi(t *testing.T) {
319320
assert.NoError(t, err)
320321
r.Header.Set("Content-Type", "text/caddyfile")
321322
resp := tester.AssertResponseCode(r, http.StatusOK)
322-
defer resp.Body.Close()
323+
defer func() { require.NoError(t, resp.Body.Close()) }()
323324

324325
// Get the updated debug state to check if the worker was added
325326
updatedDebugState := getDebugState(t, tester)

caddy/app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type FrankenPHPApp struct {
6666
logger *slog.Logger
6767
}
6868

69-
var iniError = errors.New(`"php_ini" must be in the format: php_ini "<key>" "<value>"`)
69+
var errIni = errors.New(`"php_ini" must be in the format: php_ini "<key>" "<value>"`)
7070

7171
// CaddyModule returns the Caddy module information.
7272
func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
@@ -274,14 +274,14 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
274274
parseIniLine := func(d *caddyfile.Dispenser) error {
275275
key := d.Val()
276276
if !d.NextArg() {
277-
return d.WrapErr(iniError)
277+
return d.WrapErr(errIni)
278278
}
279279
if f.PhpIni == nil {
280280
f.PhpIni = make(map[string]string)
281281
}
282282
f.PhpIni[key] = d.Val()
283283
if d.NextArg() {
284-
return d.WrapErr(iniError)
284+
return d.WrapErr(errIni)
285285
}
286286

287287
return nil
@@ -298,7 +298,7 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
298298

299299
if !isBlock {
300300
if !d.NextArg() {
301-
return d.WrapErr(iniError)
301+
return d.WrapErr(errIni)
302302
}
303303
err := parseIniLine(d)
304304
if err != nil {

caddy/mercure.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func (f *FrankenPHPModule) assignMercureHub(ctx caddy.Context) {
4040
func createMercureRoute() (caddyhttp.Route, error) {
4141
mercurePublisherJwtKey := os.Getenv("MERCURE_PUBLISHER_JWT_KEY")
4242
if mercurePublisherJwtKey == "" {
43-
return caddyhttp.Route{}, errors.New(`The "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
43+
return caddyhttp.Route{}, errors.New(`the "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
4444
}
4545

4646
mercureSubscriberJwtKey := os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY")
4747
if mercureSubscriberJwtKey == "" {
48-
return caddyhttp.Route{}, errors.New(`The "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
48+
return caddyhttp.Route{}, errors.New(`the "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
4949
}
5050

5151
mercureRoute := caddyhttp.Route{

0 commit comments

Comments
 (0)