Skip to content

Commit

Permalink
chore: #![deny(clippy::all)] (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective authored Dec 21, 2024
1 parent f4fa972 commit 06fc347
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct IdeaReactionAction {
}

#[derive(thiserror::Error, Debug)]
// TODO(kisaragi): https://github.com/GiganticMinecraft/idea-reaction/pull/153 が済んだらヴァリアントの名前を変える
#[expect(clippy::enum_variant_names)]
pub enum IdeaReactionActionError {
#[error("Failed to reaction. (Reason: {0})")]
FailedToReaction(String),
Expand Down
5 changes: 3 additions & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ impl EventHandler for Handler {
return;
};

if message.embeds.first().is_none() {
let Some(first_embed) = message.embeds.first() else {
return;
};
let embed = match parse_embed(message.embeds.first().unwrap()) {

let embed = match parse_embed(first_embed) {
Ok(embed) => embed,
Err(why) => {
tracing::error!("Failed to parse embed: {:?}", why);
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all)]

use anyhow::Context;
use handler::Handler;
use serenity::{all::GatewayIntents, Client};
Expand Down
18 changes: 9 additions & 9 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ pub fn parse_embed(embed: &serenity::all::Embed) -> anyhow::Result<IdeaEmbed, Pa
};
let issue_number = parse_issue_number(title)?;

return Ok(IdeaEmbed::builder()
Ok(IdeaEmbed::builder()
.title(title.clone())
.issue_number(issue_number)
.build());
.build())
}

fn parse_issue_number(title: &String) -> anyhow::Result<u16, ParseEnvIDsError> {
fn parse_issue_number(title: &str) -> anyhow::Result<u16, ParseEnvIDsError> {
let re = match regex::Regex::new(r"#(\d+)") {
Ok(regex) => regex,
Err(why) => return Err(ParseEnvIDsError::FailedToParseIssueNumber(why.to_string())),
};

match re.captures(&title) {
match re.captures(title) {
Some(caps) => match caps.get(1).unwrap().as_str().parse::<u16>() {
Ok(num) => Ok(num),
Err(why) => Err(ParseEnvIDsError::FailedToParseIssueNumber(why.to_string())),
Expand Down Expand Up @@ -94,17 +94,17 @@ mod parsers_test {
"[New issue] アイデア提案用プロジェクト - アイデア提案 #10925: 棒メニューに建築素材のみの購入メニュー"
];

assert_eq!(parse_issue_number(&mock[0].to_string()).unwrap(), 9);
assert_eq!(parse_issue_number(&mock[1].to_string()).unwrap(), 951);
assert_eq!(parse_issue_number(&mock[2].to_string()).unwrap(), 1527);
assert_eq!(parse_issue_number(&mock[3].to_string()).unwrap(), 10925);
assert_eq!(parse_issue_number(mock[0]).unwrap(), 9);
assert_eq!(parse_issue_number(mock[1]).unwrap(), 951);
assert_eq!(parse_issue_number(mock[2]).unwrap(), 1527);
assert_eq!(parse_issue_number(mock[3]).unwrap(), 10925);
}

// `parse_issue_number()` が Issue 番号がないタイトルのパースを正しく失敗できるか
#[test]
fn test_parse_issue_number_no_capture() {
let mock = "[New issue] アイデア提案用プロジェクト - アイデア提案: 不定期イベントシステム";
let result = parse_issue_number(&mock.to_string());
let result = parse_issue_number(mock);

assert!(result.is_err());
}
Expand Down

0 comments on commit 06fc347

Please sign in to comment.