Skip to content

refactor(upickle): only usage scaladoc stays, each reason moves to a test or ADR 0011 - #429

Open
rcardin wants to merge 10 commits into
devfrom
refactor/no-comment-upickle
Open

rcardin wants to merge 10 commits into
devfrom
refactor/no-comment-upickle

Conversation

@rcardin

@rcardin rcardin commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The maintainer decided that a comment is allowed in one place only: scaladoc on a member of the public API, in main code, and that scaladoc tells a user how to use the member. Every other comment is refused, and that includes every comment in a test source, scaladoc on a private member, and history or design rationale in public scaladoc. The reason that a comment carried moves to a test whose name states it or to an ADR, and a constraint of a third party becomes a test that pins the behaviour of that third party.

This pull request applies the decision to modules/upickle. It is one of three pilot modules.

What

Comments refused by the rule, counted with a syntactic lint rule that is not in the build yet (one finding for each line comment line, one for each scaladoc):

Before After
Main sources 7 findings (7 private scaladocs) 0
Test sources 28 findings (19 scaladocs, 3 line comments: two paragraphs of 4 lines and one line) 0

The public scaladoc of idReadWriter stays as it was. The public scaladoc of serde keeps its usage text and loses its design rationale. Its last sentence is corrected: a Serde that the application gives for one model wins over the import at any level, not only at a nearer level. No module has a protected member, so no scaladoc of that kind was in scope.

Behaviour and public API do not change. The changes are: deleted comments, two ADRs, a suite LibraryConstraintsSuite with 4 tests that pin the behaviour of upickle and ujson, 3 new tests and 2 tests split out of others in the module's suites, one renamed test, and new names in tests. The module suite has 42 tests, 33 before.

ADRs

  • ADR 0011: the given serde builds the Serde from a upickle.default.ReadWriter, and derives one only for a case class. Rejected: derive each type with a Mirror; a given that is not inline; strict numbers through an Api of eezo's own.
  • ADR 0017: the Serde reads a body in two passes over its bytes, and builds no ujson.Value. Rejected: edit a parsed tree; one pass that sorts exceptions; Malformed for JSON that is not an object.

Both record decisions taken on issue #309 (and #328 for the decided fields). 0012 to 0016 are taken by refactor/no-comment-core, so bin/adr-next gave 0017. Neither ADR names a test or a private member.

Where each reason went

"Red under X" names a revert check of the next table: the production line was broken, the module suite was run, the named test went red, and the line was restored.

