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