Find new mandoc -T lint warnings in FreeBSD manual pages, per Git
commit, before they pile up.
mandoc -T lint is the standard way to check a manual page, but on a
page with existing warnings it is hard to see whether your change made
things better or worse. This script answers exactly that question. For
every manual page changed in a commit, it lints the old and the new
version and reports only the difference: the warnings that were
introduced and the ones that were fixed.
It can also check uncommitted changes before you commit them, check recent history such as the last 30 days or your last 10 commits, and give an overview of which pages in a directory are lint clean and which still need work.
Download the script from https://people.freebsd.org/~wosch/src/mandoc-lint-regression/mandoc-lint-regression.sh and make it executable, e.g. on FreeBSD:
fetch https://people.freebsd.org/~wosch/src/mandoc-lint-regression/mandoc-lint-regression.sh
chmod +x mandoc-lint-regression.sh
git: pkg install git/bin/sh, mandoc(1), and file(1) from the
FreeBSD base systemRun the script anywhere inside a Git checkout, e.g. freebsd-src.
mandoc-lint-regression.sh [-cku] [-d level] [-F file] [-W level]
{commit ... | staged | unstaged}
mandoc-lint-regression.sh [-Acku] [-a who] [-d level] [-F file]
[-W level] {-D days [-n count] | -n count}
mandoc-lint-regression.sh [-c] [-d level] [-F file] [-W level]
-s path ...
mandoc-lint-regression.sh -h
mandoc-lint-regression.sh -V
| Argument / option | Meaning |
|---|---|
commit ... |
a commit hash, or any name Git accepts: HEAD, HEAD~3, a branch, a tag; several commits are checked one after another |
staged |
changes in the index against HEAD (git diff --cached) |
unstaged |
changes in the working tree against the index (git diff) |
-D days |
check the commits of the last days that change a manual page, see below |
-n count |
check the last count commits that change a manual page, see below |
-s path ... |
lint status of all manual pages below the paths, see below |
-A |
with -D or -n: check only your own commits, as author or committer |
-a who |
with -D or -n: check only the commits of who, as author or committer, see below |
-c |
ignore vendor code below contrib/, crypto/, cddl/, and sys/contrib/ (FreeBSD), external/ (NetBSD), and gnu/ (OpenBSD, NetBSD); for a renamed page, the new path counts |
-d level |
output level 0 to 3, see below (default: 1) |
-F file |
ignore references to the manual pages listed in file that are not installed, see below |
-h |
print the usage message and the homepage, and exit |
-k |
keep the work directory with the extracted files and lint output |
-u |
do not show the URL of the commit, or with -s of the manual page, on the Git web server |
-V |
print the version; unless the output level is 0, also check for a newer version, see below |
-W level |
the minimum level of the mandoc messages to look at, see below |
Environment variables:
| Variable | Meaning |
|---|---|
COMMIT_URL |
URL of a commit on the Git web server, without the hash at the end (default: detected from the Git remotes, see below) |
MANDOC_LINT_EXCLUDE |
default for -F file |
MANDOC |
mandoc binary to use, a command name or path without options (default: mandoc) |
MANPATTERN |
file names of manual pages, shell patterns separated by spaces (default: *.[1-9]) |
NO_COLOR |
if set, print no colored marks |
TMPDIR |
directory for the work directory (default: /tmp) |
VERSION_CHECK |
set to no to disable the check for a newer version |
debug |
default output level, overridden by -d |
A file counts as a manual page if its name matches MANPATTERN and
file(1) detects it as troff input, so data files like test.1 are
skipped.
Exit status: 0 if there are no new warnings (with -s: all pages are
lint clean), 1 if there are, in at least one of the commits, 2 on
errors, including a mandoc that fails to run (mandoc exit status 5 or
6), a failed git command, and a manual page that cannot be read: the
script never reports success for a page it could not check. Lint
messages never cause exit status 2. This makes the script usable in
loops, Git hooks, and CI.
$ mandoc-lint-regression.sh -d 2 11a64dfa100d
==> lib/libpmc/pmc.amd.3 (11a64dfa100d 2026-11-08 @wosch)
log: pmc.amd.3: add missing commas between names
url: https://cgit.freebsd.org/src/commit/?id=11a64dfa100d
fixed warnings:
mandoc: lib/libpmc/pmc.amd.3:29:2: WARNING: missing comma before name: Nm pmc.k8
✓ 3 warning(s) left
==> usr.bin/find/find.1 (11a64dfa100d 2026-11-08 @wosch)
log: pmc.amd.3: add missing commas between names
url: https://cgit.freebsd.org/src/commit/?id=11a64dfa100d
✗ new warnings:
mandoc: usr.bin/find/find.1:412:23: STYLE: whitespace at end of input line
Each page is shown with the commit's short hash, date, and committer,
followed by the subject of the commit message (log:) and the URL of
the commit on the Git web server (url:). Use -u to omit the URL.
The URL is shown only in a FreeBSD repository, which is detected from the URLs of the Git remotes:
| Remote | URL shown |
|---|---|
FreeBSD src, doc, or ports (git.freebsd.org, gitrepo.freebsd.org, or a mirror like codeberg.org/FreeBSD/freebsd-src) |
https://cgit.freebsd.org/src/commit/?id=... |
| anything else, e.g. openbsd-src, netbsd-src, or a clone of a local mirror | no URL |
For other repositories, set COMMIT_URL to the URL of a commit on
your web server, without the hash, e.g.
COMMIT_URL='https://codeberg.org/owner/repo/commit/'.
If the commit is on a vendor branch, e.g. a vendor import, the branch is shown as well:
==> zlib.3 (d3419e91c112 origin/vendor/zlib 2026-11-07 @delphij)
Line and column numbers are ignored when comparing, so text that only moved does not show up as a new warning. Renamed pages are compared with their old version.
On a UTF-8 terminal, the status is marked in color:
| Mark | Meaning |
|---|---|
| ✗ red | new warnings |
| ✓ yellow | warnings fixed or unchanged, but some are left |
| ✓ green | the page is lint clean (no mandoc output at all) |
In pipes and log files, or with NO_COLOR set, the output is plain
text.
mandoc -T lint reports everything, down to style messages like
"whitespace at end of input line". With -W level, only the messages
of that level and above are looked at. The levels are those of
mandoc(1): base (the default, also called all), style,
warning, error, and unsupp.
mandoc-lint-regression.sh -W warning -D 30
mandoc-lint-regression.sh -W warning -s usr.bin/find
With -W warning, a commit that only adds a STYLE message is not
reported, and with -s, a page that has only STYLE messages counts as
lint clean. -W works in all modes.
mandoc checks every .Xr reference against the manual pages installed
on your system. A page that refers to a program from the ports
collection, e.g. cvs(1), gets a STYLE message:
mandoc: contrib/mandoc/mdoc.7:1277:6: STYLE: referenced manual not found: Xr cvs 1
With -F file, these messages are ignored for the manual pages listed
in file, one per line, as name and section. Empty lines and lines
starting with # are ignored:
# manual pages that are not in the base system
cvs 1
git 1
The messages are removed before the comparison, so they never count as
new warnings, and with -s, a page whose only messages are about
listed manual pages counts as lint clean. Other messages are not
affected. At output level 3, the ignored messages are still shown.
To use the same list on every run, e.g. in the pre-commit hook, set
the environment variable MANDOC_LINT_EXCLUDE to the file; -F
overrides it. -W warning hides these messages as well, but together
with all other STYLE messages.
Set the level with -d level:
| Level | Shows |
|---|---|
| 0 | nothing, only the exit status |
| 1 | new warnings (default); for a list of commits and with -D or -n, also a summary at the end |
| 2 | also fixed warnings, and whether the page is now lint clean or how many warnings are left |
| 3 | everything: unchanged and skipped pages, and a summary |
The summary counts manual pages:
100 commits: 205 manual page(s) checked
24 with new warnings
31 with fixed warnings
12 now lint clean
1 non-troff file(s) skipped
0 vendor file(s) ignored
"Now lint clean" counts the pages that had warnings before the commit and have none after it.
mandoc-lint-regression.sh unstaged
mandoc-lint-regression.sh staged
New files must be known to Git: git add them, or use git add -N file
for unstaged. The keywords take precedence over a branch or tag of the
same name; use e.g. refs/heads/staged in that case.
To refuse commits that add new warnings, put this into
.git/hooks/pre-commit and make it executable:
#!/bin/sh
exec mandoc-lint-regression.sh staged
With -s, the script does not compare versions, but reports the
current state of all manual pages below the given directories or files,
as they are on disk:
$ mandoc-lint-regression.sh -s usr.bin/find lib/libc
✗ lib/libc/gen/getbsize.3: 2 warning(s)
✗ usr.bin/find/find.1: 1 warning(s)
214 manual page(s) checked: 212 lint clean, 2 need fixing
At level 2 and above, in a FreeBSD repository, each page that needs
fixing is shown with its URL on the Git web server, as of the commit
HEAD, so the line numbers of the messages fit. Use -u to omit it:
$ mandoc-lint-regression.sh -W error -d 2 -s usr.sbin/nfsd
✗ usr.sbin/nfsd/nfsd.8: 3 warning(s)
url: https://cgit.freebsd.org/src/tree/usr.sbin/nfsd/nfsd.8?id=11a64dfa100d
mandoc: usr.sbin/nfsd/nfsd.8:61:2: ERROR: skipping display without arguments: Bd
...
Only files tracked by Git are checked, so build output and other
untracked files are ignored. With -s, the output levels set with
-d level are:
| Level | Shows |
|---|---|
| 0 | nothing, only the exit status |
| 1 | the pages that need fixing, and a summary (default) |
| 2 | also their warnings, and the URL of the page on the Git web server |
| 3 | also the lint clean and skipped pages |
The script checks all commits given on the command line, one after
another and in the given order. Use git log to pick the commits. The
exit status is 1 if any of them introduced a new warning. An unknown
commit in the list is an error, and nothing is checked.
Use git log --first-parent to check only the commits made on the
branch itself, e.g. main. Without it, git log also lists the commits
of branches that were merged into main, above all the vendor branches,
so you would check every single commit of a vendor import, e.g. on
vendor/zlib. With --first-parent, you get the merge commit instead.
It shows the change below contrib/, which -c can ignore.
With -D days, the script finds the commits itself: all commits of
the last days on the current branch that change a manual page, newest
first.
mandoc-lint-regression.sh -D 7
mandoc-lint-regression.sh -c -d 2 -D 30
This is the same as a list of commits from
git log --first-parent --since="7 days ago" -- '*.[1-9]'.
With -n count, the script checks the last commits that change a
manual page, however old they are, newest first. With -D as well,
both limits apply: the commits of the last days, but no more than
count.
mandoc-lint-regression.sh -n 20
mandoc-lint-regression.sh -D 30 -n 50
-D and -n cannot be combined with commits, staged, unstaged,
or -s.
With -A, only your own commits are checked: those where you are the
author or the committer, by the e-mail address in
git config user.email. As a committer, this includes the patches you
committed for other people. With -d 2, the output also shows the
warnings you fixed, and whether a page is now lint clean:
mandoc-lint-regression.sh -A -d 2 -D 90
mandoc-lint-regression.sh -A -n 10
With -n, the count is your own commits: -A -n 10 checks your last
10 commits that change a manual page.
With -a who, only the commits of who are checked, as author or
committer, as with -A. who is an e-mail address, or a name without
@ that matches the part of the address before the @: -a wosch
finds the commits of wosch@FreeBSD.org, the same name the script
shows in its headers as @wosch.
mandoc-lint-regression.sh -a wosch -D 90
mandoc-lint-regression.sh -a wosch@FreeBSD.org -n 20
-a needs -D or -n, and cannot be combined with -A.
For anything else, e.g. another branch, pass the commits yourself, as in the following examples.
With -c, manual pages in vendor code, e.g. below contrib/, are
ignored:
mandoc-lint-regression.sh -c $(git log --first-parent --format=%h \
--since="30 days ago")
Faster: with the path pattern '*.[1-9]', Git lists only the commits
that change a manual page. --reverse checks them oldest first:
mandoc-lint-regression.sh $(git log --first-parent --reverse \
--format=%h --since="90 days ago" -- '*.[1-9]')
All commits on stable/15 since the 15.1 release that touch manual
pages, oldest first, ignoring vendor code with -c:
mandoc-lint-regression.sh -c $(git log --first-parent --reverse \
--format=%h release/15.1.0..origin/stable/15 -- '*.[1-9]')
The range release/15.1.0..origin/stable/15 lists the commits on
stable/15 that are not part of 15.1.0. As the release tag is on the
releng/15.1 branch, this includes the commits made on stable/15
during the release cycle, after releng/15.1 was branched. If your
remote is called freebsd, use freebsd/stable/15, and run
git fetch --tags first if the tag is missing in your clone.
If git log finds no commit, the script prints its usage message, as
there is nothing to check. For more commits than fit on a command
line, e.g. the whole history, use xargs:
git log --first-parent --format=%h -- '*.[1-9]' |
xargs mandoc-lint-regression.sh -c
The script is fast enough to check a lot of history: about 1000 commits, roughly one month of freebsd-src, take less than 20 seconds. Commits that do not change any manual page cost almost nothing.
-s runs file and mandoc for many pages at once, on all CPUs in
parallel. Checking all manual pages in freebsd-src, without vendor
code, takes about 15 seconds:
$ time mandoc-lint-regression.sh -c -d 0 -s .
real 0m15.567s
user 0m39.620s
sys 0m10.906s
With -V, and when the usage message is printed after a wrong call,
the script checks if a newer version is available for download, and
prints a note on stderr if so:
$ mandoc-lint-regression.sh -V
2.11
mandoc-lint-regression.sh: version 2.12 is available, you are running 2.11
download: https://people.freebsd.org/~wosch/src/mandoc-lint-regression/
For this, it downloads a small file from people.freebsd.org, with a
timeout of 3 seconds. Network errors and timeouts are ignored. There is
no check at output level 0 (-d 0), or with VERSION_CHECK=no. A
normal run never accesses the network.
.Xr references against the manual pages installed on
your machine (/usr/share/man), not against the source tree. A
commit that adds a new page and references it reports
"referenced manual not found" until the page is installed, and -s
gives the most accurate results on a system built from the same
tree.BSD-2-Clause, Copyright (c) 2026 Wolfram Schneider wosch@FreeBSD.org
Homepage: https://people.freebsd.org/~wosch/src/mandoc-lint-regression/