# File, comment Old text (short) Where the reason is now
1 UpickleSerde.scala, serde (public) "Only a case class is derived because List and Option are sums of the standard library too ... an error about :: or Some" ADR 0011, decision and option 1. Red under R4: "a collection of a model with no ReadWriter fails to compile naming the collection"
2 UpickleSerde.scala, serde (public) "anything else is asked for as an instance, so the compiler's message names the type at the summon site" usage, kept in the scaladoc. Red under RM2: "a type with neither an instance nor a shape to derive from fails to compile, naming it" and the collection test
3 UpickleSerde.scala, serde (public) "Inline because ... neither the instance nor the Mirror and ClassTag derivation needs resolves for an abstract A" ADR 0011, second paragraph, which names the author's ReadWriter, the Mirror and the ClassTag, and option 2. Red under M3: the suite does not compile; the first error is in "a model with no ReadWriter is derived, with its fields named as declared"
4 UpickleSerde.scala, serde (public) "Imported, so it sits in the caller's lexical scope and is found before any Serde in a model's companion" usage, kept in the scaladoc without "lexical scope". Test "the imported serde wins over a Serde in the model's companion", which pins a rule of the compiler (no eezo line makes it red)
5 UpickleSerde.scala, serde (public) "brings it into scope at a nearer level than this import for it to win" false: a probe showed that an application's Serde for one model also wins when the import of serde is nearer. The scaladoc now says "by a given or an import at any level". Test "a Serde the application gives for one model wins over the imported serde, at any level" (no eezo line makes it red)
6 UpickleSerde.scala, adapt "The one place the inline given hands off to compiled code ... compiled once ... stays out of the public API" deleted with no home (see below). M6 and T3a: nothing goes red
7 UpickleSerde.scala, UpickleSerde "It answers Either and throws nothing of eezo's: the HTTP status a failure earns is http's decision, and an adapter that threw would make it twice" the rule: red under M7, 11 tests, among them "a missing or wrongly typed field is Unfit, as one reason naming the field's path". The reason: ADR 0006, option "Sealed exceptions, kept" ("the one exhaustive match stays the only place a status is decided") and Consequences paragraph 1 (request.as[A] answers the Either by throwing)
8 UpickleSerde.scala, UpickleSerde "A JSON number becomes an Int or a Long the way upickle's own readers make it ... Strict readers would need an upickle Api of eezo's" ADR 0011, option 3 and Consequences. Red under R3: "a number with a fraction, in quotes or past the range of an Int reads as upickle reads it". Third party: "an upickle Api of eezo's own would not find the author's upickle.default ReadWriter"
9 UpickleSerde.scala, parsed "which step failed is what tells a body that was never JSON from one that was and did not fit" ADR 0017, decision and option 2. Red under R9: "a body that is not JSON, or no body at all, is Malformed with the cause and the path" and two tests of SerdeRouteSuite
10 UpickleSerde.scala, parsed "the parser walks the bytes with a stack of its own, so a body nested past any model costs no thread stack" ADR 0017, reason paragraph. Red under R3: "a body nested deeper than any model is refused as a failure, never thrown" (a StackOverflowError)
11 UpickleSerde.scala, fitted "Through no ujson.Value in between, because that tree holds every number as a Double ... StackOverflowError" ADR 0017, option 1. Red under R3: "an integer past what a Double holds reads back exactly, with or without a key" and 3 more. Third party: "a ujson.Value holds a Long past 2^53 as the nearest Double"
12 UpickleSerde.scala, fitted "goes through NoNulls because upickle takes a JSON null for the model and for any of its fields" red under R2: "a null field is Unfit at its path, whatever the field's type, with or without a key" and 2 more. Third party: "upickle alone reads a JSON null into a String field as null and into an Int field as 0"
13 UpickleSerde.scala, traced "upickle reports a failure as the JSON path, with the complaint as its cause, and both go in the one reason" red under R13: 9 tests, among them "a missing or wrongly typed field is Unfit, as one reason naming the field's path"
14 UpickleSerde.scala, traced "A complaint the model raised leaves out the byte offset the parser adds to it, because the path already says where" red under R1: "a complaint the model raises carries its JSON path and not the parser's byte offset" and 6 more. Third party: "upickle reports a model's complaint with the byte offset in its message, not in its clue"
15 UpickleSerde.scala, Decided "every field eezo decided put under its name ... as the text its key has on the wire" red under R15: "every name eezo decided wins over whatever the body carried there, and over nothing" and 12 more
16 UpickleSerde.scala, Decided "On the way past rather than by editing a parsed tree, for the same reasons" ADR 0017, decision and option 1
17 UpickleSerde.scala, Decided "skipped unread, as often as it names it ... decided values go in last" red under R6: "a decided name the body repeats, or spells with an escape, is skipped every time"
18 UpickleSerde.scala, Decided "A name is compared after the parser has undone its escapes" the same test: its body spells owner and id with escapes, so it goes red if ujson stops undoing escapes. No eezo line
19 UpickleSerde.scala, Decided "Anything but an object at the top goes to the model untouched, which refuses it in its own words" red under R19: "JSON that is not an object is Unfit for a record, with or without a key"
20 UpickleSerde.scala, NoNulls "at the top and in every field and element below it" red under R5: "a null field is Unfit at its path, whatever the field's type, with or without a key"
21 UpickleSerde.scala, NoNulls "null for a String, a key or a decimal ... boxed null that unboxes to 0" third party: "upickle alone reads a JSON null ..." (a String and an Int). Red under R2 for a key and a BigDecimal: the null field test
22 UpickleSerde.scala, NoNulls "the handler would meet the null later as a 500 rather than the client hearing a 422 now" the refusal: red under R2 (row 21). The 500 that would follow: deleted with no home (see below)
23 UpickleSerde.scala, NoNulls "A reader that gives null a meaning of its own, as an Option ... keeps it ... at its own path" red under R23: "a null the model reads as absent, or an id the key replaces, is not refused"; the path: red under R2
24 UpickleAdapterSuite.scala, suite "In a package outside io.eezo on purpose. The given is inline and expands here ..." deleted with no home (see below). T3b: three compile error tests go red, but only because their expected text names the package
25 UpickleAdapterSuite.scala, suite "No server is booted: the adapter knows nothing of HTTP, so its answers are read straight off the Serde" deleted with no home (see below)
26 UpickleAdapterSuite.scala, line comment "Decided against the ticket's four test rule, which calls a body that is not an object Malformed" ADR 0017, option 3. Red under K4: "a JSON array reads into a Serde of a list" and "JSON that is not an object is Unfit for a record, with or without a key"
27 UpickleAdapterSuite.scala, line comment "making them strict would mean an Api object of eezo's ... These pin what that choice lets through" ADR 0011, option 3; the number test names the three cases. Red under R3
28 SerdeRouteSuite.scala, suite "Inside the adapter's package, so its given is in scope here as it is after the import in an application, and so the routes can be built the way the generated table builds them" deleted with no home (see below). The compiler refuses Route.handwritten outside io.eezo, but the compiler is not a test
29 SerdeRouteSuite.scala, suite "Booted rather than called, because the status of a refusal is decided at the boundary ..." deleted with no home (see below). No commit body carries it
30 SerdeRouteSuite.scala, problem "The problem a refusal carries, read with the parser http's own suites read one with" deleted with no home (see below)
31 SerdeRouteSuite.scala, reason "What the adapter itself says about a body, which the problem's detail must repeat" restated: the helper is now adapterReason, and the 400 and 422 tests compare the detail with it. Red under R9 for the 400 tests
32 DerivedApiSuite.scala, Product "in a package of its own, with the adapter's given imported and nothing else, so the Serde derives Api asks for comes from that import alone" red under T12: "a program creates, reads and lists through upickle, under a key eezo minted" and the page test
33 DerivedApiSuite.scala, line comment "The row the program made is the row the page shows." test "the row a program creates through upickle is the row the page shows", which now reads the name and the cents on the page. Red under K6 and T12
34 DerivedApiSuite.scala, notes "the caller named off an X-User header the way a guard's token arm names it" restated: the value is currentUserFromHeader and the function ownedNotes. The comparison with a guard's token arm is deleted

