-use crate::error::LemmyError;
+use crate::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
use regex::{Regex, RegexBuilder};
pub fn remove_slurs(test: &str, slur_regex: &Option<Regex>) -> String {
pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
if let Err(slurs) = slur_check(text, slur_regex) {
- Err(LemmyError::from_error_message(
- anyhow::anyhow!("{}", slurs_vec_to_str(&slurs)),
- "slurs",
- ))
+ Err(anyhow::anyhow!("{}", slurs_vec_to_str(&slurs))).with_lemmy_type(LemmyErrorType::Slurs)
} else {
Ok(())
}
#[cfg(test)]
mod test {
+ #![allow(clippy::unwrap_used)]
+ #![allow(clippy::indexing_slicing)]
+
use crate::utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str};
use regex::RegexBuilder;