Skip to content

Latest commit

 

History

History
93 lines (72 loc) · 15.3 KB

generated-code-markers.md

File metadata and controls

93 lines (72 loc) · 15.3 KB

Generated-Code Markers

Measured 2026-10-23 with the development build of Locmetry 0.9.0 at commit f413a59 (--no-user-config, release build) on shallow clones, removed afterwards. Question: which signals identify generated code inside module layouts without false claims, so that it no longer counts silently as hand-written implementation? The framework layout precision pass found such code to be the largest silent false claim; the prior-art record chose GitHub Linguist's checks as the starting evidence. The generated-code markers proposal uses these results.

Method

A script read the leading comment block of every source file Locmetry reported (the lines before the first line that is neither blank nor a comment) and its first 30 to 60 lines, and evaluated each candidate signal separately. Two groups of repositories were measured:

Hand-written lists served as oracles: the generated rule of the Loki policy and the generated overrides of the Immich policy.

Signals and their sources

Signal Source Result
Go's line ^// Code generated .* DO NOT EDIT\.$ before the first non-comment, non-blank text go help generate No false claim found among 7,108 matched files: every match in the Go generator repositories outside conventional generated names such as .pb.go, _string.go and testdata/ was read and is generated, including files a tool copied. Applications: Loki 2,037 files, gin-vue-admin 9,307 lines, Answer 594 lines
Linguist's looser Go check: ^// Code generated anywhere in the first 40 lines Linguist generated.rb 73ee9a3b277f False claim: gopls's hand-written generator gopls/internal/protocol/command/gen/gen.go, whose output template follows the package clause
Roslyn's rule: C# or VB file names ending .designer, .generated, .g or .g.i before the extension, case-insensitive, or starting TemporaryGeneratedFile_; a leading comment containing <auto-generated or <autogenerated Roslyn GeneratedCodeUtilities.cs a53af1f55e32; .NET code analysis options No false claim. Bitwarden 492 files, 1,034,108 lines; Jellyfin 59 files, 56,786 lines. The comment check covers every name match plus the EF Core model snapshots and two older migrations; EF writes a byte-order mark before the comment, which a check must skip. Generators: every production match in EF Core, 21 files, is a resource designer or T4 output, and all four in CommunityToolkit are T4 output; three hand-written EF Core generators that emit // <auto-generated /> from code are not matched, because the check reads only the leading comment
.gitattributes paths marked linguist-generated GitHub: customizing how changed files appear Declared in 3 of 18 repositories: Polar 363 files, 223,144 lines (its generated Python and TypeScript SDKs), Saleor 465 files, 17,064 lines (*_auto_*.py migrations), Loki 5 vendored files. The declarations are the projects' own; Polar's include SDK tests and tool configuration, and Saleor's *_auto_* pattern covers 62 migrations, 3,464 lines, that contain hand-written data code
Django's migration header # Generated by Django <version> on <date> on the first line Django's migration writer Saleor 1,293 files, 44,770 lines, all in migrations/; Django's own hand-written test migrations carry no header. False claim: the header stays when developers add code, and 268 of Saleor's headed migrations, 15,540 lines, define data functions, RunPython or RunSQL, such as the 397-line product/migrations/0183_calculate_discounted_prices.py
OpenAPI Generator's manifest .openapi-generator/FILES Shown only in a log excerpt of the file post-processing docs a03c03d2ace1; the customization docs do not describe it Halo 346 files, 21,459 lines, exactly its ui/packages/api-client
OpenAPI Generator named in a header line Generator templates False claim: Immich's hand-written open-api/bin/generate-dart-sdk.sh, which calls openapi-generator-cli
@generated in the leading comment Practice of Meta's tools; Arcanist's generated linter honors it (Phorge T15021) No false claim: Relay's 1,882 signed artifacts and fixture tests, 12 vendored go.uber.org/atomic files in Loki
Path __generated__/ Linguist; Relay's artifact folders Relay 1,767 files, all artifacts
Tool-specific headers Linguist checks (protocol buffer compiler, Thrift, jOOQ, Cython, gRPC C++, Dart build_runner, JFlex, Racc, PEG.js, Jison) Linguist generated.rb No match in any measured repository
MyBatis Generator's @mbg.generated Generator documentation False claim: MergeConstants.java in MyBatis Generator's production source; mall's 82% generated code carries no marker at all
Any line saying the file is generated near "do not edit" or similar, in the first 30 lines None; a heuristic False claims in production: sqlc's internal/goldeneye/*/install.go and internal/engine/duckdb/seed.go, protobuf-go's runtime/protoimpl/version.go, gopls's gen.go

Coverage in applications

Code lines of production that module layouts claim, and the share the signals would reclassify. "Documented" is Go's line, Roslyn's rule and .gitattributes; "with optional" adds Django's header, OpenAPI Generator's manifest, @generated and __generated__/.

Application Module production Documented With optional
mall 65,451 0% 0%
Halo 131,956 0% 16%
Answer 99,681 1% 1%
gin-vue-admin 69,465 13% 13%
Polar 576,106 37% 37%
Saleor 259,334 7% 18%
Loki 3,563,852 84%, of which 2,857,043 lines in vendor/ 84%
Jellyfin 217,302 26% 26%
Bitwarden 1,251,248 83% 83%
Immich 169,786 0% 0%
  • Against Loki's hand-written list, the documented signals find 50 of its 51 files, 130,084 of 130,204 lines. The one miss, tools/doc-generator/main.go, is a hand-written generator listed by mistake. They also find four counterfeiter fakes, 2,590 lines, that the list omits.
  • Immich's 38 hand-labelled files, 16,165 lines, carry no documented signal: the oazapfts SDK client has a free-form "DO NOT MODIFY" banner, and the SQL query snapshots a "NOTE: ... auto generated" comment.
  • Answer's swag documentation, 13,491 lines, says "Code generated by swaggo/swag. DO NOT EDIT" after a // Package docs prefix and without the final period, so Go's line does not match; golangci-lint loosened its own check for such tools.
  • Bitwarden's share is mostly EF Core designer files, which the unreleased dotnet-generated convention already classifies; Roslyn's comment check adds the model snapshots.

Java and Spring

Measured the same day with the same build, because the first round covered Java only through mall and Halo. Repositories:

Signal Source Result
@Generated from javax.annotation.processing, javax.annotation or jakarta.annotation, by qualified name or import, annotating the first top-level type Java SE javax.annotation.processing.Generated, which says the annotation can also mark generated parts of a hand-written file, so only the type position states the whole file No false claim. Applications: brapi-Java-TestServer 254 files, 22,809 lines, 53% of its module production; spatial-data-processor 29 files, 3,716 lines, 67%; every match names Swagger Codegen or OpenAPI Generator in the annotation and is a model or API interface; whether developers edited them since was not checked against history. The hand-written classes beside them in the same packages carry no annotation. Generators: 135 matches, all MapStruct's expected-output fixtures; hand-written generator source in Dagger, Hilt and Hibernate that writes the annotation as text is not matched
The same annotation anywhere in the file The same Three more matches, all tests: two hand-written tests that contain the annotation in string literals, and one MapStruct fixture whose class annotation the measurement script missed because a later annotation argument contains braces; an implementation must skip balanced annotation arguments
jOOQ's header This file is generated by jOOQ. in the leading comment Linguist generated_jooq?, which requires it in the first two lines container-auto-tune 141 files, 26,421 lines; killbill-qualpay-plugin 9 files, 862 lines; jOOQ's own jOOQ-meta 184 files. False claim: container-auto-tune's hand-written agent/twatch/ActionTemplate.java, whose author copied the header. Linguist's two-line position matches none of container-auto-tune's files, because a license header precedes the line
Protocol buffer compiler's header Linguist generated_protocol_buffer? No match; Maven and Gradle generate protocol buffer classes into target/ and build/
  • mall's MyBatis output and Halo carry no Java marker; jOOQ writes @Generated only when configured to, and container-auto-tune's jOOQ classes carry none.
  • Most generated Java never reaches a measurement: Maven and Gradle generate into target/ and build/, which projects ignore. The annotation matters for projects that commit generated sources, as both OpenAPI applications do.
  • A copied header is a false claim no position rule prevents; it appeared once among 141 jOOQ matches and not among the Go and .NET matches.

Acceptance Run

On 2026-10-23 the implementation (commit 341c057, release build, --no-user-config) measured twelve of the repositories above at their recorded commits; the shallow clones were removed afterwards. Marker-decided files and code lines:

Repository Marker Files Code lines Against the record
brapi-Java-TestServer java-generated-annotation 254 22,809 as recorded
spatial-data-processor java-generated-annotation 29 3,716 as recorded
Jellyfin roslyn-generated 59 56,786 as recorded
EF Core roslyn-generated 21 11,740 21 production matches; the first count of 25 was a miscount
gin-vue-admin go-generated-header 1 9,307 as recorded
Saleor linguist-generated 465 17,064 as recorded
Polar linguist-generated 327 215,532 the record's 363 files include declared tests, tool configuration and documentation, which earlier stages or the source-only rule keep
golang/tools, protobuf-go, sqlc go-generated-header 23, 182, 2,888 every match outside .pb.go, _string.go and testdata/ names a generator or copier in its header and is generated
Dagger, MapStruct — 0 no production match; MapStruct's annotated files are test fixtures

Conclusions

  • A marker that records where a file came from does not show that nobody edited it since: Django's header stays on hand-written data migrations.
  • Documented, position-bound markers made no false claim; every free-text heuristic did, including Linguist's own looser Go check. Generators' repositories are where marker strings occur in hand-written code, and only the position-bound checks survived them.
  • .gitattributes declarations cover what no marker can, such as Polar's SDKs, and are the project's own judgment.
  • Project-specific generators without a documented marker, as in mall and Immich, still need policy entries.
  • Vendored code dominates Loki's markers; whether vendored generated code is production at all is the separate Go vendor/ question in PLAN.