fix clippy #42

Merged
ben merged 4 commits from ben/Jobboerse:main into main 2023-01-28 20:40:42 +01:00
13 changed files with 26 additions and 27 deletions

View file

@ -2,7 +2,7 @@
name = "better_toml_datetime"
description = "Small helper crate for usage in the jobboerse crate containing some helpers for working with toml date, datetime and time structs"
keywords = ["toml", "date", "time"]
categories = []
categories = ["date-and-time", "encoding"]
version.workspace = true
edition.workspace = true
rust-version.workspace = true

View file

@ -22,7 +22,7 @@ fn main() -> Result<(), std::io::Error> {
println!("cargo:rerun-if-changed=Cargo.lock");
println!("cargo:rerun-if-changed=THIRDPARTY.toml");
let input = BufReader::new(File::open(&thirdparty)?);
let input = BufReader::new(File::open(thirdparty)?);
#[allow(clippy::expect_fun_call)]
let previous = bundle_licenses_lib::format::Format::Toml

View file

@ -72,7 +72,7 @@ impl Attachment<NamedTempFile> {
) -> Result<Attachment<PathBuf>, PersistError> {
let attachment_location = Self::attachment_filename(idx);
let file_path = folder_path.join(&attachment_location);
self.attachment_location.persist(&file_path)?;
self.attachment_location.persist(file_path)?;
Ok(Attachment {
title: self.title,
file_name: self.file_name,
@ -91,7 +91,7 @@ impl Attachment<PathBuf> {
req: &HttpRequest,
preview_token: Option<&str>,
) -> Result<Url, UrlGenerationError> {
let mut url = req.url_for(JOBOFFER_ATTACHMENT_ROUTE, &[id, self.file_name.as_str()])?;
let mut url = req.url_for(JOBOFFER_ATTACHMENT_ROUTE, [id, self.file_name.as_str()])?;
if let Some(token) = preview_token {
url.query_pairs_mut().append_pair("token", token);
@ -568,7 +568,7 @@ impl JobOffer<PathBuf> {
req: &HttpRequest,
) -> Result<Url, UrlGenerationError> {
let mut url = req.url_for_static(JOBOFFER_OVERVIEW_ROUTE)?;
url.set_fragment(Some(&format!("joboffer-{}", id)));
url.set_fragment(Some(&format!("joboffer-{id}")));
Ok(url)
}
@ -960,7 +960,7 @@ mod test {
let serialized = toml::ser::to_string_pretty(&old)
.expect("testing serialization is not the goal of this test");
println!("{}", serialized);
println!("{serialized}");
toml::de::from_str::<JobOfferStatus>(&serialized).expect_err(
"V1 should not parse as current, this will prevent migration from applying",

View file

@ -65,19 +65,19 @@ impl JobOfferActions {
offer: &JobOffer<PathBuf>,
) -> actix_web::Result<Self, UrlGenerationError> {
let publish_url = req
.url_for(JOBOFFER_PUBLISH_ROUTE, &[id])
.url_for(JOBOFFER_PUBLISH_ROUTE, [id])
.expect("generation of publish route urls should succeed");
let unpublish_url = req
.url_for(JOBOFFER_UNPUBLISH_ROUTE, &[id])
.url_for(JOBOFFER_UNPUBLISH_ROUTE, [id])
.expect("generation of un-publish route urls should succeed");
let delete_url = req
.url_for(JOBOFFER_DELETION_ROUTE, &[id])
.url_for(JOBOFFER_DELETION_ROUTE, [id])
.expect("generation of delete route urls should succeed");
let edit_url = req
.url_for(JOBOFFER_EDIT_ROUTE, &[id])
.url_for(JOBOFFER_EDIT_ROUTE, [id])
.expect("generation of delete route urls should succeed");
let confirmation_url = match &offer.status {

View file

@ -1,5 +1,6 @@
#![warn(clippy::cargo)]
#![warn(clippy::unwrap_used)]
#![allow(clippy::multiple_crate_versions)]
// imports from standard library
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};

View file

@ -140,7 +140,7 @@ pub(crate) fn bad_request<B>(
}
SubmissionResponseError::Form(FormProcessingError::MultiPart(mpe)|FormProcessingError::Field(MultipartFieldError::Multipart(mpe))) => {
warn!("{}", mpe);
msg = format!("{}", mpe);
msg = format!("{mpe}");
Some(msg.as_str())
}
SubmissionResponseError::Form(FormProcessingError::Field(MultipartFieldError::NotAFile { field })) => {

View file

@ -148,7 +148,7 @@ pub(crate) async fn job_offer_attachment(
.map_or(false, |token| offer.check_submitter_token(token))
{
let dest = req
.url_for(JOBOFFER_ATTACHMENT_ROUTE, &[id, attachment_name])
.url_for(JOBOFFER_ATTACHMENT_ROUTE, [id, attachment_name])
.expect("generation of attachment route urls should succeed");
// when not authenticated, redirect to login with return path set back to the attachment
User::current(&session).map_err(|req_login| req_login.return_to(dest))?;
@ -159,7 +159,7 @@ pub(crate) async fn job_offer_attachment(
Ok(NamedFile::open_async(path).await.map(|named_file| {
named_file
.disable_content_disposition()
.set_content_type(mime_guess::from_path(&attachment_name).first_or_octet_stream())
.set_content_type(mime_guess::from_path(attachment_name).first_or_octet_stream())
}))
}

View file

@ -50,10 +50,10 @@ pub(crate) async fn confirm_joboffer_get(
preview: job_offer.to_preview_data(id, &req, Some(req_token))?,
actions: ConfirmActions {
confirm_url: req
.url_for(JOBOFFER_SUBMISSION_CONFIRM_ACTION_ROUTE, &[id, req_token])?
.url_for(JOBOFFER_SUBMISSION_CONFIRM_ACTION_ROUTE, [id, req_token])?
.to_string(),
retract_url: req
.url_for(JOBOFFER_SUBMISSION_RETRACT_ACTION_ROUTE, &[id, req_token])?
.url_for(JOBOFFER_SUBMISSION_RETRACT_ACTION_ROUTE, [id, req_token])?
.to_string(),
},
is_reviewed: !job_offer.status.requires_review(),

View file

@ -253,7 +253,7 @@ pub(crate) async fn create_job_offer<'data, 'config>(
.and_then(|highlight| Ok((highlight, req.url_for_static(LOGIN_ROUTE)?)))
{
Ok((highlight_url, login_url)) => {
email::send_reviewer_notice(hb, &email_config, highlight_url, login_url).await;
email::send_reviewer_notice(hb, email_config, highlight_url, login_url).await;
}
Err(err) => {
error!("Failed to generate highlight link: {}", err)
@ -262,7 +262,7 @@ pub(crate) async fn create_job_offer<'data, 'config>(
}
if !skip_confirmation {
let confirm_url = req.url_for(JOBOFFER_CONFIRM_ROUTE, &[created_offer.id(), &token])?;
let confirm_url = req.url_for(JOBOFFER_CONFIRM_ROUTE, [created_offer.id(), &token])?;
email::send_confirmation_email(
hb,

View file

@ -154,7 +154,7 @@ pub(crate) async fn edit_joboffer_post(
if let Some(tmp_file) = file {
// TODO error handling
let _todo =
tmp_file.persist(&job_offer_folder.join(&offer.attachment_location));
tmp_file.persist(job_offer_folder.join(&offer.attachment_location));
}
Some(offer)

View file

@ -60,7 +60,7 @@ pub fn chrono_datetime_to_toml_datetime<Tz: chrono::TimeZone>(
pub fn toml_date_to_chrono_date(date: &toml::value::Date) -> chrono::DateTime<FixedOffset> {
let local_date =
NaiveDate::from_ymd_opt(date.year.into(), date.month.into(), date.day.into()).unwrap();
NaiveDate::from_ymd_opt(date.year.into(), date.month.into(), date.day.into()).expect("toml should contain valid date");
let offset = chrono_tz::Europe::Berlin
.offset_from_local_date(&local_date)
.map(|offset| offset.fix())
@ -91,15 +91,13 @@ pub fn toml_datetime_to_chrono_datetime(
toml_date.year.into(),
toml_date.month.into(),
toml_date.day.into(),
)
.unwrap()
).expect("toml should contain valid date")
.and_hms_nano_opt(
toml_time.hour.into(),
toml_time.minute.into(),
toml_time.second.into(),
toml_time.nanosecond,
)
.unwrap();
).expect("toml should contain valid time");
let offset: FixedOffset = datetime
.offset
@ -108,7 +106,7 @@ pub fn toml_datetime_to_chrono_datetime(
Offset::Z => 0,
Offset::Custom { minutes } => *minutes as i32 * 60,
})
.and_then(|sec_offset| FixedOffset::east_opt(sec_offset))
.and_then(FixedOffset::east_opt)
.unwrap_or_else(|| {
// try to interpret timestamp as local Europe/Berlin time
let tz_result = chrono_tz::Europe::Berlin
@ -148,7 +146,7 @@ pub(crate) fn parse_datetime(
None | Some("") => None,
Some(backdate) => {
// toml currently requires time to include seconds, but the html field does not include them, so we just add them here
let backdate_with_sec = format!("{}:00", backdate);
let backdate_with_sec = format!("{backdate}:00");
Some(better_toml_datetime::Datetime::from_str(
&backdate_with_sec,
)?)

View file

@ -2,7 +2,7 @@
name = "multipart_helper"
description = "A helper crate for handling multipart forms in the jobbörse create"
keywords = ["multipart/form-data"]
categories = []
categories = ["encoding", "network-programming"]
version.workspace = true
edition.workspace = true
rust-version.workspace = true

View file

@ -133,7 +133,7 @@ pub(crate) async fn tmpfile_from_field(
let buf = if let Some(buf) = file_buffer.as_mut() {
buf
} else {
let file = NamedTempFile::new_in(&tmp_dir)?;
let file = NamedTempFile::new_in(tmp_dir)?;
file_buffer.insert(BufWriter::new(file))
};
remaining -= data.len();