format: one name for one setting, and one place for a picture side - #92
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/imagedimowns 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:
for WEBP, 256 for ICO - each is the ceiling of the thing itself)
wide it is
The reader unifies on the best of the ten rather than the most common. Nine
built a string with
fmt.Errorf. SVG returnedformat.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 formatshas to describe the same kind of setting. Asks about
KindandUnitonly, because
Max,DefaultandMindiverge for reasons that weremeasured 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 deliberatehomonym has to still be one, checked from both sides.
entry_formatisthat homonym, and the guard banning it outright was written and deleted on
2026-09-01 for reddening on it.
TestThePictureSideBackstopRefusesWhatTheDeclarationWouldplus a controlthat 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.goandrecipe/target.go, the only two productioncallers -
pngwithwidth=999999comes back as exit 4 with the sentencebuilt from the declaration - and nothing in
internal/guardreached agenerator with a value outside its range. It is kept for the reason
textenc.Parsegives about its own branches, and keeping it moved theburden to a test, which it now has.
Measured
tfg formats --jsonidentical byte for byte, all twenty four declarationhashes unchanged
gofmtandvetclean, preflight all checks passedten helpers became one - found by
staleness.py, repaired and re-runNo changelog entry: nothing a user can observe has changed.
🤖 Generated with Claude Code