Skip to content

format: one name for one setting, and one place for a picture side - #92

Merged
donislawdev merged 1 commit into
mainfrom
format/one-name-one-setting
Sep 8, 2026
Merged

format: one name for one setting, and one place for a picture side#92
donislawdev merged 1 commit into
mainfrom
format/one-name-one-setting

Conversation

@donislawdev

Copy link
Copy Markdown
Owner

What this is

Width and height were declared from scratch in ten picture formats, and the
function reading them stood in all ten as well - the same twelve lines,
differing only in the format named inside its message. This gives them one
declaration and one reader, and adds the guards that keep an eleventh format
from drifting away from both.

Two of the three clusters of shared settings were already held together by a
shared package: the container axes and the text encoding. This is the third
and largest one.

What is shared, and what deliberately is not

internal/format/imagedim owns what cannot legitimately differ - the name,
that it is a whole number, that the smallest side is one pixel, that the
number counts pixels. Each format still supplies what was measured to differ
for a reason:

  • the largest side (20000 for five formats, 16384 for AVIF and JXL, 16383
    for WEBP, 256 for ICO - each is the ceiling of the thing itself)
  • the sentence, because an icon is not a picture and an SVG only says how
    wide it is
  • the default, which only SVG declares

The reader unifies on the best of the ten rather than the most common. Nine
built a string with fmt.Errorf. SVG returned format.PropertyValueError,
the same type the registry raises, so a reporter can ask for the parts by
name instead of parsing a sentence. The wording is SVG's, unchanged.

Guards

  • TestOneSettingNameMeansOneKindOfSetting - a name written by two formats
    has to describe the same kind of setting. Asks about Kind and Unit
    only, because Max, Default and Min diverge for reasons that were
    measured first. Asked of every registered format and every shared name, so
    a cluster that does not exist yet is covered on the day it arrives.
  • TestEveryDeliberateHomonymStillNamesTwoMeanings - the one deliberate
    homonym has to still be one, checked from both sides. entry_format is
    that homonym, and the guard banning it outright was written and deleted on
    2026-09-01 for reddening on it.
  • TestThePictureSideBackstopRefusesWhatTheDeclarationWould plus a control
    that it did not become a wall.

The debt this repays

The range check inside those ten copies could not be reached. The registry
refuses first in engine.go and recipe/target.go, the only two production
callers - png with width=999999 comes back as exit 4 with the sentence
built from the declaration - and nothing in internal/guard reached a
generator with a value outside its range. It is kept for the reason
textenc.Parse gives about its own branches, and keeping it moved the
burden to a test, which it now has.

Measured

  • tfg formats --json identical byte for byte, all twenty four declaration
    hashes unchanged
  • full suite green, gofmt and vet clean, preflight all checks passed
  • four new mutations, all caught. Three existing entries went stale when the
    ten helpers became one - found by staleness.py, repaired and re-run
  • net 88 lines added, 300 removed across the ten format packages

No changelog entry: nothing a user can observe has changed.

🤖 Generated with Claude Code

Twenty four formats declare seventy two settings under thirty nine names,
and thirteen of those names are written by more than one format. Nothing
compared them. Two of the clusters were already held together by a shared
package - the container axes and the text encoding - and the third, the
largest, was not: width and height were written out from scratch in ten
packages, and the function reading them stood in all ten as well, the same
twelve lines differing only in the format named inside its message.

internal/format/imagedim is that third package. What it owns is what cannot
legitimately differ: the name, that it is a whole number, that the smallest
side is one pixel, and that the number counts pixels. What each format still
supplies is what was measured to differ for a reason - the largest side, the
sentence, and the default that only SVG declares. The sentences are NOT
unified: an icon is not a picture and an SVG only says how wide it is, so
three of the four wordings would have become wrong.

The reader unifies on the best of the ten rather than the most common. Nine
built a string with fmt.Errorf and named the format inside it. SVG returned
format.PropertyValueError, the same type the registry itself raises, so what
reports it asks for the parts by name instead of parsing a sentence. The
wording is SVG's, unchanged.

Two guards keep the shape without forcing a false one. The first asks that a
name written by two formats describes the same kind of setting, in Kind and
Unit only - Max, Default and Min diverge for measured reasons, so asking
about them would redden on the legitimate case. The second asks that the one
deliberate homonym is still one, from both sides, because an excuse that
outlives its case reads as a rule. entry_format is that homonym: a log means
the shape of a log line by it where a container means the format of the
files it holds, which is why the guard banning it outright was deleted on
2026-09-01.

The range check under the ten was unreachable. The registry refuses first in
engine.go and recipe/target.go, the only two production callers - png with
width 999999 comes back as exit 4 with the sentence built from the
declaration - and nothing in internal/guard reached a generator with a value
outside its range. It is kept for the reason textenc.Parse gives about its
own branches, and keeping it moved the burden to a test, so it now has one,
with a control that it did not become a wall.

Measured after: tfg formats --json identical byte for byte, all twenty four
declaration hashes unchanged, full suite green, gofmt and vet clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@donislawdev
donislawdev merged commit 89be0a6 into main Sep 8, 2026
18 checks passed
@donislawdev
donislawdev deleted the format/one-name-one-setting branch September 8, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant