forgejo/build
Mathieu Fenniak 7b5d623737 fix: introduce lint-single-response to prevent control flow continuing past a ctx.Error(...)-style method (#13087)
This PR adds a new linter to the codebase and addresses all the problems that it identified (including a small number of false positives).  The lint-single-response Go analyzer attempts to prevent a common problem in Forgejo where it is possible for a web handler to provide a response to a request, and then continue code execution unintentionally.  For example:

```go
err := json.Unmarshal(data, &claims)
if err != nil {
    ctx.Error(http.StatusInternalServerError, "Error in unmarshal", err)
    // Oops, I forgot to `return` here...
}
// ... more work occurs ...
ctx.JSON(http.StatusOK, resp)
```

In order to detect these cases, lint-single-response contains a list of functions that deliver a web response.  When any of those functions are used within a function, the control flow must not perform any work after the function is invoked -- it can only return and exit the function.

### Tests for Go changes

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I ran...
  - [x] `make pr-go` before pushing

### Documentation

- [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
    - Documentation on the new linter is included inline, in `build/lint-single-response/README.md`.
- [ ] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
- [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13087
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
2026-06-14 17:06:03 +02:00
..
codeformat chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
lint-locale feat: add actionable message on lint-locale failure (#12748) 2026-05-27 11:48:07 +02:00
lint-locale-usage feat(build): Support go "fmt" format strings as masked usage patterns (#12013) 2026-05-01 02:46:01 +02:00
lint-single-response fix: introduce lint-single-response to prevent control flow continuing past a ctx.Error(...)-style method (#13087) 2026-06-14 17:06:03 +02:00
backport-locales.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
code-batch-process.go chore: rename 'migrations' to 'gitea_migrations' 2025-10-14 14:40:49 -06:00
generate-bindata.go fix: Dockerfile should re-use bindata files when possible 2025-06-13 14:00:57 +02:00
generate-disposable-email.go feat: add setting to block disposable emails 2024-11-20 23:17:37 -06:00
generate-emoji.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
generate-gitignores.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
generate-go-licenses.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
generate-licenses.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
merge-forgejo-locales.go [I18N] make merge-locales & build/merge-forgejo-locales.go are noop 2024-03-28 18:02:55 +01:00
test-echo.go Clean some legacy files and move some build files (#23699) 2023-03-25 16:22:51 -04:00
test-env-check.sh Prepare and check test env during CI (#17725) 2021-11-19 13:58:34 +08:00
test-env-prepare.sh Prepare and check test env during CI (#17725) 2021-11-19 13:58:34 +08:00