From 63e0f794d1b577d0c30d2dc9468681edbf9f5fab Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 21 Feb 2025 20:54:49 -0500 Subject: [PATCH] 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 https://github.com/TheBevyFlock/bevy_cli/issues/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) ``` --- Cargo.toml | 2 ++ benches/Cargo.toml | 1 + clippy.toml | 3 +++ 3 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f5efb88019..deaf9cfd6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ undocumented_unsafe_blocks = "warn" unwrap_or_default = "warn" needless_lifetimes = "allow" too_many_arguments = "allow" +nonstandard_macro_braces = "warn" ptr_as_ptr = "warn" ptr_cast_constness = "warn" @@ -91,6 +92,7 @@ undocumented_unsafe_blocks = "warn" unwrap_or_default = "warn" needless_lifetimes = "allow" too_many_arguments = "allow" +nonstandard_macro_braces = "warn" ptr_as_ptr = "warn" ptr_cast_constness = "warn" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index d4b032eab0..4fc852d1a2 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -50,6 +50,7 @@ undocumented_unsafe_blocks = "warn" unwrap_or_default = "warn" needless_lifetimes = "allow" too_many_arguments = "allow" +nonstandard_macro_braces = "warn" ptr_as_ptr = "warn" ptr_cast_constness = "warn" diff --git a/clippy.toml b/clippy.toml index 26b39b4e84..2c98e8ed02 100644 --- a/clippy.toml +++ b/clippy.toml @@ -43,3 +43,6 @@ disallowed-methods = [ { path = "f32::atanh", reason = "use bevy_math::ops::atanh instead for libm determinism" }, { path = "criterion::black_box", reason = "use core::hint::black_box instead" }, ] + +# Require `bevy_ecs::children!` to use `[]` braces, instead of `()` or `{}`. +standard-macro-braces = [{ name = "children", brace = "[" }]