Skip to content

Commit 18eda6e

Browse files
committed
feat: switch to PathLookups in paths
1 parent 0a3cddb commit 18eda6e

File tree

2 files changed

+108
-48
lines changed

2 files changed

+108
-48
lines changed

bevy_lint/src/paths.rs

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,67 @@
1-
//! A collection of hardcoded types and functions that the linter uses.
1+
//! A collection of hardcoded type and function paths that the linter uses.
22
//!
33
//! Since Bevy is a 3rd-party crate, we cannot easily add diagnostic items to it. In lieu of this,
44
//! we hardcode the paths to the items we need here, for easy referencing.
5-
//!
6-
//! Also see: [`match_type()`](clippy_utils::ty::match_type),
7-
//! [`match_def_path()`](clippy_utils::match_def_path).
85
9-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_app/src/app.rs#L78>
10-
pub const APP: [&str; 3] = ["bevy_app", "app", "App"];
11-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/system/commands/command.rs#L48>
12-
pub const COMMANDS: [&str; 4] = ["bevy_ecs", "system", "commands", "Commands"];
13-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/component.rs#L456>
14-
pub const COMPONENT: [&str; 3] = ["bevy_ecs", "component", "Component"];
15-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/system/system_param.rs#L1378>
16-
pub const DEFERRED: [&str; 4] = ["bevy_ecs", "system", "system_param", "Deferred"];
17-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/world/deferred_world.rs#L23>
18-
pub const DEFERRED_WORLD: [&str; 4] = ["bevy_ecs", "world", "deferred_world", "DeferredWorld"];
19-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/system/commands/mod.rs#L1167>
20-
pub const ENTITY_COMMANDS: [&str; 4] = ["bevy_ecs", "system", "commands", "EntityCommands"];
21-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/world/entity_ref.rs#L448>
22-
pub const ENTITY_MUT: [&str; 4] = ["bevy_ecs", "world", "entity_ref", "EntityMut"];
23-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/event/base.rs#L48>
24-
pub const EVENT: [&str; 4] = ["bevy_ecs", "event", "base", "Event"];
25-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/event/collections.rs#L94>
26-
pub const EVENTS: [&str; 4] = ["bevy_ecs", "event", "collections", "Events"];
27-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/world/entity_ref.rs#L3687>
28-
pub const FILTERED_ENTITY_MUT: [&str; 4] = ["bevy_ecs", "world", "entity_ref", "FilteredEntityMut"];
29-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/change_detection.rs#L920>
30-
pub const MUT: [&str; 3] = ["bevy_ecs", "change_detection", "Mut"];
31-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/change_detection.rs#L1020>
32-
pub const MUT_UNTYPED: [&str; 3] = ["bevy_ecs", "change_detection", "MutUntyped"];
33-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/change_detection.rs#L734>
34-
pub const NON_SEND_MUT: [&str; 3] = ["bevy_ecs", "change_detection", "NonSendMut"];
6+
use clippy_utils::paths::{PathLookup, PathNS};
7+
8+
use crate::sym;
9+
10+
/// Returns a new [`PathLookup`] in the [type namespace](PathNS::Type) for a given path.
11+
///
12+
/// `type_path!()` takes a `::`-separated list of identifiers. Each identifier should correspond to
13+
/// a [`Symbol`](rustc_span::Symbol) in [`crate::sym`]. For example,
14+
/// `type_path!(bevy_app::app::App)` creates a [`PathLookup`] in the [`PathNS::Type`] namespace
15+
/// with the path `[sym::bevy_app, sym::app, sym::App]`.
16+
macro_rules! type_path {
17+
($first:ident $(:: $remaining:ident)*) => {
18+
PathLookup::new(PathNS::Type, &[sym::$first, $(sym::$remaining),*])
19+
};
20+
}
21+
22+
// Keep the following list alphabetically sorted :)
23+
24+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_app/src/app.rs#L78>
25+
pub static APP: PathLookup = type_path!(bevy_app::app::App);
26+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/system/commands/mod.rs#L101>
27+
pub static COMMANDS: PathLookup = type_path!(bevy_ecs::system::commands::Commands);
28+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/component.rs#L485>
29+
pub static COMPONENT: PathLookup = type_path!(bevy_ecs::component::Component);
30+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/world/deferred_world.rs#L23>
31+
pub static DEFERRED_WORLD: PathLookup = type_path!(bevy_ecs::world::deferred_world::DeferredWorld);
32+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/system/system_param.rs#L1415>
33+
pub static DEFERRED: PathLookup = type_path!(bevy_ecs::system::system_param::Deferred);
34+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/system/commands/mod.rs#L1233>
35+
pub static ENTITY_COMMANDS: PathLookup = type_path!(bevy_ecs::system::commands::EntityCommands);
36+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/world/entity_ref.rs#L448>
37+
pub static ENTITY_MUT: PathLookup = type_path!(bevy_ecs::world::entity_ref::EntityMut);
38+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/event/base.rs#L48>
39+
pub static EVENT: PathLookup = type_path!(bevy_ecs::event::base::Event);
40+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/event/collections.rs#L94>
41+
pub static EVENTS: PathLookup = type_path!(bevy_ecs::event::collections::Events);
42+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/world/entity_ref.rs#L3687>
43+
pub static FILTERED_ENTITY_MUT: PathLookup = type_path!(bevy_ecs::world::entity_ref::FilteredEntityMut);
44+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/change_detection.rs#L1059>
45+
pub static MUT_UNTYPED: PathLookup = type_path!(bevy_ecs::change_detection::MutUntyped);
46+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/change_detection.rs#L959>
47+
pub static MUT: PathLookup = type_path!(bevy_ecs::change_detection::Mut);
48+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/change_detection.rs#L773>
49+
pub static NON_SEND_MUT: PathLookup = type_path!(bevy_ecs::change_detection::NonSendMut);
3550
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_reflect/src/reflect.rs#L84>
36-
pub const PARTIAL_REFLECT: [&str; 3] = ["bevy_reflect", "reflect", "PartialReflect"];
37-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_app/src/plugin.rs#L57>
38-
pub const PLUGIN: [&str; 3] = ["bevy_app", "plugin", "Plugin"];
39-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ptr/src/lib.rs#L178>
40-
pub const PTR_MUT: [&str; 2] = ["bevy_ptr", "PtrMut"];
41-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/system/query.rs#L379>
42-
pub const QUERY: [&str; 4] = ["bevy_ecs", "system", "query", "Query"];
43-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_reflect/src/reflect.rs#L413>
44-
pub const REFLECT: [&str; 3] = ["bevy_reflect", "reflect", "Reflect"];
45-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/change_detection.rs#L675>
46-
pub const RES_MUT: [&str; 3] = ["bevy_ecs", "change_detection", "ResMut"];
47-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/resource.rs#L75>
48-
pub const RESOURCE: [&str; 3] = ["bevy_ecs", "resource", "Resource"];
49-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/schedule/set.rs>
50-
pub const SYSTEM_SET: [&str; 4] = ["bevy_ecs", "schedule", "set", "SystemSet"];
51-
/// <https://github.com/bevyengine/bevy/blob/release-0.16.0/crates/bevy_ecs/src/world/mod.rs#L94>
52-
pub const WORLD: [&str; 3] = ["bevy_ecs", "world", "World"];
51+
pub static PARTIAL_REFLECT: PathLookup = type_path!(bevy_reflect::reflect::PartialReflect);
52+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_app/src/plugin.rs#L57>
53+
pub static PLUGIN: PathLookup = type_path!(bevy_app::plugin::Plugin);
54+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ptr/src/lib.rs#L178>
55+
pub static PTR_MUT: PathLookup = type_path!(bevy_ptr::PtrMut);
56+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/system/query.rs#L482>
57+
pub static QUERY: PathLookup = type_path!(bevy_ecs::system::query::Query);
58+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_reflect/src/reflect.rs#L413>
59+
pub static REFLECT: PathLookup = type_path!(bevy_reflect::reflect::Reflect);
60+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/change_detection.rs#L714>
61+
pub static RES_MUT: PathLookup = type_path!(bevy_ecs::change_detection::ResMut);
62+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/resource.rs#L75>
63+
pub static RESOURCE: PathLookup = type_path!(bevy_ecs::resource::Resource);
64+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/schedule/set.rs#L35>
65+
pub static SYSTEM_SET: PathLookup = type_path!(bevy_ecs::schedule::set::SystemSet);
66+
/// <https://github.com/bevyengine/bevy/blob/v0.16.0/crates/bevy_ecs/src/world/mod.rs#L94>
67+
pub static WORLD: PathLookup = type_path!(bevy_ecs::world::World);

