-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing_reflect
lint (attempt 2)
#139
Conversation
I want to write a few UI tests and the module documentation for this lint, but everything else is ready for review. :) |
One question: How does this handle types that cannot be struct NotReflect(f32);
#[derive(Component)]
struct MyComponent(NotReflect); It seems like there's two options for users here:
I think both are fine, but would it make sense (and/or be possible) to check if all fields are already |
I must admit, I didn't realize there weren't types that could be reflected. (Though thinking through it, it does make sense.) The lint currently doesn't care if it's impossible to implement
I think checking that all fields can implement For checking all fields, should I just check that they also implement
I'm not worried about performance too much right now. I'd much prefer the linter to be useful, smart, and feature-complete than zippy. (And there's some low-hanging fruit, should performance become arduous.) |
So this is where it can get a little confusing 😅 Always Required The traits that are always mandatory are Active Fields Then for active fields (i.e. fields not marked Reflection Bound Lastly, all active fields must implement either Since Generic Types And generic type parameters require So if we did want to handle cases with un-reflectable fields, it would be best if we checked for all of these. But if it's simpler to start with, I'd say the biggest one to check for is just There are other attributes to help users control these bounds (e.g. Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with merging this and moving the edge cases @MrGVSV described to a separate issue.
Their comment would serve as a great issue description.
Maybe we can even split this into two lints in the future: One for the simple cases where all fields implement Reflect, which would be machine applicable, and one for the cases where some fields require additional amnotations, which could be maybe incorrect.
Sounds good! I'm going to do some final touch-ups, then merge this as-is. |
Unfortunately due to #141, I had to switch the suggestion to With that, this PR is ready to go. Merging! |
Closes #54. See #137 for past attempt.
This adds a lint that lets users require all components, resources, and events derive
Reflect
.Reflect
is often used by tools such asbevy-inspector-egui
to view the state of the world while the game is running, but these tools are far less useful if they do not have access to reflection data.This lint is off by default, and intended to be used to require
Reflect
for types within specific modules. For example:Developers are free to require it throughout the entire crate, however.
#![deny(bevy::missing_reflect)]
This lint gives lots of information when it is raised, such as where the offending trait was implemented and how to fix it:
Thanks to
clippy_utils
'ssuggest_item_with_attr()
, the suggestion is machine applicable. This means thatcargo fix
can automatically fix this lint, making migrating a code base super easy.