Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: capitalize notable places and I-contractions
hippietrailceec7c635575
diff --git a/harper-core/affixes.json b/harper-core/affixes.jsonindex 5ef61d7d6..8907d57c1 100644--- a/harper-core/affixes.json+++ b/harper-core/affixes.json@@ -718,7 +718,8 @@}},"*": {- "#": "singular third-person pronoun property",+ "#": "singular third-person subject pronoun property",+ "//": "so we can do verb agreement","suffix": true,"cross_product": true,"replacements": [],diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dictindex 6230feb11..678644d8c 100644--- a/harper-core/dictionary.dict+++ b/harper-core/dictionary.dict@@ -4670,6 +4670,7 @@ Hyundai/1MHz/MI/8~fI'd/~+I'd've/I'll/~I'm/~I've/~@@ -7079,6 +7080,7 @@ NES/1MNF/251NFC/21NFL/21M+NGO/1MSNH/2145NHL/12MNIH/25@@ -10619,7 +10621,6 @@ Whitman/2MWhitney/2MWhitsunday/12MSWhittier/2M-WiFi/14Wicca/2MWichita/12MWiemar/M@@ -12986,7 +12987,7 @@ assessor/1MSasset/~1MSasseverate/4DSGNasseveration/1M-asshole/1MS!6+asshole/1MS6assiduity/1Massiduous/5PYassiduousness/1M@@ -15556,10 +15557,10 @@ bullock/~14SMbullpen/~1SMbullring/1MSbullseye/~1-bullshit/~154MS!-bullshitted/4!-bullshitter/1SM!-bullshitting/4!+bullshit/~154MS6+bullshitted/46+bullshitter/1SM6+bullshitting/46bullwhip/14Sbully/~145DSMGbulrush/1MS@@ -16908,7 +16909,7 @@ chicken/~154MDGchickenfeed/1Mchickenhearted/5chickenpox/1M-chickenshit/51S!+chickenshit/51S6chickpea/1SMchickweed/1Mchicle/1M@@ -17623,7 +17624,7 @@ cockney/~152SMcockpit/~1SMcockroach/1MScockscomb/1SM-cocksucker/1MS!6+cocksucker/1MS6cocksure/5cocktail/~154MScocky/514RTP@@ -19586,7 +19587,7 @@ cumulus/~1Mcuneiform/~51Mcunnilingus/1Mcunning/~51MRYT-cunt/145MS!6+cunt/145MS6cup/~14SMcupboard/~14SMcupcake/14MS@@ -20720,7 +20721,7 @@ diciest/5dick/~14MRXZS6dicker/41DGdickey/~15SM-dickhead/1S+dickhead/1S6dickybird/Sdicotyledon/1MSdicotyledonous/5@@ -25236,9 +25237,9 @@ fryer/~1SMft/~14ftp/~5124ZGSfuchsia/15MS-fuck/~41SMGDRZ!6-fucker/1M!6S-fuckhead/1S!6+fuck/~41SMGDRZ6+fucker/1M6S+fuckhead/1S6fuddle/41DSMGfudge/~14DSMGfuehrer/1MS@@ -27425,7 +27426,7 @@ heppest/5heptagon/1MSheptagonal/5heptathlon/1SM-her/~-*ot+her/~-otherald/~14SMDGheralded/~4Uheraldic/~5@@ -27489,7 +27490,7 @@ herpetologist/1SMherpetology/1Mherring/~1MSherringbone/14M-hers/~8+hers/~8*herself/~8hertz/~1Mhesitance/1M@@ -27928,7 +27929,7 @@ horsemen/~9horseplay/14Mhorsepower/~1Mhorseradish/1MS-horseshit/1!6+horseshit/16horseshoe/~14DSMhorseshoeing/4horsetail/1SM@@ -29886,7 +29887,7 @@ iteration/~1AMiterator/1Sitinerant/~51SMitinerary/~15SM-its/~8-+its/~8-*itself/~8iv/~Uivory/~15SM@@ -33133,7 +33134,7 @@ mind/~14ADRSZGmind'smindbogglingly/jminded/~54P-mindfuck/1SM6!+mindfuck/1SM6mindful/~51YPmindfulness/~1Mmindless/5YP@@ -33795,8 +33796,8 @@ moth/~14Mmothball/14GMDSmother/~14MDYSGmotherboard/~1SM-motherfucker/1MS!6-motherfucking/5!+motherfucker/1MS6+motherfucking/56motherhood/~1Mmotherland/~1MSmotherless/5@@ -34612,11 +34613,11 @@ nifedipine/1niff/14niffy/5nifty/51TR-nigga/1MS!+nigga/1MS6niggard/514SMYniggardliness/1M-niggaz/1!-nigger/~14SM!+niggaz/16+nigger/~14SM6niggle/14MZGDRSniggler/1Mnigh/~54+RT@@ -36219,7 +36220,7 @@ overmaster/4SDGovermodest/5overmuch/51Sovernice/5-overnight/~541MS+overnight/~541MSDGoveroptimism/1Moveroptimistic/5overpaid/4@@ -40320,6 +40321,7 @@ rebelliousness/1Mrebid/41Srebidding/4rebirth/~14M+reboard/4GDSreboil/4SDGrebuild/~41SGrebuke/14DSMG@@ -43143,16 +43145,16 @@ shirtsleeve/1SMshirttail/1SMshirtwaist/1MSshirty/5-shit/~154SM!6-shitfaced/5!6-shitfest/1MS!6-shithead/1S!6-shitless/5!6-shitload/1!6-shitpost/!61MSDG-shitted/4!6-shitting/145!6-shitty/5RT!6+shit/~154SM6+shitfaced/56+shitfest/1MS6+shithead/1S6+shitless/56+shitload/16+shitpost/61MSDG+shitted/46+shitting/1456+shitty/5RT6shiv/~14ZMRSshiver/41MDGshivery/5@@ -51845,6 +51847,7 @@ one-handed/5one-man/5one-off/5out-and-out/5+Pan Am/1Mright-wing/5run-up/1MSshort-term/5j@@ -51858,6 +51861,7 @@ UTF-8/1Mwalkie-talkie/1MSweb page/~1SMwell-known/5+Wi-Fi/1Mworking-class/15MS# New entries may be added below this linediff --git a/harper-core/proper_noun_rules.json b/harper-core/proper_noun_rules.jsonindex a44ee0ecd..db9f9e4ee 100644--- a/harper-core/proper_noun_rules.json+++ b/harper-core/proper_noun_rules.json@@ -511,5 +511,14 @@"Colorado School of Mines"],"description": "Ensure proper capitalization of major universities in the United States."+ },+ "NotablePlaces": {+ "canonical": [+ "Las Palmas",+ "Las Vegas",+ "Los Angeles",+ "San Francisco"+ ],+ "description": "Ensure proper capitalization of notable places that are significant regional centers, travel destinations, or have international importance."}}diff --git a/harper-core/src/linting/capitalize_personal_pronouns.rs b/harper-core/src/linting/capitalize_personal_pronouns.rsindex 5558a36d1..82a722eb1 100644--- a/harper-core/src/linting/capitalize_personal_pronouns.rs+++ b/harper-core/src/linting/capitalize_personal_pronouns.rs@@ -1,34 +1,42 @@-use crate::{TokenKind, TokenStringExt, WordMetadata};+use crate::TokenStringExt;use super::{Lint, LintKind, Linter, Suggestion};-/// A super-simple linter that makes sure you capitalize "I".+/// A linter that makes sure you capitalize "I" and its contractions.#[derive(Default)]pub struct CapitalizePersonalPronouns;impl Linter for CapitalizePersonalPronouns {fn lint(&mut self, document: &crate::Document) -> Vec<Lint> {- let mut lints = Vec::new();-- for tok in document.iter_words() {- if let TokenKind::Word(Some(WordMetadata {- pronoun: Some(_), ..- })) = tok.kind- {- if document.get_span_content(&tok.span) == ['i'] {- lints.push(Lint {+ document+ .iter_words()+ .filter_map(|tok| {+ let span_content = document.get_span_content(&tok.span);++ if matches!(+ span_content,+ ['i']+ | ['i', '\'', 'd']+ | ['i', '\'', 'd', '\\', 'v', 'e']+ | ['i', '\'', 'l', 'l']+ | ['i', '\'', 'm']+ | ['i', '\'', 'v', 'e']+ ) {+ let mut replacement = span_content.to_vec();+ replacement[0] = 'I';+ Some(Lint {span: tok.span,lint_kind: LintKind::Capitalization,- suggestions: vec![Suggestion::ReplaceWith(vec!['I'])],+ suggestions: vec![Suggestion::ReplaceWith(replacement)],message: "The first-person singular subject pronoun must be capitalized.".to_string(),priority: 31,- });+ })+ } else {+ None}- }- }-- lints+ })+ .collect()}fn description(&self) -> &'static str {@@ -73,4 +81,74 @@ mod tests {0,);}++ #[test]+ fn corrects_id() {+ assert_suggestion_result("i'd", CapitalizePersonalPronouns, "I'd");+ }++ #[test]+ fn correct_real_world_id() {+ assert_suggestion_result(+ "Personal Homebrew tap with tools i'd like to use",+ CapitalizePersonalPronouns,+ "Personal Homebrew tap with tools I'd like to use",+ )+ }++ #[test]+ fn corrects_idve() {+ assert_suggestion_result("i'd've", CapitalizePersonalPronouns, "I'd've");+ }++ #[test]+ fn correct_real_world_idve() {+ assert_suggestion_result(+ "... i'd've loved this even more twice length , but let not get greedy",+ CapitalizePersonalPronouns,+ "... I'd've loved this even more twice length , but let not get greedy",+ )+ }++ #[test]+ fn corrects_ill() {+ assert_suggestion_result("i'll", CapitalizePersonalPronouns, "I'll");+ }++ #[test]+ fn correct_real_world_ill() {+ assert_suggestion_result(+ "Hey i deploy my contract it give me error and i'll match with the script file both are same if someone have idea how i slove this please ...",+ CapitalizePersonalPronouns,+ "Hey I deploy my contract it give me error and I'll match with the script file both are same if someone have idea how I slove this please ...",+ )+ }++ #[test]+ fn corrects_im() {+ assert_suggestion_result("i'm", CapitalizePersonalPronouns, "I'm");+ }++ #[test]+ fn correct_real_world_im() {+ assert_suggestion_result(+ "Grid view not working, i'm not using any template",+ CapitalizePersonalPronouns,+ "Grid view not working, I'm not using any template",+ )+ }++ #[test]+ fn corrects_ive() {+ assert_suggestion_result("i've", CapitalizePersonalPronouns, "I've");+ }++ #[test]+ fn correct_real_world_ive() {+ assert_suggestion_result(+ "Can't use Github Pro although i've verified for student pack",+ CapitalizePersonalPronouns,+ "Can't use Github Pro although I've verified for student pack",+ )+ }}