diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..21fccfc --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,15 @@ +name: Clippy + +on: + push: + +jobs: + clippy: + name: cargo clippy + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + - run: | + rustup toolchain install + - run: | + cargo clippy --workspace --all-targets --all-features -- -D warnings diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index 2a8acc5..622ab8e 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -7,11 +7,8 @@ jobs: check_fmt: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1 - with: - toolchain: stable - - uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1 - with: - command: fmt - args: -- --check + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + - run: | + rustup toolchain install + - run: | + cargo fmt -- --check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15a86e0..7a4b37e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,10 +8,9 @@ jobs: name: cargo test runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1 - with: - toolchain: stable + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + - run: | + rustup toolchain install - uses: michaelkaye/setup-matrix-synapse@main with: @@ -24,9 +23,7 @@ jobs: "enable_registration": true } - - uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1 - with: - command: test + - run: cargo test env: RUST_BACKTRACE: 1 RUST_LOG: info,micro=trace,matrix=trace,ruma=trace,test=trace diff --git a/microbot/src/lib.rs b/microbot/src/lib.rs index 785ef3c..0c26b7b 100644 --- a/microbot/src/lib.rs +++ b/microbot/src/lib.rs @@ -43,7 +43,7 @@ pub enum MessengerError { #[error("Bot has already been started")] AlreadyStarted, #[error(transparent)] - Builder(#[from] ClientBuildError), + Builder(Box), #[error(transparent)] Client(#[from] matrix_sdk::Error), #[error(transparent)] @@ -54,6 +54,12 @@ pub enum MessengerError { PrefixConfig(regex::Error), } +impl From for MessengerError { + fn from(err: ClientBuildError) -> Self { + MessengerError::Builder(Box::new(err)) + } +} + #[derive(Debug, Deserialize)] pub struct MatrixConfig { pub url: String, @@ -189,7 +195,7 @@ impl MatrixMessenger { LoopCtrl::Continue } }).await - }.map_err(|err| MessengerError::Client(err)) + }.map_err(MessengerError::Client) )); Ok(()) diff --git a/microbot/src/message.rs b/microbot/src/message.rs index 964ecee..143330f 100644 --- a/microbot/src/message.rs +++ b/microbot/src/message.rs @@ -62,33 +62,6 @@ pub(crate) struct CommandMessageParser { command_pattern: Regex, } -#[derive(Debug)] -pub(crate) struct CommandMessageParserError { - pub inner: regex::Error, -} - -impl From for CommandMessageParserError { - fn from(err: regex::Error) -> Self { - Self { inner: err } - } -} - -impl std::fmt::Display for CommandMessageParserError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Failed to construct command message parser: {}", - self.inner - ) - } -} - -impl std::error::Error for CommandMessageParserError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - Some(&self.inner) - } -} - impl Default for CommandMessageParser { fn default() -> Self { Self { diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..38ab2c6 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.95.0" +components = ["clippy", "rustfmt"] diff --git a/tests/tests/bot_conversation.rs b/tests/tests/bot_conversation.rs index 42e32c8..296973e 100644 --- a/tests/tests/bot_conversation.rs +++ b/tests/tests/bot_conversation.rs @@ -12,7 +12,7 @@ use tokio::sync::{ }; use tracing_subscriber::filter::EnvFilter; -static HOMESERVER: &'static str = "http://localhost:8008"; +static HOMESERVER: &str = "http://localhost:8008"; // This test configures two bots and an initial sender that will send an initial command. // In response to this command the two bots will command messages to the room triggering @@ -49,7 +49,7 @@ async fn test_bot_conversation() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); let bot1 = format!( @@ -57,7 +57,7 @@ async fn test_bot_conversation() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); let bot2 = format!( @@ -65,7 +65,7 @@ async fn test_bot_conversation() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); @@ -164,8 +164,6 @@ async fn test_bot_conversation() { handle1.abort(); handle2.abort(); - - () }) .await .expect("Failed to run bot test in time"); diff --git a/tests/tests/ignore_old_messages.rs b/tests/tests/ignore_old_messages.rs index 032f4fb..a61f146 100644 --- a/tests/tests/ignore_old_messages.rs +++ b/tests/tests/ignore_old_messages.rs @@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt}; use tokio::sync::{mpsc, mpsc::Sender}; use tracing_subscriber::filter::EnvFilter; -static HOMESERVER: &'static str = "http://localhost:8008"; +static HOMESERVER: &str = "http://localhost:8008"; #[tokio::test] async fn test_ignores_old_messages() { @@ -23,7 +23,7 @@ async fn test_ignores_old_messages() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); let receiver = format!( @@ -31,7 +31,7 @@ async fn test_ignores_old_messages() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); diff --git a/tests/tests/receives_command.rs b/tests/tests/receives_command.rs index be11079..7b001d3 100644 --- a/tests/tests/receives_command.rs +++ b/tests/tests/receives_command.rs @@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt}; use tokio::sync::{mpsc, mpsc::Sender}; use tracing_subscriber::filter::EnvFilter; -static HOMESERVER: &'static str = "http://localhost:8008"; +static HOMESERVER: &str = "http://localhost:8008"; #[tokio::test] async fn test_receives_command() { @@ -23,7 +23,7 @@ async fn test_receives_command() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() ); let receiver = format!( @@ -31,7 +31,7 @@ async fn test_receives_command() { rand::rng() .sample_iter(&Alphanumeric) .take(24) - .map(|b| char::from(b)) + .map(char::from) .collect::() );