Skip to main content

sqrust_rules/layout/
long_lines.rs

1use sqrust_core::{Diagnostic, FileContext, Rule};
2
3pub struct LongLines {
4    pub max_length: usize,
5}
6
7impl Default for LongLines {
8    fn default() -> Self {
9        LongLines { max_length: 120 }
10    }
11}
12
13impl Rule for LongLines {
14    fn name(&self) -> &'static str {
15        "Layout/LongLines"
16    }
17
18    fn check(&self, ctx: &FileContext) -> Vec<Diagnostic> {
19        let mut diags = Vec::new();
20        for (line_num, line) in ctx.lines() {
21            let length = line.chars().count();
22            if length > self.max_length {
23                diags.push(Diagnostic {
24                    rule: self.name(),
25                    message: format!(
26                        "Line is {} characters, maximum is {}",
27                        length, self.max_length
28                    ),
29                    line: line_num,
30                    col: self.max_length + 1,
31                });
32            }
33        }
34        diags
35    }
36}