harper_core/linting/
avoid_curses.rs1use super::{Lint, LintKind, Linter};
2use crate::{Document, TokenStringExt};
3
4#[derive(Debug, Default)]
5pub struct AvoidCurses;
6
7impl Linter for AvoidCurses {
8 fn lint(&mut self, document: &Document) -> Vec<Lint> {
9 document
10 .iter_words()
11 .filter(|t| t.kind.is_swear())
12 .map(|t| Lint {
13 span: t.span,
14 lint_kind: LintKind::Miscellaneous,
15 suggestions: vec![],
16 message: "Try to avoid offensive language.".to_string(),
17 priority: 63,
18 })
19 .collect()
20 }
21
22 fn description(&self) -> &'static str {
23 "A rule that looks for common offensive language."
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::AvoidCurses;
30 use crate::linting::tests::assert_lint_count;
31
32 #[test]
33 fn detects_shit() {
34 assert_lint_count("He ate shit when he fell off the bike.", AvoidCurses, 1);
35 }
36}