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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bevy_lint/src/lints/duplicate_bevy_dependencies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Checks for multiple versions of `bevy` in the dependencies.
//!
//! # Motivation
//!
//! When different third party crates use incompatible versions of Bevy, it can lead to confusing
//! errors and type incompatibilities.

use crate::declare_bevy_lint;
use clippy_utils::{diagnostics::span_lint, find_crates, sym};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
use rustc_span::Symbol;

declare_bevy_lint! {
pub DUPLICATE_BEVY_DEPENDENCIES,
CORRECTNESS,
"duplicate bevy dependencies",
}

pub(crate) struct DuplicateBevyDependencies {
bevy_symbol: Symbol,
}

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

impl_lint_pass! {
DuplicateBevyDependencies => [DUPLICATE_BEVY_DEPENDENCIES.lint]
}

impl<'tcx> LateLintPass<'tcx> for DuplicateBevyDependencies {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
let bevy_crates = find_crates(cx.tcx, self.bevy_symbol);

if bevy_crates.len() > 1 {
let span = cx.tcx.def_span(bevy_crates[1].def_id());
span_lint(
cx,
DUPLICATE_BEVY_DEPENDENCIES.lint,
span,
"Multiple versions of `bevy` found",
);
}
}
}
5 changes: 5 additions & 0 deletions bevy_lint/src/lints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::lint::BevyLint;
use rustc_lint::{Lint, LintStore};

pub mod duplicate_bevy_dependencies;
pub mod insert_event_resource;
pub mod main_return_without_appexit;
pub mod missing_reflect;
Expand All @@ -22,6 +23,7 @@ pub(crate) static LINTS: &[&BevyLint] = &[
panicking_methods::PANICKING_WORLD_METHODS,
plugin_not_ending_in_plugin::PLUGIN_NOT_ENDING_IN_PLUGIN,
zst_query::ZST_QUERY,
duplicate_bevy_dependencies::DUPLICATE_BEVY_DEPENDENCIES,
];

pub(crate) fn register_lints(store: &mut LintStore) {
Expand All @@ -36,4 +38,7 @@ pub(crate) fn register_passes(store: &mut LintStore) {
store.register_late_pass(|_| Box::new(panicking_methods::PanickingMethods));
store.register_late_pass(|_| Box::new(plugin_not_ending_in_plugin::PluginNotEndingInPlugin));
store.register_late_pass(|_| Box::new(zst_query::ZstQuery));
store.register_late_pass(|_| {
Box::new(duplicate_bevy_dependencies::DuplicateBevyDependencies::default())
});
}
Loading