Skip to content
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

feat: initial duplicate bevy version lint #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DaAlbrecht
Copy link

@DaAlbrecht DaAlbrecht commented Nov 27, 2024

A first draft of a quick lint to check if multiple versions of bevy are defined. #15

todos:

  • crate ui test
  • better error message, perhaps use cargo metadata to get information about the crate versions.
  • fix the span ( this should point to the crate causing the issue in the Cargo.toml)
error: Multiple versions of `bevy` found
  --> /Users/didi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy-0.13.2/src/lib.rs:1:1
   |
1  | / #![allow(clippy::single_component_path_imports)]
2  | |
3  | | //! [![](https://bevyengine.org/assets/bevy_logo_d...
4  | | //!
...  |
51 | | #[allow(unused_imports)]
52 | | use bevy_dylib;
   | |_______________^
   |
   = note: `#[deny(bevy::duplicate_bevy_dependencies)]` on by default

Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far this looks good! I am interested in getting a span to Cargo.toml / Cargo.lock, though I'm unsure if the compiler will know that file exists. Ping me when this is ready for a final review!


impl<'tcx> LateLintPass<'tcx> for DuplicateBevyDependencies {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
let bevy_crates = find_crates(cx.tcx, Symbol::intern("bevy"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nit) Calling Symbol::intern() / sym!() is an expensive operation that should probably be cached. I solve this by storing the Symbol as a field in the lint pass in #184.

// Sketch of what you may do...
struct DuplicateBevyDependencies {
    bevy_symbol: Symbol,
}

impl Default for DuplicateBevyDependencies {
    fn default() -> Self {
        Self { bevy_symbol: sym!(bevy) }
    }
}

// This is different from `declare_lint_pass!`, since it does not actually define the lint pass structure.
impl_lint_pass! {
    DuplicateBevyDependencies => [DUPLICATE_BEVY_DEPENDENCIES.lint]
}

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.

2 participants