# "Static analysis" for hugo sites with "strict mode" (build time safety against unintentional errors)

**URL:** <https://discourse.gohugo.io/t/static-analysis-for-hugo-sites-with-strict-mode-build-time-safety-against-unintentional-errors/56197>\
**Category:** dev\
**Created:** [November 1, 2025, 1:38pm UTC](https://discourse.gohugo.io/t/static-analysis-for-hugo-sites-with-strict-mode-build-time-safety-against-unintentional-errors/56197 "2025-11-01T13:38:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregtau](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gregtau/32/25308_2.png) [@gregtau](https://discourse.gohugo.io/u/gregtau)\
**Post date:** [November 1, 2025, 1:38pm UTC](https://discourse.gohugo.io/t/static-analysis-for-hugo-sites-with-strict-mode-build-time-safety-against-unintentional-errors/56197/1 "2025-11-01T13:38:24Z")

</div>

I also made an issue for this: ["strict mode" that make build fail on missing links, unused keys etc. · Issue #14108 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/issues/14108)

But basically I want to have more build time safety for unintentional errors, just like a statically typed language gives safety during refactoring.

I’m able to get internal link checking to work, but I had to manually check stuff as GPT-5 was not smart enough to do it in 2-3 shots, this just tells me it is not well documented enough

Internal link checks worked by just adding the below in layouts/\_markup/render-links.html (ref. [Link and image render hooks - Veriphor](https://www.veriphor.com/articles/link-and-image-render-hooks/) ):

```auto
{{- $u := urls.Parse .Destination -}}
{{- $isAbs := or (ne $u.Scheme "") (strings.HasPrefix .Destination "//") -}}

{{- if not $isAbs -}}
  {{- $page := site.GetPage $u.Path | default (.Page.GetPage $u.Path) -}}
  {{- $res := cond (not $page) (resources.Get $u.Path) nil -}}

  {{- if not (or $page $res) -}}
    {{- errorf "Broken internal link %q on %s" .Destination .Page.File.Path -}}
  {{- end -}}

  {{- if and $page $u.Fragment -}}
    {{- if not ($page.Fragments.Identifiers.Contains $u.Fragment) -}}
      {{- errorf "Broken fragment #%s in link %q on %s" $u.Fragment .Destination .Page.File.Path -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

<a href="{{ .Destination | safeURL }}"{{- with .Title }} title="{{ . }}"{{- end }}>{{ .Text | safeHTML }}</a>

```
