🚨 Fix clippy warnings

This commit is contained in:
2024-03-30 18:24:04 +01:00
parent 448b81b65d
commit 83fe388e8d
6 changed files with 73 additions and 68 deletions

View File

@@ -30,20 +30,20 @@ use style::{
turf::style_sheet!("src/components/login.scss");
const BACKGROUND_COLORS_STR: &'static str = formatcp!(
const BACKGROUND_COLORS_STR: &str = formatcp!(
"{COLOR_PRIMARY_150},{COLOR_PRIMARY_140},\
{COLOR_SECONDARY_150},{COLOR_SECONDARY_140},\
{COLOR_TERNARY_150},{COLOR_TERNARY_140}"
);
const SHAPE_1_COLORS_STR: &'static str = formatcp!(
const SHAPE_1_COLORS_STR: &str = formatcp!(
"{COLOR_PRIMARY_120},{COLOR_PRIMARY_110},{COLOR_PRIMARY_100},{COLOR_PRIMARY_90},{COLOR_PRIMARY_80}"
);
const SHAPE_2_COLORS_STR: &'static str = formatcp!(
const SHAPE_2_COLORS_STR: &str = formatcp!(
"{COLOR_SECONDARY_120},{COLOR_SECONDARY_110},{COLOR_SECONDARY_100},{COLOR_SECONDARY_90},{COLOR_SECONDARY_80}");
const SHAPE_3_COLORS_STR: &'static str = formatcp!(
const SHAPE_3_COLORS_STR: &str = formatcp!(
"{COLOR_TERNARY_120},{COLOR_TERNARY_110},{COLOR_TERNARY_100},{COLOR_TERNARY_90},{COLOR_TERNARY_80}");
async fn generate_random_avatar(url: &String) -> Option<String> {
@@ -76,27 +76,27 @@ async fn generate_random_avatar(url: &String) -> Option<String> {
res
}
const REQUIRED_ERROR_NAME: &'static str = "required";
const REQUIRED_ERROR_HELPER_TEXT: &'static str = "This field must be completed";
const REQUIRED_ERROR_NAME: &str = "required";
const REQUIRED_ERROR_HELPER_TEXT: &str = "This field must be completed";
const INVALID_URL_ERROR_NAME: &'static str = "url";
const INVALID_URL_ERROR_HELPER_TEXT: &'static str = "This field must be a valid URL";
const INVALID_URL_ERROR_NAME: &str = "url";
const INVALID_URL_ERROR_HELPER_TEXT: &str = "This field must be a valid URL";
const INVALID_EMAIL_ERROR_NAME: &'static str = "email";
const INVALID_EMAIL_ERROR_HELPER_TEXT: &'static str = "This field must be a valid email";
const INVALID_EMAIL_ERROR_NAME: &str = "email";
const INVALID_EMAIL_ERROR_HELPER_TEXT: &str = "This field must be a valid email";
const TOO_WEAK_PASSWORD_ERROR_NAME: &'static str = "too_weak_password";
const TOO_WEAK_PASSWORD_ERROR_HELPER_TEXT: &'static str = "The password is too weak";
const TOO_WEAK_PASSWORD_ERROR_NAME: &str = "too_weak_password";
const TOO_WEAK_PASSWORD_ERROR_HELPER_TEXT: &str = "The password is too weak";
const FIELDS_MISMATCH_ERROR_NAME: &'static str = "mismatch";
const FIELDS_MISMATCH_ERROR_NAME: &str = "mismatch";
const HOMESERVER_FIELD_NAME: &'static str = "homeserver_url";
const ID_FIELD_NAME: &'static str = "id";
const PASSWORD_FIELD_NAME: &'static str = "password";
const CONFIRM_PASSWORD_FIELD_NAME: &'static str = "confirm password";
const HOMESERVER_FIELD_NAME: &str = "homeserver_url";
const ID_FIELD_NAME: &str = "id";
const PASSWORD_FIELD_NAME: &str = "password";
const CONFIRM_PASSWORD_FIELD_NAME: &str = "confirm password";
const LOGIN_ID_PLACEHOLDER: &'static str = "Username";
const REGISTER_ID_PLACEHOLDER: &'static str = "Email";
const LOGIN_ID_PLACEHOLDER: &str = "Username";
const REGISTER_ID_PLACEHOLDER: &str = "Email";
#[derive(PartialEq)]
enum Process {
@@ -273,9 +273,7 @@ fn on_validation_errors(
) {
for (field_name, errors) in field_errors {
if let Some(handler) = handlers.get(field_name) {
errors
.into_iter()
.for_each(|e| handler.on_validation_error(e));
errors.iter().for_each(|e| handler.on_validation_error(e));
} else if *field_name == "__all__" {
for error in *errors {
let code = error.code.to_string();
@@ -289,11 +287,11 @@ fn on_validation_errors(
.collect::<Vec<_>>();
for field_name in field_names.iter() {
if let Some(handler) = handlers.get(*field_name) {
if let Some(handler) = handlers.get(field_name) {
let other_field_names = field_names
.iter()
.filter(|f| **f != *field_name)
.map(|f| *f)
.copied()
.collect::<Vec<_>>();
let other_field_names_len = other_field_names.len();
@@ -366,12 +364,12 @@ fn validate_data(data: &Data, process: &Process) -> Result<(), ValidationError>
Process::Registration => {
let mut is_confirm_password_empty = true;
if let Some(confirm_password) = &data.confirm_password {
if confirm_password.len() > 0 {
if !confirm_password.is_empty() {
is_confirm_password_empty = false;
}
}
if is_confirm_password_empty {
let mut err = ValidationError::new(&REQUIRED_ERROR_NAME);
let mut err = ValidationError::new(REQUIRED_ERROR_NAME);
err.add_param(Cow::from("field_name"), &CONFIRM_PASSWORD_FIELD_NAME);
return Err(err);
}
@@ -389,11 +387,9 @@ fn validate_data(data: &Data, process: &Process) -> Result<(), ValidationError>
}
fn validate_id(id: &Option<String>, process: &Process) -> Result<(), ValidationError> {
if *process == Process::Registration {
if !id.validate_email() {
let err = ValidationError::new(&INVALID_EMAIL_ERROR_NAME);
return Err(err);
}
if *process == Process::Registration && !id.validate_email() {
let err = ValidationError::new(INVALID_EMAIL_ERROR_NAME);
return Err(err);
}
Ok(())
@@ -415,7 +411,7 @@ impl PasswordValidationResult {
}
fn compute_password_score(
password: &String,
password: &str,
with_suggestions: Option<bool>,
) -> Option<PasswordValidationResult> {
let Ok(estimate) = zxcvbn(password, &[]) else {
@@ -705,7 +701,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps>) -> Element<'a> {
spinner_animated.set(true);
if let Err(errors) = on_login(&session, &data_ref) {
if let Err(errors) = on_login(session, data_ref) {
let field_errors = errors.field_errors();
on_validation_errors(&field_errors, &handlers);
}
@@ -728,7 +724,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps>) -> Element<'a> {
spinner_animated.set(true);
if let Err(errors) = on_register(&session, &data_ref) {
if let Err(errors) = on_register(session, data_ref) {
let field_name = PASSWORD_FIELD_NAME;
let field_errors = errors.field_errors();
@@ -750,7 +746,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps>) -> Element<'a> {
}
});
if suggestions_msgs.len() > 0 {
if !suggestions_msgs.is_empty() {
let mut modal_config = PasswordSuggestionsModalConfig::new(
None,
"Let's talk about your password".to_string(),
@@ -794,11 +790,10 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps>) -> Element<'a> {
let on_modal_confirm = move |_: Event<MouseData>| {
modal_config.set(None);
};
let rendered_modal = if let Some(modal_config) = modal_config.get() {
Some(render!(generate_modal(modal_config, on_modal_confirm)))
} else {
None
};
let rendered_modal = modal_config
.get()
.as_ref()
.map(|modal_config| render!(generate_modal(modal_config, on_modal_confirm)));
let form_classes_str = form_classes.join(" ");
let password_classes_str = password_classes.join(" ");