harper_core/linting/
long_sentences.rs1use super::{Lint, LintKind, Linter};
2use crate::TokenStringExt;
3use crate::{Document, Span};
4
5#[derive(Debug, Clone, Copy, Default)]
7pub struct LongSentences;
8
9impl Linter for LongSentences {
10 fn lint(&mut self, document: &Document) -> Vec<Lint> {
11 let mut output = Vec::new();
12
13 for sentence in document.iter_sentences() {
14 let word_count = sentence.iter_words().count();
15
16 if word_count > 40 {
17 output.push(Lint {
18 span: Span::new(
19 sentence.first_word().unwrap().span.start,
20 sentence.last().unwrap().span.end,
21 ),
22 lint_kind: LintKind::Readability,
23 message: format!("This sentence is {word_count} words long."),
24 ..Default::default()
25 })
26 }
27 }
28
29 output
30 }
31
32 fn description(&self) -> &'static str {
33 "This rule looks for run-on sentences, which can make your work harder to grok."
34 }
35}