1#![doc = include_str!("../README.md")]
2#![allow(dead_code)]
3
4mod char_ext;
5mod char_string;
6mod currency;
7mod document;
8mod edit_distance;
9mod fat_token;
10mod ignored_lints;
11pub mod language_detection;
12mod lexing;
13pub mod linting;
14mod mask;
15mod number;
16pub mod parsers;
17pub mod patterns;
18mod punctuation;
19mod span;
20pub mod spell;
21mod sync;
22mod title_case;
23mod token;
24mod token_kind;
25mod token_string_ext;
26mod vec_ext;
27mod word_metadata;
28
29use std::collections::VecDeque;
30
31pub use char_string::{CharString, CharStringExt};
32pub use currency::Currency;
33pub use document::Document;
34pub use fat_token::FatToken;
35pub use ignored_lints::IgnoredLints;
36use linting::Lint;
37pub use mask::{Mask, Masker};
38pub use number::{Number, NumberSuffix};
39pub use punctuation::{Punctuation, Quote};
40pub use span::Span;
41pub use spell::{Dictionary, FstDictionary, MergedDictionary, MutableDictionary};
42pub use sync::Lrc;
43pub use title_case::{make_title_case, make_title_case_str};
44pub use token::Token;
45pub use token_kind::TokenKind;
46pub use token_string_ext::TokenStringExt;
47pub use vec_ext::VecExt;
48pub use word_metadata::{AdverbData, ConjunctionData, NounData, Tense, VerbData, WordMetadata};
49
50pub fn remove_overlaps(lints: &mut Vec<Lint>) {
55 if lints.len() < 2 {
56 return;
57 }
58
59 let mut remove_indices = VecDeque::new();
60 lints.sort_by_key(|l| (l.span.start, !0 - l.span.end));
61
62 let mut cur = 0;
63
64 for (i, lint) in lints.iter().enumerate() {
65 if lint.span.start < cur {
66 remove_indices.push_back(i);
67 continue;
68 }
69 cur = lint.span.end;
70 }
71
72 lints.remove_indices(remove_indices);
73}
74
75#[cfg(test)]
76mod tests {
77 use crate::{
78 linting::{LintGroup, LintGroupConfig, Linter},
79 remove_overlaps, Document, FstDictionary,
80 };
81
82 #[test]
83 fn keeps_space_lint() {
84 let doc = Document::new_plain_english_curated("Ths tet");
85
86 let lint_config = LintGroupConfig {
87 spell_check: Some(true),
88 spaces: Some(true),
89 ..LintGroupConfig::none()
90 };
91 let mut linter = LintGroup::new(lint_config, FstDictionary::curated());
92
93 let mut lints = linter.lint(&doc);
94
95 dbg!(&lints);
96 remove_overlaps(&mut lints);
97 dbg!(&lints);
98
99 assert_eq!(lints.len(), 3);
100 }
101}