Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
|
| These configuration options determine the driver used to determine and
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
| allow the maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
|
Expand Down
4 changes: 2 additions & 2 deletions harper-core/dictionary.dict
Original file line number Diff line number Diff line change
Expand Up @@ -28011,10 +28011,10 @@ highway/~NVgS
highwayman/~Ng
highwaymen/~9
hijab/~NSg
hijack/~VNSzZGgd>
hijack/~VNSzZGgd
hijacker/~Ng
hijacking/~VNwg
hike/~NVgZGd>S
hike/~NVgZGdS
hiker/Ng
hiking/~VNmg
hilarious/~JpY
Expand Down
10 changes: 10 additions & 0 deletions harper-core/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ where
pub trait OwnedExprExt {
fn or(self, other: impl Expr + 'static) -> FirstMatchOf;
fn or_longest(self, other: impl Expr + 'static) -> LongestMatchOf;
fn and(self, other: impl Expr + 'static) -> All;
fn and_not(self, other: impl Expr + 'static) -> All;
}

impl<E> OwnedExprExt for E
Expand All @@ -167,4 +169,12 @@ where
fn or_longest(self, other: impl Expr + 'static) -> LongestMatchOf {
LongestMatchOf::new(vec![Box::new(self), Box::new(other)])
}

fn and(self, other: impl Expr + 'static) -> All {
All::new(vec![Box::new(self), Box::new(other)])
}

fn and_not(self, other: impl Expr + 'static) -> All {
self.and(UnlessStep::new(other, |_: &Token, _: &[char]| true))
}
}
1 change: 1 addition & 0 deletions harper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod punctuation;
mod render_markdown;
mod span;
pub mod spell;
mod starts_with_vowel;
mod sync;
mod title_case;
mod token;
Expand Down
117 changes: 1 addition & 116 deletions harper-core/src/linting/an_a.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::borrow::Cow;

use itertools::Itertools;

use crate::linting::{Lint, LintKind, Linter, Suggestion};
use crate::{Document, TokenStringExt};
use crate::{Document, TokenStringExt, starts_with_vowel::starts_with_vowel};

#[derive(Debug, Default)]
pub struct AnA;
Expand Down Expand Up @@ -78,119 +76,6 @@ impl Linter for AnA {
}
}

fn to_lower_word(word: &[char]) -> Cow<'_, [char]> {
if word.iter().any(|c| c.is_uppercase()) {
Cow::Owned(
word.iter()
.flat_map(|c| c.to_lowercase())
.collect::<Vec<_>>(),
)
} else {
Cow::Borrowed(word)
}
}

/// Checks whether a provided word begins with a vowel _sound_.
///
/// It was produced through trial and error.
/// Matches with 99.71% and 99.77% of vowels and non-vowels in the
/// Carnegie-Mellon University word -> pronunciation dataset.
fn starts_with_vowel(word: &[char]) -> bool {
let is_likely_initialism = word.iter().all(|c| c.is_uppercase());

if is_likely_initialism && !word.is_empty() {
return matches!(
word[0],
'A' | 'E' | 'F' | 'H' | 'I' | 'L' | 'M' | 'N' | 'O' | 'R' | 'S' | 'X'
);
}

let word = to_lower_word(word);
let word = word.as_ref();

if matches!(
word,
[] | ['u', 'k', ..]
| ['e', 'u', 'p', 'h', ..]
| ['e', 'u', 'g' | 'l' | 'c', ..]
| ['o', 'n', 'e']
| ['o', 'n', 'c', 'e']
) {
return false;
}

if matches!(word, |['h', 'o', 'u', 'r', ..]| ['h', 'o', 'n', ..]
| ['u', 'n', 'i', 'n' | 'm', ..]
| ['u', 'n', 'a' | 'u', ..]
| ['h', 'e', 'r', 'b', ..]
| ['u', 'r', 'b', ..]
| ['i', 'n', 't', ..])
{
return true;
}

if matches!(word, ['u', 'n' | 's', 'i' | 'a' | 'u', ..]) {
return false;
}

if matches!(word, ['u', 'n', ..]) {
return true;
}

if matches!(word, ['u', 'r', 'g', ..]) {
return true;
}

if matches!(word, ['u', 't', 't', ..]) {
return true;
}

if matches!(
word,
['u', 't' | 'r' | 'n', ..] | ['e', 'u', 'r', ..] | ['u', 'w', ..] | ['u', 's', 'e', ..]
) {
return false;
}

if matches!(word, ['o', 'n', 'e', 'a' | 'e' | 'i' | 'u', 'l' | 'd', ..]) {
return true;
}

if matches!(word, ['o', 'n', 'e', 'a' | 'e' | 'i' | 'u' | '-' | 's', ..]) {
return false;
}

if matches!(
word,
['s', 'o', 's']
| ['r', 'z', ..]
| ['n', 'g', ..]
| ['n', 'v', ..]
| ['x']
| ['x', 'b', 'o', 'x']
| ['h', 'e', 'i', 'r', ..]
| ['h', 'o', 'n', 'o', 'r', ..]
) {
return true;
}

if matches!(
word,
['j', 'u' | 'o', 'n', ..] | ['j', 'u', 'r', 'a' | 'i' | 'o', ..]
) {
return false;
}

if matches!(word, ['x', '-' | '\'' | '.' | 'o' | 's', ..]) {
return true;
}

matches!(
word,
['a', ..] | ['e', ..] | ['i', ..] | ['o', ..] | ['u', ..]
)
}

#[cfg(test)]
mod tests {
use super::AnA;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/confident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ExprLinter for Confident {
}

fn description(&self) -> &'static str {
"This linter detects instances where the noun `confidant` is incorrectly used in place of the adjective `confident`. `Confidant` refers to a trusted person, whereas `confident` describes certainty or self-assurance. The rule suggests replacing `confidant` with `confident` when used in an adjectival context."
"This linter detects instances where the noun `confidant` is incorrectly used in place of the adjective `confident`. `Confidant` refers to a trusted person, whereas `confident` describes some certainty or self-assurance. The rule suggests replacing `confidant` with `confident` when used in an adjectival context."
}
}

Expand Down
2 changes: 2 additions & 0 deletions harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use super::likewise::Likewise;
use super::long_sentences::LongSentences;
use super::looking_forward_to::LookingForwardTo;
use super::merge_words::MergeWords;
use super::missing_article::MissingArticle;
use super::missing_preposition::MissingPreposition;
use super::modal_of::ModalOf;
use super::most_number::MostNumber;
Expand Down Expand Up @@ -400,6 +401,7 @@ impl LintGroup {
insert_struct_rule!(CapitalizePersonalPronouns, true);
insert_expr_rule!(ChockFull, true);
insert_expr_rule!(DoubleModal, true);
insert_expr_rule!(MissingArticle, true);
insert_expr_rule!(MissingPreposition, true);
insert_struct_rule!(DiscourseMarkers, true);
insert_expr_rule!(WayTooAdjective, true);
Expand Down
Loading