bevy_lint/src/sym.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,55 @@ macro_rules! declare_bevy_symbols {
5959
}
6060

6161
declare_bevy_symbols! {
62+
// Keep this list alphabetically sorted :)
63+
app,
64+
App,
65+
base,
66+
bevy_app,
67+
bevy_ecs,
68+
bevy_ptr,
69+
bevy_reflect,
6270
bevy,
71+
change_detection,
72+
collections,
73+
commands,
74+
Commands,
75+
component,
76+
Component,
77+
deferred_world,
78+
Deferred,
79+
DeferredWorld,
80+
entity_ref,
81+
EntityCommands,
82+
EntityMut,
83+
event,
84+
Event,
85+
Events,
86+
FilteredEntityMut,
6387
init_resource,
6488
insert_resource,
6589
iter_current_update_events,
66-
spawn,
90+
Mut,
91+
MutUntyped,
92+
NonSendMut,
93+
PartialReflect,
94+
plugin,
95+
Plugin,
96+
PtrMut,
97+
query,
98+
Query,
99+
reflect,
100+
Reflect,
101+
ResMut,
102+
resource,
103+
Resource,
67104
run,
105+
schedule,
106+
set,
107+
spawn,
108+
system_param,
109+
system,
110+
SystemSet,
111+
world,
112+
World,
68113
}

0 commit comments

Comments
 (0)