Skip to content

Commit

Permalink
feat: use improved declare_lint_pass macro #228
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAlbrecht committed Jan 21, 2025
1 parent da7c05a commit 33f45af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 8 additions & 18 deletions bevy_lint/src/lints/cargo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::declare_bevy_lint;
use crate::{declare_bevy_lint, declare_bevy_lint_pass};
use cargo_metadata::MetadataCommand;
use clippy_utils::{diagnostics::span_lint, sym};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{impl_lint_pass, utils::was_invoked_from_cargo};
use rustc_session::utils::was_invoked_from_cargo;
use rustc_span::{BytePos, Pos, SourceFile, Span, Symbol, SyntaxContext};
use serde::Deserialize;
use std::{collections::BTreeMap, ops::Range};
Expand All @@ -16,21 +16,11 @@ declare_bevy_lint! {
"duplicate bevy dependencies",
}

impl_lint_pass!(Cargo => [
DUPLICATE_BEVY_DEPENDENCIES.lint
]);

pub struct Cargo {
/// A cached [`Symbol`] representing the interned string `"bevy"`.
bevy_symbol: Symbol,
}

impl Default for Cargo {
fn default() -> Self {
Self {
bevy_symbol: sym!(bevy),
}
}
declare_bevy_lint_pass! {
pub Cargo => [DUPLICATE_BEVY_DEPENDENCIES.lint],
@default = {
bevy: Symbol = sym!(bevy),
},
}

impl LateLintPass<'_> for Cargo {
Expand All @@ -42,7 +32,7 @@ impl LateLintPass<'_> for Cargo {

match MetadataCommand::new().exec() {
Ok(metadata) => {
duplicate_bevy_dependencies::check(cx, &metadata, self.bevy_symbol);
duplicate_bevy_dependencies::check(cx, &metadata, self.bevy);
}
Err(e) => {
span_lint(
Expand Down
1 change: 1 addition & 0 deletions bevy_lint/src/lints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ pub(crate) fn register_passes(store: &mut LintStore) {
Box::new(plugin_not_ending_in_plugin::PluginNotEndingInPlugin::default())
});
store.register_late_pass(|_| Box::new(zst_query::ZstQuery::default()));
store.register_late_pass(|_| Box::new(cargo::Cargo::default()));
}

0 comments on commit 33f45af

Please sign in to comment.