Files
lucisv/tools/vfmt-changed.sh
T
lucioandClaude Fable 5 e9008b680c Add range formatting and the second lint-rule set (round 18)
range-formatting: --lines M-N[,M-N...] formats only the top-level
items intersecting the ranges; modules/packages split head/body/tail
with independent decisions, everything else is atomic, and
unselected units are emitted as merged verbatim source slices (the
run-merge is load-bearing: per-item slices let separators collapse
blank lines between untouched items). Convergence via Selection
replay -- same-selection re-runs are fixed points, sound because the
equivalence check has already proven token identity; QA's sabotage
of the replay failed immediately on real RTL. The honest limit
(same line numbers can sweep in a neighbor after lines move;
449/8236 corpus trials, all settled next run) is measured and
pinned. Fence wins over range; alignment groups split at verbatim
boundaries; cache fully bypassed; LSP rangeFormatting advertised and
consumes only lines (no UTF-16 column math); tools/vfmt-changed.sh
derives ranges from git diff. Default behavior provably unchanged
(TSV md5 + all-578-file byte-compare vs a pre-round binary).

lint-rules-2: visit.rs walks class bodies (closing the classes
handshake; +6 real findings in UVM code), five new rules with
evidence-based defaults -- parameter/enum/struct-union-name-style ON
with Verible's exact names and published defaults (vendored waivers
now honored), module-name-style OFF (Verible has no such rule; the
brief's premise was checked and corrected), wire-reg-mixup ON (0
corpus noise in .v, 209 findings on a .sv rename -- both zeroes
proven). rules_markdown() generates the rule reference; 13 rules
total, zero CLI/server wiring needed.

Also: lead notes in classes and shared-fence-filter READMEs
documenting the fence asymmetry lint-rules-2 QA found (a fence in a
class body protects fixes via the scan backstop even though the
formatter ignores it there).

768 workspace tests. Dev: 2 Opus agents; QA: 2 Sonnet agents;
reviews in docs/features/{range-formatting,lint-rules-2}/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 15:28:24 -07:00

61 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Format only the lines a git diff touched — vfmt's answer to Verible's
# `git-verible-verilog-format.sh`.
#
# This is what makes vfmt adoptable in a dirty legacy tree: your patch comes
# out formatted, and not one byte outside it moves, so review sees the change
# you made rather than a reflow of the whole file.
#
# Usage: tools/vfmt-changed.sh [--check|--diff] [<rev>] [-- <pathspec>...]
#
# <rev> what to diff against; default: unstaged+staged work, i.e. HEAD.
# `tools/vfmt-changed.sh origin/main` formats a whole branch.
# --check / --diff are passed through to vfmt, so this works in CI.
#
# Exit status is vfmt's, per the frozen contract: 0 nothing to do, 1
# --check/--diff found changes, 2 an error (that file was left untouched).
#
# Only *added* lines are formatted: `git diff -U0` hunk headers give
# `@@ -old +first,count @@`, and a `count` of 0 means the hunk only deleted,
# so there is nothing on the new side to format.
set -eu
vfmt=${VFMT:-target/release/vfmt}
mode=""
rev="HEAD"
have_rev=0
while [ $# -gt 0 ]; do
case $1 in
--check|--diff) mode=$1; shift ;;
--) shift; break ;;
-*) echo "usage: $0 [--check|--diff] [<rev>] [-- <pathspec>...]" >&2; exit 2 ;;
*) rev=$1; have_rev=1; shift ;;
esac
done
[ "$have_rev" = 1 ] || rev=HEAD
command -v "$vfmt" >/dev/null 2>&1 || [ -x "$vfmt" ] || {
echo "no vfmt binary at $vfmt (cargo build --release? or set VFMT=)" >&2
exit 2
}
status=0
files=$(git diff --name-only --diff-filter=d "$rev" -- "$@" \
| grep -E '\.(sv|svh|v|vh)$' || true)
[ -n "$files" ] || exit 0
for file in $files; do
# `first,count` from every hunk header, as `first-last`, comma-joined.
ranges=$(git diff -U0 "$rev" -- "$file" \
| sed -n 's/^@@ -[0-9,]* +\([0-9]*\)\(,\([0-9]*\)\)\{0,1\} @@.*/\1 \3/p' \
| awk '{ count = ($2 == "" ? 1 : $2); if (count > 0) printf "%s%d-%d", sep, $1, $1 + count - 1; sep = "," }')
[ -n "$ranges" ] || continue
# shellcheck disable=SC2086 # $mode is one optional flag, deliberately split.
"$vfmt" $mode --lines "$ranges" "$file" || status=$?
done
exit $status