-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: swapped out
LintSet
for LintGroup
and made linters configur…
…able
- Loading branch information
1 parent
5c0f23f
commit 8ff3182
Showing
14 changed files
with
217 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use paste::paste; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::an_a::AnA; | ||
use super::long_sentences::LongSentences; | ||
use super::matcher::Matcher; | ||
use super::repeated_words::RepeatedWords; | ||
use super::sentence_capitalization::SentenceCapitalization; | ||
use super::spaces::Spaces; | ||
use super::spell_check::SpellCheck; | ||
use super::spelled_numbers::SpelledNumbers; | ||
use super::unclosed_quotes::UnclosedQuotes; | ||
use super::wrong_quotes::WrongQuotes; | ||
use super::{Lint, Linter}; | ||
use crate::{Dictionary, Document}; | ||
|
||
macro_rules! create_lint_group_config { | ||
($($linter:ident => $default:expr),*) => { | ||
paste! { | ||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)] | ||
pub struct LintGroupConfig { | ||
$( | ||
#[doc = "Configures the use of the `" $linter "` linter. | ||
If set to [`None`], the default configuration will be used."] | ||
pub [<$linter:snake>]: Option<bool>, | ||
)* | ||
pub spell_check: Option<bool> | ||
} | ||
|
||
impl LintGroupConfig { | ||
/// Fills the [`None`] values in the configuration with the default values. | ||
pub fn fill_default_values(&mut self){ | ||
$( | ||
if self.[<$linter:snake>].is_none() { | ||
self.[<$linter:snake>] = Some($default); | ||
} | ||
)* | ||
|
||
if self.spell_check.is_none() { | ||
self.spell_check = Some(true); | ||
} | ||
} | ||
} | ||
|
||
pub struct LintGroup<T: Dictionary> { | ||
$( | ||
[<$linter:snake>]: $linter, | ||
)* | ||
spell_check: SpellCheck<T>, | ||
pub config: LintGroupConfig | ||
} | ||
|
||
|
||
impl<T: Dictionary> LintGroup<T> { | ||
pub fn new(config: LintGroupConfig, dictionary: T) -> Self { | ||
Self { | ||
$( | ||
[<$linter:snake>]: $linter::default(), | ||
)* | ||
spell_check: SpellCheck::new(dictionary), | ||
config, | ||
} | ||
} | ||
} | ||
|
||
impl<T: Dictionary> Linter for LintGroup<T> { | ||
fn lint(&mut self, document: &Document) -> Vec<Lint>{ | ||
let mut lints = Vec::new(); | ||
|
||
let mut config = self.config.clone(); | ||
config.fill_default_values(); | ||
|
||
$( | ||
if config.[<$linter:snake>].unwrap() { | ||
lints.append(&mut self.[<$linter:snake>].lint(document)); | ||
} | ||
)* | ||
|
||
if config.spell_check.unwrap() { | ||
lints.append(&mut self.spell_check.lint(document)); | ||
} | ||
|
||
|
||
lints | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
create_lint_group_config!( | ||
SpelledNumbers => false, | ||
AnA => true, | ||
SentenceCapitalization => true, | ||
UnclosedQuotes => true, | ||
WrongQuotes => true, | ||
LongSentences => true, | ||
RepeatedWords => true, | ||
Spaces => true, | ||
Matcher => true | ||
); | ||
|
||
impl<T: Dictionary + Default> Default for LintGroup<T> { | ||
fn default() -> Self { | ||
Self::new(LintGroupConfig::default(), T::default()) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ tracing = "0.1.40" | |
tracing-subscriber = "0.3.18" | ||
resolve-path = "0.1.0" | ||
open = "5.1.1" | ||
futures = "0.3.30" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.