Skip to content

Commit

Permalink
Merge branch 'master' into dep-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Feb 17, 2025
2 parents 466372f + b1e4a31 commit a25f82c
Show file tree
Hide file tree
Showing 28 changed files with 1,369 additions and 1,078 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion harper-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/automattic/harper"
[dependencies]
anyhow = "1.0.95"
ariadne = "0.4.1"
clap = { version = "4.5.28", features = ["derive"] }
clap = { version = "4.5.29", features = ["derive"] }
harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.21.0" }
harper-core = { path = "../harper-core", version = "0.21.0" }
harper-comments = { path = "../harper-comments", version = "0.21.0" }
Expand Down
2 changes: 1 addition & 1 deletion harper-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ paste = "1.0.14"
pulldown-cmark = "0.12.2"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.138"
smallvec = { version = "1.13.2", features = ["serde"] }
smallvec = { version = "1.14.0", features = ["serde"] }
thiserror = "2.0.11"
unicode-blocks = "0.1.9"
unicode-script = "0.5.7"
Expand Down
18 changes: 16 additions & 2 deletions harper-core/dictionary.dict
Original file line number Diff line number Diff line change
Expand Up @@ -8570,7 +8570,6 @@ Ryan/2M
Rydberg/2M
Ryder/2M
Ryukyu/2M
S/152MN
SA/5124
SAC/12
SALT/2M
Expand Down Expand Up @@ -37361,7 +37360,6 @@ pox/14MS
pp/1
ppm/1
ppr
pr/5
practicability/1M
practicably/
practical/51SMY
Expand Down Expand Up @@ -49928,3 +49926,19 @@ backplane/SM
cyberattack/SM
RTX/1SM
PDP/1SM
Jetpack/2M
learnt/4
WooCommerce/2M
Tumblr/2M
Akismet/2M
Simplenote/2M
Longreads/2M
VaultPress/2M
Gravatar/2M
Crowdsignal/2M
Mullenweg/M
journaling/SM3
Polldaddy/2M
P2/M
VideoPress/2M
stylization/SM
6 changes: 5 additions & 1 deletion harper-core/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ impl Document {
for token in self.tokens.iter_mut() {
if let TokenKind::Word(meta) = &mut token.kind {
let word_source = token.span.get_content(&self.source);
let found_meta = dictionary.get_word_metadata(word_source);
let found_meta = dictionary
.get_correct_capitalization_of(word_source)
.map(|canonical_caps| dictionary.get_word_metadata(canonical_caps))
.unwrap_or_default();
*meta = meta.or(&found_meta);
}
}
Expand Down Expand Up @@ -535,6 +538,7 @@ macro_rules! create_fns_on_doc {

impl TokenStringExt for Document {
create_fns_on_doc!(word);
create_fns_on_doc!(hostname);
create_fns_on_doc!(word_like);
create_fns_on_doc!(conjunction);
create_fns_on_doc!(space);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl PatternLinter for GeneralCompoundNouns {

fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {
let span = matched_tokens.span().unwrap();
let orig = span.get_content(source);
// If the pattern matched, this will not return `None`.
let word = self
.split_pattern
Expand All @@ -67,7 +68,7 @@ impl PatternLinter for GeneralCompoundNouns {
Lint {
span,
lint_kind: LintKind::Spelling,
suggestions: vec![Suggestion::ReplaceWith(word.to_vec())],
suggestions: vec![Suggestion::replace_with_match_case(word.to_vec(), orig)],
message: format!(
"Did you mean the closed compound noun “{}”?",
word.to_string()
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/compound_nouns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod tests {
#[test]
fn web_socket() {
let test_sentence = "Real-time updates are sent via a web socket.";
let expected = "Real-time updates are sent via a WebSocket.";
let expected = "Real-time updates are sent via a websocket.";
assert_suggestion_result(test_sentence, CompoundNouns::default(), expected);
}

Expand Down
14 changes: 12 additions & 2 deletions harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ use super::phrase_corrections::MutePoint;
use super::phrase_corrections::StateOfTheArt;
use super::phrase_corrections::WantBe;
use super::phrase_corrections::{
AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
AndTheLike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,
SupposedTo, ThanOthers, ThatChallenged, TurnItOff,
};
use super::pique_interest::PiqueInterest;
use super::plural_conjugate::PluralConjugate;
use super::possessive_your::PossessiveYour;
use super::pronoun_contraction::PronounContraction;
use super::proper_noun_capitalization_linters::DayOneNames;
use super::proper_noun_capitalization_linters::JetpackNames;
use super::proper_noun_capitalization_linters::PocketCastsNames;
use super::proper_noun_capitalization_linters::TumblrNames;
use super::proper_noun_capitalization_linters::{
AmazonNames, Americas, AppleNames, Australia, AzureNames, Canada, ChineseCommunistParty,
GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,
Expand All @@ -72,6 +76,7 @@ use super::unclosed_quotes::UnclosedQuotes;
use super::use_genitive::UseGenitive;
use super::was_aloud::WasAloud;
use super::whereas::Whereas;
use super::wordpress_dotcom::WordPressDotcom;
use super::wrong_quotes::WrongQuotes;
use super::{CurrencyPlacement, Lint, Linter, NoOxfordComma, OxfordComma};
use crate::{Dictionary, Document};
Expand Down Expand Up @@ -195,6 +200,11 @@ macro_rules! create_lint_group_config {
}

create_lint_group_config!(
WordPressDotcom => true,
DayOneNames => true,
PocketCastsNames => true,
TumblrNames => true,
JetpackNames => true,
OutOfDate => true,
Desktop => true,
Laptop => true,
Expand Down Expand Up @@ -312,7 +322,7 @@ create_lint_group_config!(
ThatChallenged => true,
TurnItOff => true,
OfCourse => true,
AndAlike => true,
AndTheLike => true,
BadRap => true,
BatedBreath => true,
BeckAndCall => true,
Expand Down
8 changes: 7 additions & 1 deletion harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod unclosed_quotes;
mod use_genitive;
mod was_aloud;
mod whereas;
mod wordpress_dotcom;
mod wrong_quotes;

pub use an_a::AnA;
Expand Down Expand Up @@ -109,14 +110,18 @@ pub use phrase_corrections::MutePoint;
pub use phrase_corrections::StateOfTheArt;
pub use phrase_corrections::WantBe;
pub use phrase_corrections::{
AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
AndTheLike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,
SupposedTo, ThanOthers, ThatChallenged, TurnItOff,
};
pub use pique_interest::PiqueInterest;
pub use plural_conjugate::PluralConjugate;
pub use possessive_your::PossessiveYour;
pub use pronoun_contraction::PronounContraction;
pub use proper_noun_capitalization_linters::DayOneNames;
pub use proper_noun_capitalization_linters::JetpackNames;
pub use proper_noun_capitalization_linters::PocketCastsNames;
pub use proper_noun_capitalization_linters::TumblrNames;
pub use proper_noun_capitalization_linters::{
AmazonNames, Americas, AppleNames, Australia, AzureNames, Canada, ChineseCommunistParty,
GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,
Expand All @@ -135,6 +140,7 @@ pub use unclosed_quotes::UnclosedQuotes;
pub use use_genitive::UseGenitive;
pub use was_aloud::WasAloud;
pub use whereas::Whereas;
pub use wordpress_dotcom::WordPressDotcom;
pub use wrong_quotes::WrongQuotes;

use crate::Document;
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/phrase_corrections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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!(OfCourse, "of course", 1);
create_linter_for_phrase!(AndAlike, "and alike", 1);
create_linter_for_phrase!(AndTheLike, "and the like", 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);
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/possessive_your.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl PatternLinter for PossessiveYour {
Suggestion::replace_with_match_case("your".chars().collect(), orig_chars),
Suggestion::replace_with_match_case("you're an".chars().collect(), orig_chars),
],
message: "The possesive version of this word is more common in this context."
message: "The possessive version of this word is more common in this context."
.to_owned(),
..Default::default()
}
Expand Down
107 changes: 107 additions & 0 deletions harper-core/src/linting/proper_noun_capitalization_linters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,113 @@ create_linter_for!(
"When referring to Meta products and services, make sure to treat them as proper nouns."
);

create_linter_for!(
JetpackNames,
SequencePattern::default()
.t_aco("Jetpack")
.then_whitespace()
.then(Box::new(EitherPattern::new(vec![
Box::new(
SequencePattern::default()
.t_aco("VaultPress")
.then_whitespace()
.t_aco("Backup")
),
Box::new(SequencePattern::default().t_aco("VaultPress")),
Box::new(SequencePattern::default().t_aco("Scan")),
Box::new(
SequencePattern::default()
.t_aco("Akismet")
.then_whitespace()
.t_aco("Anti-spam")
),
Box::new(SequencePattern::default().t_aco("Stats")),
Box::new(SequencePattern::default().t_aco("Social")),
Box::new(SequencePattern::default().t_aco("Blaze")),
Box::new(
SequencePattern::default()
.t_aco("AI")
.then_whitespace()
.t_aco("Assistant")
),
Box::new(
SequencePattern::default()
.t_aco("Site")
.then_whitespace()
.t_aco("Search")
),
Box::new(SequencePattern::default().t_aco("Boost")),
Box::new(SequencePattern::default().t_aco("VideoPress")),
Box::new(
SequencePattern::default()
.t_aco("For")
.then_whitespace()
.t_aco("Agencies")
),
Box::new(SequencePattern::default().t_aco("CRM")),
]))),
"Ensure proper capitalization of Jetpack-related terms."
);

create_linter_for!(
TumblrNames,
SequencePattern::default()
.t_aco("Tumblr")
.then_whitespace()
.then(Box::new(EitherPattern::new(vec![
Box::new(SequencePattern::default().t_aco("Blaze")),
Box::new(SequencePattern::default().t_aco("Pro")),
Box::new(SequencePattern::default().t_aco("Live")),
Box::new(SequencePattern::default().t_aco("Ads")),
Box::new(SequencePattern::default().t_aco("Communities")),
Box::new(SequencePattern::default().t_aco("Shop")),
Box::new(SequencePattern::default().t_aco("Dashboard"))
]))),
"Ensure proper capitalization of Tumblr-related terms."
);

create_linter_for!(
PocketCastsNames,
EitherPattern::new(vec![
Box::new(
SequencePattern::default()
.t_aco("Pocket")
.then_whitespace()
.t_aco("Casts")
),
Box::new(
SequencePattern::default()
.t_aco("Pocket")
.then_whitespace()
.t_aco("Casts")
.then_whitespace()
.t_aco("Plus")
)
]),
"Ensure proper capitalization of Pocket Casts and Pocket Casts Plus as brand names."
);

create_linter_for!(
DayOneNames,
EitherPattern::new(vec![
Box::new(
SequencePattern::default()
.t_aco("Day")
.then_whitespace()
.t_aco("One")
),
Box::new(
SequencePattern::default()
.t_aco("Day")
.then_whitespace()
.t_aco("One")
.then_whitespace()
.t_aco("Premium")
)
]),
"Ensure proper capitalization of Day One and Day One Premium as brand names."
);

#[cfg(test)]
mod tests {
use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
Expand Down
6 changes: 4 additions & 2 deletions harper-core/src/linting/spell_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::Suggestion;
use super::{Lint, LintKind, Linter};
use crate::document::Document;
use crate::spell::suggest_correct_spelling;
use crate::{CharString, Dictionary, TokenStringExt};
use crate::{CharString, CharStringExt, Dictionary, TokenStringExt};

pub struct SpellCheck<T>
where
Expand Down Expand Up @@ -56,7 +56,9 @@ impl<T: Dictionary> Linter for SpellCheck<T> {

for word in document.iter_words() {
let word_chars = document.get_span_content(word.span);
if self.dictionary.contains_word(word_chars) {
if self.dictionary.contains_exact_word(word_chars)
|| self.dictionary.contains_exact_word(&word_chars.to_lower())
{
continue;
}

Expand Down
Loading

0 comments on commit a25f82c

Please sign in to comment.