ruma icon indicating copy to clipboard operation
ruma copied to clipboard

Disallow uses of `serde(flatten)` for single-body-field requests or responses

Open jplatte opened this issue 4 years ago • 4 comments

#[ruma_api(body)] does the same thing and is better in every way.

jplatte avatar Jan 27 '22 14:01 jplatte

Is there a lint of sorts that we could use for this? Or could we possibly detect this with the macros that wrap those requests/responses?

ShadowJonathan avatar Jan 27 '22 14:01 ShadowJonathan

There is no lint because this is a serde-specific thing, and library-specific lints don't really exist as of right now. Also the solution I suggested above is Ruma-specific too.

I've also thought about how we could lint about this. @DevinR528 has looked into that sort of thing before. Maybe dylint would be something to look into now that we have some internal lints we'd like to write that aren't suitable for clippy? Another one would be using #[serde(flatten)] on a Raw value in a struct that derives Deserialize without customizing that further, which will always fail (that's what lead to creating this issue).

jplatte avatar Jan 27 '22 15:01 jplatte

Something similar to files_are_tidy test in rust-analyzer can also be used. It is used in rust-analyzer for disallowing dbg! macros or TODO: comments to be committed in main branch. It is text based, so it will have more false positive rate than dylint, but it is easier to setup.

HKalbasi avatar Feb 12 '23 07:02 HKalbasi

I think we should just do this in the #[request] / #[response] macros as suggested by Jonathan.

jplatte avatar Mar 12 '23 10:03 jplatte