Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): further refinements from fuzzing
Elijah Potterd8ee17a8ef15
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rsindex 2d34b9f10..51b9704bd 100644--- a/harper-cli/src/main.rs+++ b/harper-cli/src/main.rs@@ -31,6 +31,10 @@ enum Args {/// without further details.#[arg(short, long)]count: bool,+ /// Restrict linting to only a specific set of rules.+ /// If omitted, `harper-cli` will run every rule.+ #[arg(short, long)]+ only_lint_with: Option<Vec<String>>,},/// Parse a provided document and print the detected symbols.Parse {@@ -61,10 +65,23 @@ fn main() -> anyhow::Result<()> {let dictionary = FstDictionary::curated();match args {- Args::Lint { file, count } => {+ Args::Lint {+ file,+ count,+ only_lint_with,+ } => {let (doc, source) = load_file(&file, markdown_options)?;let mut linter = LintGroup::new_curated(dictionary);++ if let Some(rules) = only_lint_with {+ linter.set_all_rules_to(Some(false));++ for rule in rules {+ linter.config.set_rule_enabled(rule, true);+ }+ }+let mut lints = linter.lint(&doc);if count {diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dictindex 6cb5b7194..12f1d602b 100644--- a/harper-core/dictionary.dict+++ b/harper-core/dictionary.dict@@ -20876,7 +20876,7 @@ dopier/5dopiest/5dopiness/1Mdoping/41M-doppelganger/1S+doppelgänger/1Sdork/14MSdorky/5RTdorm/14MRZS@@ -32426,7 +32426,7 @@ mite/14MZRSmiter/41MDGmitigate/4DSGNmitigated/54U-mitigation/1M+mitigation/1MSmitochondria/1mitochondrial/5mitochondrion/1diff --git a/harper-core/src/linting/oxford_comma.rs b/harper-core/src/linting/oxford_comma.rsindex 6a1b4a7af..7a8589234 100644--- a/harper-core/src/linting/oxford_comma.rs+++ b/harper-core/src/linting/oxford_comma.rs@@ -59,6 +59,17 @@ impl Linter for OxfordComma {for sentence in document.iter_sentences() {let mut tok_cursor = 0;+ let mut words = sentence.iter_words().filter_map(|v| v.kind.expect_word());++ if let (Some(first), Some(second)) = (words.next(), words.next()) {+ if first.preposition && second.is_likely_homograph() {+ tok_cursor = sentence+ .iter()+ .position(|t| t.kind.is_comma())+ .unwrap_or(sentence.iter().len())+ }+ }+loop {if tok_cursor >= sentence.len() {break;@@ -194,4 +205,22 @@ mod tests {0,);}++ #[test]+ fn allow_at_first() {+ assert_lint_count(+ "In the heart of a bustling city, Sarah finds herself trapped in an endless cycle of the same day. Each morning, she awakens to find the date unchanged, her life on repeat. At first, confusion and frustration cloud her thoughts, but soon she notices something peculiar—each day has tiny differences, subtle changes that hint at a larger pattern.",+ OxfordComma::default(),+ 0,+ );+ }++ #[test]+ fn allow_standoff() {+ assert_lint_count(+ "In a tense standoff, Alex and his reflection engage in a battle of wills.",+ OxfordComma::default(),+ 0,+ );+ }}diff --git a/justfile b/justfileindex 0e655b5df..2fd9d200b 100644--- a/justfile+++ b/justfile@@ -192,8 +192,8 @@ precommit: check test build-harperjs build-obsidian build-web# Install `harper-cli` and `harper-ls` to your machine via `cargo`install:- cargo install --path harper-ls --locked --debug- cargo install --path harper-cli --locked --debug+ cargo install --path harper-ls --locked+ cargo install --path harper-cli --locked# Run `harper-cli` on the Harper repositorydogfood: