Skip to content

Commit

Permalink
fix: move lint rules outside of quote_spanned (closes #2527) (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar4ys authored Jul 24, 2024
1 parent 0763a81 commit 7e75801
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 77 deletions.
15 changes: 7 additions & 8 deletions leptos_macro/src/view/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ pub(crate) fn fragment_to_tokens(
None,
)?;

let node = quote_spanned! {span=>
#[allow(unused_braces)] {#node}
};
let node = quote_spanned!(span => { #node });

Some(quote! {
::leptos::IntoView::into_view(#node)
::leptos::IntoView::into_view(#[allow(unused_braces)] #node)
})
})
.peekable();
Expand Down Expand Up @@ -339,9 +337,7 @@ pub(crate) fn element_to_tokens(
quote! {}
};
let ide_helper_close_tag = ide_helper_close_tag.into_iter();
Some(quote_spanned! {node.span()=>
#[allow(unused_braces)]
{
let result = quote_spanned! {node.span()=> {
#(#ide_helper_close_tag)*
#name
#(#attrs)*
Expand All @@ -352,7 +348,10 @@ pub(crate) fn element_to_tokens(
#(#children)*
#view_marker
}
})
};

// We need to move "allow" out of "quote_spanned" because it breaks hovering in rust-analyzer
Some(quote!(#[allow(unused_braces)] #result))
}
}

Expand Down
6 changes: 2 additions & 4 deletions leptos_macro/src/view/component_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ pub(crate) fn component_to_tokens(
})
.unwrap_or_else(|| quote! { #name });

let value = quote_spanned! {value.span()=>
#[allow(unused_braces)] {#value}
};
let value = quote_spanned!(value.span()=> { #value });

quote_spanned! {attr.span()=>
.#name(#value)
.#name(#[allow(unused_braces)] #value)
}
});

Expand Down
6 changes: 2 additions & 4 deletions leptos_macro/src/view/server_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ pub(crate) fn fragment_to_tokens_ssr(
let nodes = nodes.iter().map(|node| {
let span = node.span();
let node = root_node_to_tokens_ssr(node, global_class, None);
let node = quote_spanned! {span=>
#[allow(unused_braces)] {#node}
};
let node = quote_spanned!(span=> { #node });

quote! {
::leptos::IntoView::into_view(#node)
::leptos::IntoView::into_view(#[allow(unused_braces)] #node)
}
});

Expand Down
11 changes: 6 additions & 5 deletions leptos_macro/src/view/slot_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ pub(crate) fn slot_to_tokens(
})
.unwrap_or_else(|| quote! { #name });

let value = quote_spanned! {value.span()=>
#[allow(unused_braces)] {#value}
};
let value = quote_spanned!(value.span()=> { #value });

quote_spanned! {attr.span()=>
.#name(#value)
.#name(#[allow(unused_braces)] #value)
}
});

Expand Down Expand Up @@ -187,7 +185,7 @@ pub(crate) fn slot_to_tokens(
};

let slot = quote_spanned! {node.span()=>
#[allow(unused_braces)] {
{
let slot = #component_name::builder()
#(#props)*
#(#slots)*
Expand All @@ -200,6 +198,9 @@ pub(crate) fn slot_to_tokens(
},
};

// We need to move "allow" out of "quote_spanned" because it breaks hovering in rust-analyzer
let slot = quote!(#[allow(unused_braces)] #slot);

parent_slots
.entry(name)
.and_modify(|entry| entry.push(slot.clone()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(51..52),
span: bytes(37..52),
},
],
span: bytes(51..52),
span: bytes(37..52),
},
],
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -195,27 +195,27 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(70..71),
span: bytes(65..71),
},
],
span: bytes(70..71),
span: bytes(65..71),
},
],
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Brace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(51..52),
span: bytes(37..52),
},
],
span: bytes(51..52),
span: bytes(37..52),
},
],
span: bytes(51..52),
span: bytes(37..52),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -195,27 +195,27 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(70..71),
span: bytes(65..71),
},
],
span: bytes(70..71),
span: bytes(65..71),
},
],
span: bytes(70..71),
span: bytes(65..71),
},
Group {
delimiter: Brace,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
---
source: leptos_macro/src/view/tests.rs
assertion_line: 101
expression: result
---
TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(10..331),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(10..331),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(10..331),
},
],
span: bytes(10..331),
},
],
span: bytes(10..331),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -153,27 +147,22 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(28..83),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(28..83),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(28..83),
},
],
span: bytes(28..83),
},
],
span: bytes(28..83),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -404,27 +393,22 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(96..176),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(96..176),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(96..176),
},
],
span: bytes(96..176),
},
],
span: bytes(96..176),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -697,27 +681,22 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(189..223),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(189..223),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(189..223),
},
],
span: bytes(189..223),
},
],
span: bytes(189..223),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -902,27 +881,22 @@ TokenStream [
Punct {
char: '#',
spacing: Alone,
span: bytes(236..316),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
sym: allow,
span: bytes(236..316),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
sym: unused_braces,
span: bytes(236..316),
},
],
span: bytes(236..316),
},
],
span: bytes(236..316),
},
Group {
delimiter: Brace,
Expand Down
Loading

0 comments on commit 7e75801

Please sign in to comment.