diff --git a/harper-core/default_config.json b/harper-core/default_config.json index a4facb62c..971691bc1 100644 --- a/harper-core/default_config.json +++ b/harper-core/default_config.json @@ -2441,6 +2441,13 @@ "label": "Eluded To" } }, + { + "Bool": { + "name": "AlludeVsElude", + "state": true, + "label": "Allude Vs Elude" + } + }, { "Bool": { "name": "EverSince", diff --git a/harper-core/src/linting/allude_vs_elude/allude-grouped.txt b/harper-core/src/linting/allude_vs_elude/allude-grouped.txt new file mode 100644 index 000000000..96ec84416 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/allude-grouped.txt @@ -0,0 +1,82 @@ +2021 + +I allude +to allude +we allude +you allude +not allude +We allude +may allude +only allude +now allude +here allude +have alluded +already alluded +above alluded +had alluded +he alluded +before alluded +been alluded +here alluded +just alluded +is alluded +he alludes +This alludes +He alludes +here alludes +it alludes +and alludes +thus alludes +also alludes +probably alludes +which alludes +in alluding +In alluding +by alluding +*Alluding +After alluding +after alluding +was alluding +of alluding +without alluding +and alluding +allude to +allude is +allude in +allude more +allude are +allude particularly +allude here +allude was +allude only +allude not +alluded to +alluded in +alluded was +alluded as +alluded were +alluded had +alluded is +alluded above +alluded at +alluded with +alludes to +alludes in +alludes is +alludes here +alludes when +alludes as +alludes was +alludes with +alludes only +alludes are +alluding to +alluding in +alluding probably +alluding here +alluding at +alluding more +alluding only +alluding particularly +alluding perhaps +alluding with diff --git a/harper-core/src/linting/allude_vs_elude/allude-sorted.txt b/harper-core/src/linting/allude_vs_elude/allude-sorted.txt new file mode 100644 index 000000000..11058ed21 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/allude-sorted.txt @@ -0,0 +1,51 @@ +I allude +alluded to +to allude +we allude +you allude +may allude +only allude +here allude +have alluded +alludes is +alludes when +alludes was +was alluding +not allude +of alluding +he alluded +before alluded +and alluding +been alluded +also alludes +alludes with +We allude +probably alludes +already alluded +which alludes +In alluding +* Alluding +allude to +alludes only +it alludes +thus alludes +in alluding +here alluded +by alluding +allude is +just alluded +without alluding +allude more +allude particularly +now allude +This alludes +allude are +allude here +allude not +above alluded +is alluded +allude was +He alludes +alluded is +alludes to +allude only diff --git a/harper-core/src/linting/allude_vs_elude/before-and-after.txt b/harper-core/src/linting/allude_vs_elude/before-and-after.txt new file mode 100644 index 000000000..e689273c2 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/before-and-after.txt @@ -0,0 +1,82 @@ +above - +after - +already - +also - +always - +and - +be - +been - +before - +by - +can - +for - +had - +has - +have - +he - +here - +hitherto - +I - +in - +In - +is - +it - +just - +may - +not - +now - +of - +often - +only - +or - +probably - +she - +still - +that - +they - +This - +thus - +to - +To - +was - +we - +We - +which - +who - +will - +without - +you - +- a +- above +- all +- are +- as +- at +- by +- had +- her +- here +- him +- his +- in +- is +- it +- its +- me +- more +- my +- not +- only +- our +- particularly +- perhaps +- probably +- the +- their +- them +- to +- us +- was +- were +- when +- with diff --git a/harper-core/src/linting/allude_vs_elude/combined.txt b/harper-core/src/linting/allude_vs_elude/combined.txt new file mode 100644 index 000000000..4f54cdd67 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/combined.txt @@ -0,0 +1,92 @@ +* Alluding * æLuding +above alluded above æLuded +after eluding after æLuding +allude are æLude are +allude here æLude here +allude is æLude is +allude more æLude more +allude not æLude not +allude only æLude only +allude particularly æLude particularly +allude to æLude to +allude was æLude was +alluded is æLuded is +alluded to æLuded to +alludes is æLudes is +alludes only æLudes only +alludes to æLudes to +alludes was æLudes was +alludes when æLudes when +alludes with æLudes with +already alluded already æLuded +also alludes also æLudes +always eludes always æLudes +and elude and æLude +and eluded and æLuded +and eludes and æLudes +be eluded be æLuded +been alluded been æLuded +before alluded before æLuded +BOTH and æLuding +BOTH by æLuding +BOTH have æLuded +BOTH it æLudes +BOTH may æLude +BOTH not æLude +BOTH of æLuding +BOTH to æLude +BOTH was æLuding +BOTH which æLudes +can elude can æLude +elude all æLude all +elude him æLude him +elude his æLude his +elude our æLude our +elude the æLude the +elude their æLude their +elude us æLude us +eluded all æLuded all +eluded him æLuded him +eluded his æLuded his +eluded the æLuded the +eludes all æLudes all +eludes our æLudes our +eludes the æLudes the +eludes their æLudes their +eludes us æLudes us +for eluding for æLuding +had eluded had æLuded +he alluded he æLuded +He alludes He æLudes +he eludes he æLudes +here allude here æLude +here alluded here æLuded +hitherto eluded hitherto æLuded +I allude I æLude +in alluding in æLuding +In alluding In æLuding +in eluding in æLuding +is alluded is æLuded +just alluded just æLuded +now allude now æLude +often eludes often æLudes +only allude only æLude +or elude or æLude +or eluded or æLuded +or eluding or æLuding +probably alludes probably æLudes +she eludes she æLudes +still eludes still æLudes +that eluded that æLuded +that eludes that æLudes +they elude they æLude +they eluded they æLuded +This alludes This æLudes +thus alludes thus æLudes +To elude To æLude +we allude we æLude +We allude We æLude +which elude which æLude +will elude will æLude +without alluding without æLuding +you allude you æLude diff --git a/harper-core/src/linting/allude_vs_elude/elude-grouped.txt b/harper-core/src/linting/allude_vs_elude/elude-grouped.txt new file mode 100644 index 000000000..a8210c5c7 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/elude-grouped.txt @@ -0,0 +1,81 @@ +2022 +to elude +and elude +or elude +can elude +may elude +not elude +To elude +will elude +which elude +they elude +had eluded +have eluded +be eluded +has eluded +he eluded +and eluded +hitherto eluded +or eluded +that eluded +they eluded +it eludes +which eludes +that eludes +still eludes +and eludes +he eludes +often eludes +she eludes +always eludes +who eludes +of eluding +in eluding +and eluding +for eluding +in-eluding +by eluding +or eluding +thus eluding +after eluding +was eluding +elude the +elude his +elude our +elude their +elude them +elude all +elude it +elude us +elude him +elude a +eluded the +eluded him +eluded his +eluded by +eluded all +eluded their +eluded her +eluded them +eluded me +eluded my +eludes the +eludes us +eludes our +eludes me +eludes his +eludes all +eludes him +eludes her +eludes their +eludes them +eluding the +eluding his +eluding their +eluding all +eluding a +eluding them +eluding him +eluding our +eluding it +eluding its diff --git a/harper-core/src/linting/allude_vs_elude/elude-sorted.txt b/harper-core/src/linting/allude_vs_elude/elude-sorted.txt new file mode 100644 index 000000000..ea8a7d452 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/elude-sorted.txt @@ -0,0 +1,51 @@ +to elude +eluded him +elude the +and elude +can elude +may elude +will elude +had eluded +that eluded +still eludes +elude us +which elude +he eludes +they elude +have eluded +and eluded +or eluded +they eluded +often eludes +she eludes +eludes our +and eludes +not elude +be eluded +of eluding +in eluding +or eluding +after eluding +elude him +To elude +by eluding +eluded all +was eluding +hitherto eluded +or elude +it eludes +elude our +which eludes +eludes the +that eludes +for eluding +eludes all +elude all +eluded the +eluded his +and eluding +elude his +eludes us +always eludes +elude their +eludes their diff --git a/harper-core/src/linting/allude_vs_elude/mod.rs b/harper-core/src/linting/allude_vs_elude/mod.rs new file mode 100644 index 000000000..c8c84ecd4 --- /dev/null +++ b/harper-core/src/linting/allude_vs_elude/mod.rs @@ -0,0 +1,138 @@ +use crate::{ + Lint, Lrc, Token, TokenStringExt, + expr::{Expr, LongestMatchOf, SequenceExpr}, + linting::{ExprLinter, LintKind, Suggestion, debug::format_lint_match, expr_linter::Chunk}, +}; + +pub struct AlludeVsElude { + expr: SequenceExpr, +} + +const COMMON_BEFORE_VERB: &[&str] = &[ + "above", "after", "already", "also", "always", "and", "be", "been", "before", "by", "can", + "for", "had", "has", "have", "he", "here", "hitherto", "I", "in", "In", "is", "it", "just", + "may", "not", "now", "of", "often", "only", "or", "probably", "she", "still", "that", "they", + "This", "thus", "to", "To", "was", "we", "We", "which", "who", "will", "without", "you", +]; + +const COMMON_BEFORE_BOTH: &[&str] = &[ + "and", "by", "have", "it", "may", "not", "of", "to", "was", "which", +]; + +const COMMON_AFTER_VERB: &[&str] = &[ + "a", + "above", + "all", + "are", + "as", + "at", + "by", + "had", + "her", + "here", + "him", + "his", + "in", + "is", + "it", + "its", + "me", + "more", + "my", + "not", + "only", + "our", + "particularly", + "perhaps", + "probably", + "the", + "their", + "them", + "to", + "us", + "was", + "were", + "when", + "with", +]; + +const ALLUDE: &[&str] = &["allude", "alluded", "alludes", "alluding"]; +const ELUDE: &[&str] = &["elude", "eluded", "eludes", "eluding"]; + +impl Default for AlludeVsElude { + fn default() -> Self { + let either_verb = Lrc::new(LongestMatchOf::new(vec![ + Box::new(SequenceExpr::word_set(ALLUDE)), + Box::new(SequenceExpr::word_set(ELUDE)), + ])); + + Self { + expr: SequenceExpr::longest_of(vec![ + Box::new( + SequenceExpr::word_set(COMMON_BEFORE_VERB) + .t_ws() + .then(either_verb.clone()), + ), + Box::new( + SequenceExpr::with(either_verb.clone()) + .t_ws() + .t_set(COMMON_AFTER_VERB), + ), + Box::new( + SequenceExpr::word_set(COMMON_BEFORE_VERB) + .t_ws() + .then(either_verb) + .t_ws() + .t_set(COMMON_AFTER_VERB), + ), + ]), + } + } +} + +impl ExprLinter for AlludeVsElude { + type Unit = Chunk; + + fn match_to_lint_with_context( + &self, + matched_tokens: &[Token], + source: &[char], + context: Option<(&[Token], &[Token])>, + ) -> Option { + eprintln!("🚨 {}", format_lint_match(matched_tokens, context, source)); + let span = matched_tokens.span()?; + let lint_kind = LintKind::Miscellaneous; + let suggestions = vec![Suggestion::replace_with_match_case_str( + "correction", + span.get_content(source), + )]; + let message = "Fix this erorr".to_string(); + None /*Some(Lint { + span, + lint_kind, + suggestions, + message, + ..Default::default() + })*/ + } + + fn expr(&self) -> &dyn Expr { + &self.expr + } + + fn description(&self) -> &str { + "A linter skeleton for contributors to copy into `harper_core/src/linting/` and rename." + } +} + +#[cfg(test)] +mod tests { + use crate::linting::tests::assert_suggestion_result; + + use super::AlludeVsElude; + + #[test] + fn test_skeleton() { + assert_suggestion_result("erorr", AlludeVsElude::default(), "correction"); + } +} diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs index 7f2deaf08..18697fa2c 100644 --- a/harper-core/src/linting/lint_group/mod.rs +++ b/harper-core/src/linting/lint_group/mod.rs @@ -20,6 +20,7 @@ use super::after_later::AfterLater; use super::all_hell_break_loose::AllHellBreakLoose; use super::all_intents_and_purposes::AllIntentsAndPurposes; use super::allow_to::AllowTo; +use super::allude_vs_elude::AlludeVsElude; use super::am_in_the_morning::AmInTheMorning; use super::amounts_for::AmountsFor; use super::an_a::AnA; @@ -578,6 +579,7 @@ impl LintGroup { insert_expr_rule!(AllHellBreakLoose, true); insert_expr_rule!(AllIntentsAndPurposes, true); insert_expr_rule!(AllowTo, true); + insert_expr_rule!(AlludeVsElude, true); insert_expr_rule!(AmInTheMorning, true); insert_expr_rule!(AmountsFor, true); insert_struct_rule_with_dialect!(AnA, true); diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs index 229fb2afb..06dd676f4 100644 --- a/harper-core/src/linting/mod.rs +++ b/harper-core/src/linting/mod.rs @@ -12,6 +12,7 @@ mod after_later; mod all_hell_break_loose; mod all_intents_and_purposes; mod allow_to; +mod allude_vs_elude; mod am_in_the_morning; mod amounts_for; mod an_a;