mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Fix clippy warnings (#3085)
* Run clippy fix * Clippy v2 * Make const item static * Cargo fmt
This commit is contained in:
@@ -293,7 +293,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
|
||||
|
||||
let properties = &attributes.properties_string.as_ref().map(|value| quote!(Some(#value))).unwrap_or(quote!(None));
|
||||
|
||||
let cfg = crate::shader_nodes::modify_cfg(&attributes);
|
||||
let cfg = crate::shader_nodes::modify_cfg(attributes);
|
||||
let node_input_accessor = generate_node_input_references(parsed, fn_generics, &field_idents, &graphene_core, &identifier, &cfg);
|
||||
Ok(quote! {
|
||||
/// Underlying implementation for [#struct_name]
|
||||
@@ -323,6 +323,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
|
||||
|
||||
#cfg
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::module_inception)]
|
||||
mod #mod_name {
|
||||
use super::*;
|
||||
use #graphene_core as gcore;
|
||||
|
||||
@@ -117,7 +117,7 @@ fn derive_enum(enum_attributes: &[Attribute], name: Ident, input: syn::DataEnum)
|
||||
.map_err(|e| {
|
||||
syn::Error::new(
|
||||
Span::call_site(),
|
||||
format!("Failed to find location of 'graphene_core' or 'graphene-core-shaders'. Make sure it is imported as a dependency: {}", e),
|
||||
format!("Failed to find location of 'graphene_core' or 'graphene-core-shaders'. Make sure it is imported as a dependency: {e}"),
|
||||
)
|
||||
})?;
|
||||
match crate_name {
|
||||
|
||||
@@ -295,8 +295,8 @@ impl Parse for NodeFnAttributes {
|
||||
}
|
||||
|
||||
fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNodeFn> {
|
||||
let attributes = syn::parse2::<NodeFnAttributes>(attr.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse node_fn attributes: {}", e)))?;
|
||||
let input_fn = syn::parse2::<ItemFn>(item.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse function: {}. Make sure it's a valid Rust function.", e)))?;
|
||||
let attributes = syn::parse2::<NodeFnAttributes>(attr.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse node_fn attributes: {e}")))?;
|
||||
let input_fn = syn::parse2::<ItemFn>(item.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse function: {e}. Make sure it's a valid Rust function.")))?;
|
||||
|
||||
let vis = input_fn.vis;
|
||||
let fn_name = input_fn.sig.ident.clone();
|
||||
@@ -312,7 +312,7 @@ fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNo
|
||||
let crate_name = proc_macro_crate::crate_name("graphene-core").map_err(|e| {
|
||||
Error::new(
|
||||
proc_macro2::Span::call_site(),
|
||||
format!("Failed to find location of graphene_core. Make sure it is imported as a dependency: {}", e),
|
||||
format!("Failed to find location of graphene_core. Make sure it is imported as a dependency: {e}"),
|
||||
)
|
||||
})?;
|
||||
let description = input_fn
|
||||
@@ -405,7 +405,7 @@ fn parse_implementations(attr: &Attribute, name: &Ident) -> syn::Result<Punctuat
|
||||
let parser = Punctuated::<Type, Comma>::parse_terminated;
|
||||
parser.parse2(content.clone()).map_err(|e| {
|
||||
let span = e.span(); // Get the span of the error
|
||||
Error::new(span, format!("Failed to parse implementations for argument '{}': {}", name, e))
|
||||
Error::new(span, format!("Failed to parse implementations for argument '{name}': {e}"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -431,27 +431,21 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
let ident = &pat_ident.ident;
|
||||
|
||||
let default_value = extract_attribute(attrs, "default")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `default` value for argument '{}': {}", ident, e)))
|
||||
})
|
||||
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `default` value for argument '{ident}': {e}"))))
|
||||
.transpose()?;
|
||||
|
||||
let scope = extract_attribute(attrs, "scope")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `scope` value for argument '{}': {}", ident, e)))
|
||||
})
|
||||
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `scope` value for argument '{ident}': {e}"))))
|
||||
.transpose()?;
|
||||
|
||||
let name = extract_attribute(attrs, "name")
|
||||
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `name` value for argument '{}': {}", ident, e))))
|
||||
.map(|attr| attr.parse_args().map_err(|e| Error::new_spanned(attr, format!("Invalid `name` value for argument '{ident}': {e}"))))
|
||||
.transpose()?;
|
||||
|
||||
let widget_override = extract_attribute(attrs, "widget")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `widget override` value for argument '{}': {}", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `widget override` value for argument '{ident}': {e}")))
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or_default();
|
||||
@@ -468,26 +462,26 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
let number_soft_min = extract_attribute(attrs, "soft_min")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_min` value for argument '{}': {}", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_min` value for argument '{ident}': {e}")))
|
||||
})
|
||||
.transpose()?;
|
||||
let number_soft_max = extract_attribute(attrs, "soft_max")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_max` value for argument '{}': {}", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `soft_max` value for argument '{ident}': {e}")))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let number_hard_min = extract_attribute(attrs, "hard_min")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_min` value for argument '{}': {}", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_min` value for argument '{ident}': {e}")))
|
||||
})
|
||||
.transpose()?;
|
||||
let number_hard_max = extract_attribute(attrs, "hard_max")
|
||||
.map(|attr| {
|
||||
attr.parse_args()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_max` value for argument '{}': {}", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid numerical `hard_max` value for argument '{ident}': {e}")))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
@@ -496,10 +490,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
attr.parse_args::<ExprTuple>().map_err(|e| {
|
||||
Error::new_spanned(
|
||||
attr,
|
||||
format!(
|
||||
"Invalid `range` tuple of min and max range slider values for argument '{}': {}\nUSAGE EXAMPLE: #[range((0., 100.))]",
|
||||
ident, e
|
||||
),
|
||||
format!("Invalid `range` tuple of min and max range slider values for argument '{ident}': {e}\nUSAGE EXAMPLE: #[range((0., 100.))]"),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -511,7 +502,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
}
|
||||
|
||||
let unit = extract_attribute(attrs, "unit")
|
||||
.map(|attr| attr.parse_args::<LitStr>().map_err(|_e| Error::new_spanned(attr, format!("Expected a unit type as string"))))
|
||||
.map(|attr| attr.parse_args::<LitStr>().map_err(|_e| Error::new_spanned(attr, "Expected a unit type as string".to_string())))
|
||||
.transpose()?;
|
||||
|
||||
let number_display_decimal_places = extract_attribute(attrs, "display_decimal_places")
|
||||
@@ -519,14 +510,14 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
attr.parse_args::<LitInt>().map_err(|e| {
|
||||
Error::new_spanned(
|
||||
attr,
|
||||
format!("Invalid `integer` for number of decimals for argument '{}': {}\nUSAGE EXAMPLE: #[display_decimal_places(2)]", ident, e),
|
||||
format!("Invalid `integer` for number of decimals for argument '{ident}': {e}\nUSAGE EXAMPLE: #[display_decimal_places(2)]"),
|
||||
)
|
||||
})
|
||||
})
|
||||
.transpose()?
|
||||
.map(|f| {
|
||||
if let Err(e) = f.base10_parse::<u32>() {
|
||||
Err(Error::new_spanned(f, format!("Expected a `u32` for `display_decimal_places` for '{}': {}", ident, e)))
|
||||
Err(Error::new_spanned(f, format!("Expected a `u32` for `display_decimal_places` for '{ident}': {e}")))
|
||||
} else {
|
||||
Ok(f)
|
||||
}
|
||||
@@ -535,7 +526,7 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
let number_step = extract_attribute(attrs, "step")
|
||||
.map(|attr| {
|
||||
attr.parse_args::<LitFloat>()
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `step` for argument '{}': {}\nUSAGE EXAMPLE: #[step(2.)]", ident, e)))
|
||||
.map_err(|e| Error::new_spanned(attr, format!("Invalid `step` for argument '{ident}': {e}\nUSAGE EXAMPLE: #[step(2.)]")))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
@@ -660,7 +651,7 @@ pub fn new_node_fn(attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
|
||||
Ok(parsed) => parsed,
|
||||
Err(e) => {
|
||||
// Return the error as a compile error
|
||||
Error::new(e.span(), format!("Failed to parse node function: {}", e)).to_compile_error()
|
||||
Error::new(e.span(), format!("Failed to parse node function: {e}")).to_compile_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -757,7 +748,7 @@ mod tests {
|
||||
}
|
||||
_ => panic!("Mismatched default values"),
|
||||
}
|
||||
assert_eq!(format!("{:?}", p_ty), format!("{:?}", e_ty));
|
||||
assert_eq!(format!("{p_ty:?}"), format!("{:?}", e_ty));
|
||||
}
|
||||
(
|
||||
ParsedField {
|
||||
@@ -780,8 +771,8 @@ mod tests {
|
||||
},
|
||||
) => {
|
||||
assert_eq!(p_name, e_name);
|
||||
assert_eq!(format!("{:?}", p_input), format!("{:?}", e_input));
|
||||
assert_eq!(format!("{:?}", p_output), format!("{:?}", e_output));
|
||||
assert_eq!(format!("{p_input:?}"), format!("{:?}", e_input));
|
||||
assert_eq!(format!("{p_output:?}"), format!("{:?}", e_output));
|
||||
}
|
||||
_ => panic!("Mismatched field types"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user