Skip to content

Commit

Permalink
Merge pull request #589 from Automattic/phrase-fixes
Browse files Browse the repository at this point in the history
Phrase fixes
  • Loading branch information
elijah-potter authored Feb 5, 2025
2 parents 9302aca + 08995da commit f62035e
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 261 deletions.
4 changes: 3 additions & 1 deletion harper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod sync;
mod title_case;
mod token;
mod token_kind;
mod token_string_ext;
mod vec_ext;
mod word_metadata;

Expand All @@ -38,8 +39,9 @@ pub use span::Span;
pub use spell::{Dictionary, FstDictionary, FullDictionary, MergedDictionary};
pub use sync::Lrc;
pub use title_case::{make_title_case, make_title_case_str};
pub use token::{Token, TokenStringExt};
pub use token::Token;
pub use token_kind::{NumberSuffix, TokenKind};
pub use token_string_ext::TokenStringExt;
pub use vec_ext::VecExt;
pub use word_metadata::{AdverbData, ConjunctionData, NounData, Tense, VerbData, WordMetadata};

Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/correct_number_suffix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Lint, LintKind, Linter, Suggestion};
use crate::token::TokenStringExt;
use crate::TokenStringExt;
use crate::{Document, NumberSuffix, Span, TokenKind};

/// Detect and warn that the sentence is too long.
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/linking_verbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Lint, LintKind, Linter};
use crate::token::TokenStringExt;
use crate::Document;
use crate::TokenStringExt;

/// Detect and warn that the sentence is too long.
#[derive(Debug, Clone, Copy, Default)]
Expand Down
19 changes: 15 additions & 4 deletions harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use super::merge_words::MergeWords;
use super::multiple_sequential_pronouns::MultipleSequentialPronouns;
use super::number_suffix_capitalization::NumberSuffixCapitalization;
use super::phrase_corrections::{
AndThis, Decision, HumanLife, NeedHelp, NoLonger, OfCourse, ThatChallenged, TurnItOff,
AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SupposeTo,
ThatChallenged, TurnItOff,
};
use super::plural_conjugate::PluralConjugate;
use super::pronoun_contraction::PronounContraction;
Expand Down Expand Up @@ -199,14 +201,23 @@ create_lint_group_config!(
SomewhatSomething => true,
LetsConfusion => true,
DespiteOf => true,
AndThis => true,
Decision => true,
HumanLife => true,
NeedHelp => true,
NoLonger => true,
ThatChallenged => true,
TurnItOff => true,
OfCourse => true
OfCourse => true,
AndAlike => true,
BadRap => true,
BatedBreath => true,
BeckAndCall => true,
ChangeTack => true,
HungerPang => true,
EnMasse => true,
LetAlone => true,
LoAndBehold => true,
SneakingSuspicion => true,
SupposeTo => true
);

impl<T: Dictionary + Default> Default for LintGroup<T> {
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/long_sentences.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Lint, LintKind, Linter};
use crate::token::TokenStringExt;
use crate::TokenStringExt;
use crate::{Document, Span};

/// Detect and warn that the sentence is too long.
Expand Down
4 changes: 3 additions & 1 deletion harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ pub use number_suffix_capitalization::NumberSuffixCapitalization;
pub use oxford_comma::OxfordComma;
pub use pattern_linter::PatternLinter;
pub use phrase_corrections::{
AndThis, Decision, HumanLife, NeedHelp, NoLonger, OfCourse, ThatChallenged, TurnItOff,
AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SupposeTo,
ThatChallenged, TurnItOff,
};
pub use plural_conjugate::PluralConjugate;
pub use pronoun_contraction::PronounContraction;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/number_suffix_capitalization.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Lint, LintKind, Linter, Suggestion};
use crate::token::TokenStringExt;
use crate::TokenStringExt;
use crate::{Document, Span, TokenKind};

/// Detect and warn that the sentence is too long.
Expand Down
85 changes: 71 additions & 14 deletions harper-core/src/linting/phrase_corrections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,37 @@ macro_rules! create_linter_for_phrase {
};
}