13 more scaladocs restated the code or a test name and are deleted: 9 test models in UpickleAdapterSuite (Renamed, Plain, Order, Opaque, Holder, Tally, Line, Entry, Note), Basket in SerdeRouteSuite, and Clerk, Note and the suite scaladoc in DerivedApiSuite, with the first paragraphs of the two suite scaladocs of UpickleAdapterSuite and SerdeRouteSuite. For Tally, the domain example ("a 64 bit id or an amount in cents") is lost.

Revert checks

Each check breaks one line, runs bin/fast 'upickle/test' and restores the line. A test stays in this pull request only if a check of eezo code makes it red, or if it pins a behaviour of a third party that eezo depends on and that a version bump can change.

Check Line broken Tests that went red
R1 traced: abort.clue to abort.getMessage 7: "a complaint the model raises carries its JSON path and not the parser's byte offset", "a missing or wrongly typed field is Unfit, as one reason naming the field's path", and 5 more
R2 fitted reads through model, not NoNulls(model) 3: "a null field is Unfit at its path, whatever the field's type, with or without a key", "JSON that is not an object is Unfit for a record, with or without a key", "a field nobody decided is still required and refused null, ..."
R3 fitted reads through ujson.read, so through a ujson.Value 4: "an integer past what a Double holds reads back exactly, with or without a key", "a body nested deeper than any model is refused as a failure, never thrown", "a number with a fraction, in quotes or past the range of an Int reads as upickle reads it", "every name eezo decided wins over whatever the body carried there, and over nothing"
R4 serde: Mirror.ProductOf to Mirror.Of 1: "a collection of a model with no ReadWriter fails to compile naming the collection"
R5 NoNulls loses its visitArray 1: "a null field is Unfit at its path, whatever the field's type, with or without a key"
R6 Decided skips a decided name the first time only 1: "a decided name the body repeats, or spells with an escape, is skipped every time"
R9 deserialize(body) is fitted alone, with no parsed 3: "a body that is not JSON, or no body at all, is Malformed with the cause and the path", "a body that is not JSON answers 400 as problem+json, with the adapter's reason", "a request with no body that asks for one answers 400, never a 500"
R13 traced answers the complaint without the path 9, among them "a missing or wrongly typed field is Unfit, as one reason naming the field's path"
R15 Decided.visitEnd puts no decided value in 13, among them "every name eezo decided wins over whatever the body carried there, and over nothing"
R19 Decided refuses a top level array itself 1: "JSON that is not an object is Unfit for a record, with or without a key"
R23 NoNulls refuses every null, also one the model reads as None 2: "a null the model reads as absent, or an id the key replaces, is not refused", "every name eezo decided wins ..."
RM2 serde: the last case is compiletime.error and not a summon of ReadWriter[A] 2: "a type with neither an instance nor a shape to derive from fails to compile, naming it", the collection test
M3 serde is a given that is not inline, with using rw: ReadWriter[A] the test sources do not compile; first error in "a model with no ReadWriter is derived, with its fields named as declared"
M6 adapt is public none
M7 fitted throws IllegalArgumentException in place of Unfit 11, among them "a missing or wrongly typed field is Unfit, as one reason naming the field's path" and "JSON that does not fit the model answers 422 Unprocessable Content with the reason"
K4 deserialize(body) answers Malformed for a body that starts with [ 4: "a JSON array reads into a Serde of a list", "JSON that is not an object is Unfit for a record, with or without a key", and 2 more
K6 Decided skips every name of the body 14, among them "the row a program creates through upickle is the row the page shows"
T3a adapt is private[eezo] none
T3b UpickleAdapterSuite moves to package io.eezo.inside 3 compile error tests, because their expected text names elsewhere
T12 DerivedApiSuite.scala gets a second given api.Serde[Product] at the package level 2: "a program creates, reads and lists through upickle, under a key eezo minted", "the row a program creates through upickle is the row the page shows"

Each test this pull request adds or renames

Test Kept or removed Check that makes it red
"the imported serde wins over a Serde in the model's companion" (new) kept no eezo line. It pins the promise of the serde scaladoc on the given search of the Scala compiler, so a compiler that ranks givens otherwise makes it red
"a Serde the application gives for one model wins over the imported serde, at any level" (was "... brings into a nearer scope ...") repaired, kept no eezo line. It pins the corrected sentence of the serde scaladoc with a given at the package level and one in the test. The given ranking of Scala 3 changed in 3.7, so a bump can make it red
"a complaint the model raises carries its JSON path and not the parser's byte offset" (new) kept R1
"a JSON array reads into a Serde of a list" (split; was "a JSON array is never Malformed, since a Serde of a list reads it") kept K4
"a number with a fraction, in quotes or past the range of an Int reads as upickle reads it" (renamed) kept R3
"the row a program creates through upickle is the row the page shows" (split) repaired: it reads the name and the cents on the page, not only the status K6, T12
"upickle alone reads a JSON null into a String field as null and into an Int field as 0" (new) kept third party: red when upickle refuses a null itself, and then NoNulls can go
"upickle reports a model's complaint with the byte offset in its message, not in its clue" (new) repaired: it no longer asserts the full text of the message third party: red when upickle moves the offset into the clue or out of the message
"a ujson.Value holds a Long past 2^53 as the nearest Double" (was "..., so a Long past 2^53 comes back changed") kept third party: red when ujson keeps a large number exactly, and then option 1 of ADR 0017 opens again
"an upickle Api of eezo's own would not find the author's upickle.default ReadWriter" (new) kept; it now also asserts that the upickle.default instance is found third party: red when an Api of eezo's own sees the author's instance, and then option 3 of ADR 0011 opens again
"Scala finds no Mirror and no ClassTag for an abstract type parameter" removed a rule of the language: no change can make it red
"List and Option are sums with a Mirror of their own, as a sealed trait is" removed it cannot fail at run time; R4 makes the collection test red in its place
"the ujson parser reads a body nested 50000 deep with no thread stack" removed the same change of ujson makes "a body nested deeper than any model is refused as a failure, never thrown" red
"the ujson parser undoes the escapes of a name before a visitor sees it" removed it read the keys of a ujson.Value, not a visitor; the same change of ujson makes "a decided name the body repeats, or spells with an escape, is skipped every time" red

Reasons deleted with no home

These reasons fit neither a test nor an ADR, so they are deleted. The owner decides if they need a home, for example a section of the coding standards on how a suite is built.

  • UpickleSerde.scala, scaladoc of the private adapt: "The one place the inline given hands off to compiled code, so the class behind it is compiled once rather than copied into every call site, and stays out of the public API: an application writes serde, never this." A reason about a private member. M6 and T3a: nothing goes red.
  • UpickleSerde.scala, scaladoc of the private NoNulls, the part not pinned: "Without it, the handler would meet the null later as a 500 rather than the client hearing a 422 now." The refusal itself is pinned (R2).
  • UpickleAdapterSuite.scala, suite scaladoc: "In a package outside io.eezo on purpose. The given is inline and expands here, in the application's code, so whatever it reaches for has to be reachable from here at compile time and still be there at run time; a suite inside io.eezo would be let through by qualified access an application never has." A reason about how the suite is built. T3a and a probe that made the inline body call a private[eezo] member of core were both green in package elsewhere, so no check found the danger it names. T3b goes red only on the package name in three strings.
  • UpickleAdapterSuite.scala, suite scaladoc: "No server is booted: the adapter knows nothing of HTTP, so its answers are read straight off the Serde." A reason about how the suite is built. The acceptance criteria of issue api.Serde and eezo-upickle: a model crosses the wire as JSON in the dev's library #309 also say "its tests need no server".
  • SerdeRouteSuite.scala, suite scaladoc: "Inside the adapter's package, so its given is in scope here as it is after the import in an application, and so the routes can be built the way the generated table builds them." A reason about how the suite is built. The compiler refuses Route.handwritten outside io.eezo.
  • SerdeRouteSuite.scala, suite scaladoc: "Booted rather than called, because the status of a refusal is decided at the boundary and the content type of a JSON body where the response is written, and neither shows on the value a handler returns." A reason about how the suite is built.
  • SerdeRouteSuite.scala, scaladoc of problem: "The problem a refusal carries, read with the parser http's own suites read one with." A reason about how the suite is built: the parser that checks the problem is not the library under test.

Workarounds found

  • NoNulls in UpickleSerde.scala. Its scaladoc justified it by a behaviour of upickle: upickle.default reads a JSON null into a String as null and into an Int as 0. Kept, because upickle has no setting that refuses null. The test "upickle alone reads a JSON null into a String field as null and into an Int field as 0" pins the upickle behaviour, so it goes red if a later upickle refuses null itself and NoNulls can go.

Files to split

None. No file in the module had a section marker.

How to review

  1. Read ADR 0011 and ADR 0017. Each holds one decision, its rejected options and its consequences.
  2. Read the scaladoc of serde as a user of the given. It must say how to use it and nothing about why it is built so.
  3. Check each row of "Where each reason went" against the revert checks.
  4. Read "Reasons deleted with no home" and decide if any of them needs a home.

How it was tested

All runs on JDK 25.0.2.

  • bin/fast 'upickle/test': Passed: Total 42, Failed 0 (33 before this change).
  • The revert checks above.
  • The lint rule local.trusthooks:nocomment:0.1.0-ab947017159c, on main and test sources of upickle: 7 and 28 findings before, 0 and 0 after.
  • bin/fast 'upickle/scalafmtCheckAll': clean.
  • bin/prose-check on every changed file, on the commit messages and on this body: no offender.
  • bin/gate: GATE GREEN (format, prose, compile, test, plugin, examples, site).

🤖 Generated with Claude Code

…t comments

The scaladoc on each test model only told what the model and the test
name already say, so it goes.

The suite sits in the package elsewhere because the inline given expands
there as in an application: a suite inside io.eezo gets qualified access
that an application never has. A test now fails when the suite moves into
io.eezo.

JSON that is not an object is Unfit for a record and not Malformed. This
was decided against the four test rule of the ticket, which called such a
body Malformed. The reasons: [1,2] and 42 are JSON, the Serde seam puts
JSON that does not fit the model in Unfit, and the accepted spike gave the
same answer. Malformed would also refuse a payload that is a list or a
number, which a Serde of such a type reads. The list case is now a test of
its own.

The lenient number readers are a decision of ADR 0011; the test that pins
them now names all three cases it covers.

Two new tests pin what the private scaladoc of the adapter said: a
complaint the model raises carries its JSON path and not the parser's byte
offset, and upickle alone reads a JSON null into a String as null and into
an Int as 0, the behaviour NoNulls refuses.
Only the public API keeps scaladoc: idReadWriter and serde. The reasons
the private scaladoc carried now live where a check can find them.

ADR 0011 records how the adapter reads a body: two passes over the bytes,
so the pass that failed tells Malformed from Unfit; no ujson.Value tree,
so a large Long stays exact and a deep body costs no thread stack; the
decided fields put in while the body streams past; upickle's own lenient
number readers, because strict readers would need an upickle Api of
eezo's whose ReadWriter is a type apart from the author's.

ADR 0006 already says that the status of a failure is the decision of
http, so the adapter answers an Either and throws nothing of eezo's.

The tests of UpickleAdapterSuite pin the rules: the decided names, the
escapes and repeats, the null refusal at its path, the Option that keeps
its null, the reason with its JSON path and no byte offset.

One decision stays in this message. adapt is the one place where the
inline given hands off to compiled code. So UpickleSerde is compiled once
and not copied into each call site, and it stays out of the public API:
an application writes serde, never adapt.
SerdeRouteSuite boots a server and does not call the handler, because the
status of a refusal is decided at the boundary and the content type of a
JSON body where the response is written. Neither shows on the value a
handler returns. The suite sits in io.eezo.json.upickle so that the
adapter's given is in scope without an import and Route.handwritten,
which is private to eezo, builds the routes; the compiler pins both. The
helper that reads what the adapter says about a body is now adapterReason.

In DerivedApiSuite, the line that said a row a program creates is the row
the page shows is now a test with that name. The guard that names the
caller from the X-User header is now the value callerFromUserHeader, and
the note store with one row of grace's is ownedNotes. The scaladoc on the
models and the suite told what their names and the test names say.
@rcardin rcardin added the json label Nov 24, 2026
… adapter rests on

LibraryConstraintsSuite holds one test for each third party constraint
that ADR 0011 names. The test of upickle's null reading moves there.

Two new tests in UpickleAdapterSuite pin the scope rule that the scaladoc
of serde tells a user: the imported serde wins over a Serde in the model's
companion, and a Serde in a nearer scope wins over the import.

The test of the suite's package goes. Three tests already assert compile
errors that name elsewhere.Plain and elsewhere.Opaque, so they go red when
the suite moves to another package.
…s the design

The scaladoc of serde told why only a case class is derived and why the
given is inline. That text is design, so it moves to ADR 0011. The
scaladoc keeps what a user needs: which instance wins, how far
derivation goes, where the compiler names a missing instance, and how
an application's own Serde wins.

ADR 0011 now also records the inline given and adapt, the rejected
option that calls JSON that is not an object Malformed, and the tests
of LibraryConstraintsSuite. Its title and file name say both decisions.
@rcardin rcardin changed the title refactor(upickle): only public scaladoc stays, each reason moves to a test, a name, ADR 0011 or a commit body refactor(upickle): only usage scaladoc stays, each reason moves to a test or ADR 0011 Nov 24, 2026
… scaladoc states it

The scaladoc of serde says that a Serde the application gives for one
model wins at any level. The test checks a given at the package level and
one in the test. The array test has a name with no clause of reason.
…bump can make red

Deleted: the Mirror and ClassTag test, the List and Option Mirror test,
the nesting test and the escape test. The suite has its own models. The
offset test no longer asserts the full message text.
The show page must contain the name and the cents of the created row.
The guard value is currentUserFromHeader, the word of CONTEXT.md.
…o passes

Each record has one decision, its rejected options and its consequences.
The NOTE paragraphs and the lists of test names are gone.
Branch refactor/no-comment-core holds 0012 to 0016, so bin/adr-next gives 0017.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant