Skip to content

feat(rules): no-json-macro keeps json! out of the crates standard.toml lists - #31

Draft
PiquelChips wants to merge 1 commit into
feat/rule-inline-limitsfrom
feat/rule-no-json-macro
Draft

PiquelChips wants to merge 1 commit into
feat/rule-inline-limitsfrom
feat/rule-no-json-macro

Conversation

@PiquelChips

Copy link
Copy Markdown
Member

What and why

sourceorigin builds tokens and protocol documents from sourceorigin-common's structs, never json! (DP15). A json! document has a shape no type checks, so a misspelled claim or field ships silently. Clippy's disallowed-macros can't exempt tests, and sourceorigin's tests use json! about 300 times. no-json-macro fails on json! (any path, such as serde_json::json!) outside test code in the crates standard.toml lists:

no-json-macro = ["my_protocol"]
  • Test code is what inline-limits (feat(rules): inline-limits makes Durations with literals named constants #30) defines: test attributes, test cfgs, the files they declare, integration tests.
  • The check also sees a json! inside another macro's arguments, such as println!("{}", json!(…)).
  • A listed name that is no workspace crate is a violation, as in budget.
  • No --fix: the struct to serialize takes judgement.

Stacked on #30.

Testing

  • just check-changed feat/rule-inline-limits passes.
  • New fixture test: a listed crate's json! in a function and inside println! fail, and its #[test] passes. An unlisted crate passes. A listed name that is no crate fails at its line in standard.toml.

Measured on git archive copies of each repository's origin/main (since removed), with no-json-macro listing every workspace crate to show the most it would flag:

violations, every crate listed notes
sourceorigin e99cc0e6b 2 of 306 json!; { "error": "invalid_request" } in auth-sdk's logout route, and a form tag round-trip in auth-service's profile settings
piqueld a17710f52 121 103 in apps/piqueld; piqueld isn't bound by DP15 and lists nothing unless it opts in
DirkEngine 07e8ba44 0

For sourceorigin, listing the crates DP15 names makes this a two-line cleanup.

Checklist

  • The crate's README (its documentation on docs.rs) shows the change, and a repository's xtask can still follow it. (just readme, and no-json-macro in the configuration example.)
  • A change to the public API is noted for the next release, with what each repository's xtask must change. (A new Rule variant and standard.toml key; no xtask change.)
  • just check-changed passes.

Note

Written by Claude Opus 5.5 in Claude Code (via T3 Code)

Code outside tests in the crates no-json-macro lists invokes no json!, so
tokens and protocol documents come from typed structs. Clippy's
disallowed-macros can't exempt tests, which use json! freely.
@PiquelChips
PiquelChips force-pushed the feat/rule-no-json-macro branch from 72accb6 to d00bbc9 Compare November 22, 2026 22:17
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