create_linter_for_phrase!(TurnItOff, "turn it off", 2);
create_linter_for_phrase!(HumanLife, "human life", 2);
create_linter_for_phrase!(TurnItOff, "turn it off", 1);
create_linter_for_phrase!(HumanLife, "human life", 1);
create_linter_for_phrase!(ThatChallenged, "that challenged", 2);
create_linter_for_phrase!(NoLonger, "no longer", 1);
create_linter_for_phrase!(NeedHelp, "need help", 1);
create_linter_for_phrase!(AndThis, "and this", 1);
create_linter_for_phrase!(Decision, "make a decision", 1);
create_linter_for_phrase!(OfCourse, "of course", 1);
create_linter_for_phrase!(AndAlike, "and alike", 1);
create_linter_for_phrase!(BadRap, "bad rap", 1);
create_linter_for_phrase!(BatedBreath, "bated breath", 1);
create_linter_for_phrase!(BeckAndCall, "beck and call", 1);
create_linter_for_phrase!(ChangeTack, "change tack", 1);
create_linter_for_phrase!(HungerPang, "hunger pang", 2);
create_linter_for_phrase!(EnMasse, "en masse", 1);
create_linter_for_phrase!(LetAlone, "let alone", 1);
create_linter_for_phrase!(LoAndBehold, "lo and behold", 2);
create_linter_for_phrase!(SneakingSuspicion, "sneaking suspicion", 3);
create_linter_for_phrase!(SupposeTo, "suppose to", 1);

#[cfg(test)]
mod tests {
use crate::linting::tests::{assert_lint_count, assert_suggestion_result};

use super::{Decision, OfCourse, TurnItOff};
use super::{
BadRap, BatedBreath, ChangeTack, EnMasse, HungerPang, LetAlone, LoAndBehold, OfCourse,
SneakingSuspicion, SupposeTo, TurnItOff,
};

#[test]
fn issue_574() {
assert_lint_count("run by one", TurnItOff::default(), 0);
}

#[test]
fn turn_it_off_clean_lower() {
Expand All @@ -102,15 +119,6 @@ mod tests {
assert_suggestion_result("Turn i of", TurnItOff::default(), "Turn it off");
}

#[test]
fn take_a_decision() {
assert_suggestion_result(
"we should take a decision on this",
Decision::default(),
"we should make a decision on this",
);
}

#[test]
fn off_course() {
assert_suggestion_result(
Expand All @@ -128,4 +136,53 @@ mod tests {
"Yes, of course we should do that.",
);
}

#[test]
fn bad_rep() {
assert_suggestion_result("bad rep", BadRap::default(), "bad rap");
}

#[test]
fn baited_breath() {
assert_suggestion_result("baited breath", BatedBreath::default(), "bated breath");
}

#[test]
fn change_tact() {
assert_suggestion_result("change tact", ChangeTack::default(), "change tack");
}

#[test]
fn hunger_pain() {
assert_suggestion_result("hunger pain", HungerPang::default(), "hunger pang");
}

#[test]
fn in_mass() {
assert_suggestion_result("in mass", EnMasse::default(), "en masse");
}

#[test]
fn let_along() {
assert_suggestion_result("let along", LetAlone::default(), "let alone");
}

#[test]
fn long_and_behold() {
assert_suggestion_result("long and behold", LoAndBehold::default(), "lo and behold");
}

#[test]
fn sneaky_suspicion() {
assert_suggestion_result(
"sneaky suspicion",
SneakingSuspicion::default(),
"sneaking suspicion",
);
}

#[test]
fn supposed_to() {
assert_suggestion_result("supposed to", SupposeTo::default(), "suppose to");
}
}
2 changes: 1 addition & 1 deletion harper-core/src/linting/repeated_words.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use smallvec::smallvec;

use super::{Lint, LintKind, Linter, Suggestion};
use crate::token::TokenStringExt;
use crate::TokenStringExt;
use crate::{CharString, CharStringExt, Document, Span};

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/spaces.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Lint, LintKind, Linter, Suggestion};
use crate::token::TokenStringExt;
use crate::TokenStringExt;
use crate::{Document, Token, TokenKind};

#[derive(Debug, Default)]
Expand Down
Loading

0 comments on commit f62035e

Please sign in to comment.