Skip to content

Commit 63e0f79

Browse files
authored
Enable nonstandard_macro_braces and enforce [] for children! (#17974)
# Objective - [`nonstandard_macro_braces`](https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces) is a Clippy lint that enforces what braces certain known macros are allowed to use. - For instance, requiring `println!()` instead of `println!{}`. - I started working on this after seeing TheBevyFlock/bevy_cli#277. ## Solution - Enable `nonstandard_macro_braces` in the workspace. - Configure Clippy so it enforces `[]` braces for `children!`. ## Testing 1. Create `examples/clippy_test.rs`. 2. Paste the following code: ```rust //! Some docs woooooooo use bevy::prelude::*; fn main() { let _ = children!(Name::new("Foo")); } ``` 3. Run `cargo clippy --example clippy_test`. 4. Ensure the following warning is emitted: ```sh warning: use of irregular braces for `children!` macro --> examples/clippy_test.rs:6:13 | 6 | let _ = children!(Name::new("Foo")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `children![Name::new("Foo")]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: requested on the command line with `-W clippy::nonstandard-macro-braces` warning: `bevy` (example "clippy_test") generated 1 warning (run `cargo clippy --fix --example "clippy_test"` to apply 1 suggestion) ```
1 parent f3b2139 commit 63e0f79

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ undocumented_unsafe_blocks = "warn"
4646
unwrap_or_default = "warn"
4747
needless_lifetimes = "allow"
4848
too_many_arguments = "allow"
49+
nonstandard_macro_braces = "warn"
4950

5051
ptr_as_ptr = "warn"
5152
ptr_cast_constness = "warn"
@@ -91,6 +92,7 @@ undocumented_unsafe_blocks = "warn"
9192
unwrap_or_default = "warn"
9293
needless_lifetimes = "allow"
9394
too_many_arguments = "allow"
95+
nonstandard_macro_braces = "warn"
9496

9597
ptr_as_ptr = "warn"
9698
ptr_cast_constness = "warn"

benches/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ undocumented_unsafe_blocks = "warn"
5050
unwrap_or_default = "warn"
5151
needless_lifetimes = "allow"
5252
too_many_arguments = "allow"
53+
nonstandard_macro_braces = "warn"
5354

5455
ptr_as_ptr = "warn"
5556
ptr_cast_constness = "warn"

clippy.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ disallowed-methods = [
4343
{ path = "f32::atanh", reason = "use bevy_math::ops::atanh instead for libm determinism" },
4444
{ path = "criterion::black_box", reason = "use core::hint::black_box instead" },
4545
]
46+
47+
# Require `bevy_ecs::children!` to use `[]` braces, instead of `()` or `{}`.
48+
standard-macro-braces = [{ name = "children", brace = "[" }]

0 commit comments

Comments
 (0)