Skip to content

Commit

Permalink
feat: add autofix.ci to address formatting issues and possible clip…
Browse files Browse the repository at this point in the history
…py fixes (#3235)

* feat: add `autofix.ci` to address formatting issues and possible clippy
fixes

* fix: initial run of `autofix.ci` script to prevent PR pollution at first
run

* fix: typo and indent issue in `autofix.yml`

* fix: run `autofix.ci` over members with no features
  • Loading branch information
sabify authored Nov 12, 2024
1 parent 43912f4 commit d4044cd
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 25 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: autofix.ci
on:
workflow_call:
pull_request:
push:
branches: ["main"]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
autofix:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with: {toolchain: nightly, components: "rustfmt, clippy", target: "wasm32-unknown-unknown", rustflags: ""}
- name: Install jq
run: sudo apt-get install jq
- run: |
echo "Formatting the workspace"
cargo fmt --all
echo "Running Clippy against each member's features (default features included)"
for member in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | .name'); do
echo "Working on member $member":
echo -e "\tdefault-features/no-features:"
# this will also run on members with no features or default features
cargo clippy --allow-dirty --fix --lib --package "$member"
features=$(cargo metadata --no-deps --format-version 1 | jq -r ".packages[] | select(.name == \"$member\") | .features | keys[]")
for feature in $features; do
if [ "$feature" = "default" ]; then
continue
fi
echo -e "\tfeature $feature"
cargo clippy --allow-dirty --fix --lib --package "$member" --features "$feature"
done
done
- uses: autofix-ci/action@v1.3.1
if: ${{ always() }}
with:
fail-fast: false
4 changes: 2 additions & 2 deletions leptos/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ mod tests {
#[test]
fn clone_callback() {
let callback = Callback::new(move |_no_clone: NoClone| NoClone {});
let _cloned = callback.clone();
let _cloned = callback;
}

#[test]
fn clone_unsync_callback() {
let callback =
UnsyncCallback::new(move |_no_clone: NoClone| NoClone {});
let _cloned = callback.clone();
let _cloned = callback;
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions leptos_config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ fn ws_from_str_test() {

#[test]
fn env_w_default_test() {
_ = temp_env::with_var("LEPTOS_CONFIG_ENV_TEST", Some("custom"), || {
temp_env::with_var("LEPTOS_CONFIG_ENV_TEST", Some("custom"), || {
assert_eq!(
env_w_default("LEPTOS_CONFIG_ENV_TEST", "default").unwrap(),
String::from("custom")
);
});

_ = temp_env::with_var_unset("LEPTOS_CONFIG_ENV_TEST", || {
temp_env::with_var_unset("LEPTOS_CONFIG_ENV_TEST", || {
assert_eq!(
env_w_default("LEPTOS_CONFIG_ENV_TEST", "default").unwrap(),
String::from("default")
Expand All @@ -47,14 +47,14 @@ fn env_w_default_test() {

#[test]
fn env_wo_default_test() {
_ = temp_env::with_var("LEPTOS_CONFIG_ENV_TEST", Some("custom"), || {
temp_env::with_var("LEPTOS_CONFIG_ENV_TEST", Some("custom"), || {
assert_eq!(
env_wo_default("LEPTOS_CONFIG_ENV_TEST").unwrap(),
Some(String::from("custom"))
);
});

_ = temp_env::with_var_unset("LEPTOS_CONFIG_ENV_TEST", || {
temp_env::with_var_unset("LEPTOS_CONFIG_ENV_TEST", || {
assert_eq!(env_wo_default("LEPTOS_CONFIG_ENV_TEST").unwrap(), None);
});
}
Expand Down
4 changes: 2 additions & 2 deletions leptos_macro/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ enum InertElementBuilder<'a> {
},
}

impl<'a> ToTokens for InertElementBuilder<'a> {
impl ToTokens for InertElementBuilder<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
InertElementBuilder::GlobalClass { strs, .. } => {
Expand All @@ -219,7 +219,7 @@ enum GlobalClassItem<'a> {
String(String),
}

impl<'a> ToTokens for GlobalClassItem<'a> {
impl ToTokens for GlobalClassItem<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let addl_tokens = match self {
GlobalClassItem::Global(v) => v.to_token_stream(),
Expand Down
12 changes: 6 additions & 6 deletions oco/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub enum Oco<'a, T: ?Sized + ToOwned + 'a> {
Owned(<T as ToOwned>::Owned),
}

impl<'a, T: ?Sized + ToOwned> Oco<'a, T> {
impl<T: ?Sized + ToOwned> Oco<'_, T> {
/// Converts the value into an owned value.
pub fn into_owned(self) -> <T as ToOwned>::Owned {
match self {
Expand Down Expand Up @@ -339,7 +339,7 @@ where
}
}

impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<Oco<'b, B>> for Oco<'a, A>
impl<'b, A: ?Sized, B: ?Sized> PartialEq<Oco<'b, B>> for Oco<'_, A>
where
A: PartialEq<B>,
A: ToOwned,
Expand All @@ -352,7 +352,7 @@ where

impl<T: ?Sized + ToOwned + Eq> Eq for Oco<'_, T> {}

impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<Oco<'b, B>> for Oco<'a, A>
impl<'b, A: ?Sized, B: ?Sized> PartialOrd<Oco<'b, B>> for Oco<'_, A>
where
A: PartialOrd<B>,
A: ToOwned,
Expand Down Expand Up @@ -551,23 +551,23 @@ impl_slice_eq!(['a, 'b, T: PartialEq] (where [T]: ToOwned), Oco<'a, [T]>, &'b [T
impl_slice_eq!([T: PartialEq] (where [T]: ToOwned), Oco<'_, [T]>, Vec<T>);
impl_slice_eq!(['a, 'b, T: PartialEq] (where [T]: ToOwned), Oco<'a, [T]>, Cow<'b, [T]>);

impl<'a, 'b> Add<&'b str> for Oco<'a, str> {
impl<'b> Add<&'b str> for Oco<'_, str> {
type Output = Oco<'static, str>;

fn add(self, rhs: &'b str) -> Self::Output {
Oco::Owned(String::from(self) + rhs)
}
}

impl<'a, 'b> Add<Cow<'b, str>> for Oco<'a, str> {
impl<'b> Add<Cow<'b, str>> for Oco<'_, str> {
type Output = Oco<'static, str>;

fn add(self, rhs: Cow<'b, str>) -> Self::Output {
Oco::Owned(String::from(self) + rhs.as_ref())
}
}

impl<'a, 'b> Add<Oco<'b, str>> for Oco<'a, str> {
impl<'b> Add<Oco<'b, str>> for Oco<'_, str> {
type Output = Oco<'static, str>;

fn add(self, rhs: Oco<'b, str>) -> Self::Output {
Expand Down
2 changes: 1 addition & 1 deletion tachys/src/html/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<T: IntoClass> IntoClass for Option<T> {
}
}

impl<'a> IntoClass for &'a str {
impl IntoClass for &str {
type AsyncOutput = Self;
type State = (crate::renderer::types::Element, Self);
type Cloneable = Self;
Expand Down
2 changes: 1 addition & 1 deletion tachys/src/html/element/inner_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl InnerHtmlValue for Arc<str> {
}
}

impl<'a> InnerHtmlValue for &'a str {
impl InnerHtmlValue for &str {
type AsyncOutput = Self;
type State = (crate::renderer::types::Element, Self);
type Cloneable = Self;
Expand Down
2 changes: 1 addition & 1 deletion tachys/src/html/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ impl<'a> IntoStyle for (&'a str, String) {
}

#[cfg(feature = "nightly")]
impl<'a, const V: &'static str> IntoStyle for (&'a str, Static<V>) {
impl<const V: &'static str> IntoStyle for (&str, Static<V>) {
type AsyncOutput = Self;
type State = ();
type Cloneable = (Arc<str>, Static<V>);
Expand Down
1 change: 0 additions & 1 deletion tachys/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ pub trait DomRenderer: Renderer {
/// This works in a similar way to `TryFrom`. We implement it as a separate trait
/// simply so we don't have to create wrappers for the `web_sys` types; it can't be
/// implemented on them directly because of the orphan rules.

pub trait CastFrom<T>
where
Self: Sized,
Expand Down
1 change: 0 additions & 1 deletion tachys/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ where
/// Renders a view to an out-of-order stream of HTML with branch markers. This can be used to support libraries that diff
/// HTML pages against one another, by marking sections of the view that branch to different
/// types with marker comments.

fn to_html_stream_out_of_order_branching(self) -> StreamBuilder
where
Self: Sized,
Expand Down
12 changes: 6 additions & 6 deletions tachys/src/view/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> Render for &'a str {
}
}

impl<'a> RenderHtml for &'a str {
impl RenderHtml for &str {
type AsyncOutput = Self;

const MIN_LENGTH: usize = 0;
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<'a> RenderHtml for &'a str {
}
}

impl<'a> ToTemplate for &'a str {
impl ToTemplate for &str {
const TEMPLATE: &'static str = " <!>";

fn to_template(
Expand All @@ -120,7 +120,7 @@ impl<'a> ToTemplate for &'a str {
}
}

impl<'a> Mountable for StrState<'a> {
impl Mountable for StrState<'_> {
fn unmount(&mut self) {
self.node.unmount()
}
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'a> Render for Cow<'a, str> {
}
}

impl<'a> RenderHtml for Cow<'a, str> {
impl RenderHtml for Cow<'_, str> {
type AsyncOutput = Self;

const MIN_LENGTH: usize = 0;
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<'a> RenderHtml for Cow<'a, str> {
}
}

impl<'a> ToTemplate for Cow<'a, str> {
impl ToTemplate for Cow<'_, str> {
const TEMPLATE: &'static str = <&str as ToTemplate>::TEMPLATE;

fn to_template(
Expand All @@ -510,7 +510,7 @@ impl<'a> ToTemplate for Cow<'a, str> {
}
}

impl<'a> Mountable for CowStrState<'a> {
impl Mountable for CowStrState<'_> {
fn unmount(&mut self) {
self.node.unmount()
}
Expand Down

0 comments on commit d4044cd

Please sign in to comment.