Skip to content

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.json
index 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.dict
index 6230feb11..678644d8c 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -4670,6 +4670,7 @@ Hyundai/1M
Hz/M
I/8~f
I'd/~
+I'd've/
I'll/~
I'm/~
I've/~
@@ -7079,6 +7080,7 @@ NES/1M
NF/251
NFC/21
NFL/21M
+NGO/1MS
NH/2145
NHL/12M
NIH/25
@@ -10619,7 +10621,6 @@ Whitman/2M
Whitney/2M
Whitsunday/12MS
Whittier/2M
-WiFi/14
Wicca/2M
Wichita/12M
Wiemar/M
@@ -12986,7 +12987,7 @@ assessor/1MS
asset/~1MS
asseverate/4DSGN
asseveration/1M
-asshole/1MS!6
+asshole/1MS6
assiduity/1M
assiduous/5PY
assiduousness/1M
@@ -15556,10 +15557,10 @@ bullock/~14SM
bullpen/~1SM
bullring/1MS
bullseye/~1
-bullshit/~154MS!
-bullshitted/4!
-bullshitter/1SM!
-bullshitting/4!
+bullshit/~154MS6
+bullshitted/46
+bullshitter/1SM6
+bullshitting/46
bullwhip/14S
bully/~145DSMG
bulrush/1MS
@@ -16908,7 +16909,7 @@ chicken/~154MDG
chickenfeed/1M
chickenhearted/5
chickenpox/1M
-chickenshit/51S!
+chickenshit/51S6
chickpea/1SM
chickweed/1M
chicle/1M
@@ -17623,7 +17624,7 @@ cockney/~152SM
cockpit/~1SM
cockroach/1MS
cockscomb/1SM
-cocksucker/1MS!6
+cocksucker/1MS6
cocksure/5
cocktail/~154MS
cocky/514RTP
@@ -19586,7 +19587,7 @@ cumulus/~1M
cuneiform/~51M
cunnilingus/1M
cunning/~51MRYT
-cunt/145MS!6
+cunt/145MS6
cup/~14SM
cupboard/~14SM
cupcake/14MS
@@ -20720,7 +20721,7 @@ diciest/5
dick/~14MRXZS6
dicker/41DG
dickey/~15SM
-dickhead/1S
+dickhead/1S6
dickybird/S
dicotyledon/1MS
dicotyledonous/5
@@ -25236,9 +25237,9 @@ fryer/~1SM
ft/~14
ftp/~5124ZGS
fuchsia/15MS
-fuck/~41SMGDRZ!6
-fucker/1M!6S
-fuckhead/1S!6
+fuck/~41SMGDRZ6
+fucker/1M6S
+fuckhead/1S6
fuddle/41DSMG
fudge/~14DSMG
fuehrer/1MS
@@ -27425,7 +27426,7 @@ heppest/5
heptagon/1MS
heptagonal/5
heptathlon/1SM
-her/~-*ot
+her/~-ot
herald/~14SMDG
heralded/~4U
heraldic/~5
@@ -27489,7 +27490,7 @@ herpetologist/1SM
herpetology/1M
herring/~1MS
herringbone/14M
-hers/~8
+hers/~8*
herself/~8
hertz/~1M
hesitance/1M
@@ -27928,7 +27929,7 @@ horsemen/~9
horseplay/14M
horsepower/~1M
horseradish/1MS
-horseshit/1!6
+horseshit/16
horseshoe/~14DSM
horseshoeing/4
horsetail/1SM
@@ -29886,7 +29887,7 @@ iteration/~1AM
iterator/1S
itinerant/~51SM
itinerary/~15SM
-its/~8-
+its/~8-*
itself/~8
iv/~U
ivory/~15SM
@@ -33133,7 +33134,7 @@ mind/~14ADRSZG
mind's
mindbogglingly/j
minded/~54P
-mindfuck/1SM6!
+mindfuck/1SM6
mindful/~51YP
mindfulness/~1M
mindless/5YP
@@ -33795,8 +33796,8 @@ moth/~14M
mothball/14GMDS
mother/~14MDYSG
motherboard/~1SM
-motherfucker/1MS!6
-motherfucking/5!
+motherfucker/1MS6
+motherfucking/56
motherhood/~1M
motherland/~1MS
motherless/5
@@ -34612,11 +34613,11 @@ nifedipine/1
niff/14
niffy/5
nifty/51TR
-nigga/1MS!
+nigga/1MS6
niggard/514SMY
niggardliness/1M
-niggaz/1!
-nigger/~14SM!
+niggaz/16
+nigger/~14SM6
niggle/14MZGDRS
niggler/1M
nigh/~54+RT
@@ -36219,7 +36220,7 @@ overmaster/4SDG
overmodest/5
overmuch/51S
overnice/5
-overnight/~541MS
+overnight/~541MSDG
overoptimism/1M
overoptimistic/5
overpaid/4
@@ -40320,6 +40321,7 @@ rebelliousness/1M
rebid/41S
rebidding/4
rebirth/~14M
+reboard/4GDS
reboil/4SDG
rebuild/~41SG
rebuke/14DSMG
@@ -43143,16 +43145,16 @@ shirtsleeve/1SM
shirttail/1SM
shirtwaist/1MS
shirty/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/5RT6
shiv/~14ZMRS
shiver/41MDG
shivery/5
@@ -51845,6 +51847,7 @@ one-handed/5
one-man/5
one-off/5
out-and-out/5
+Pan Am/1M
right-wing/5
run-up/1MS
short-term/5j
@@ -51858,6 +51861,7 @@ UTF-8/1M
walkie-talkie/1MS
web page/~1SM
well-known/5
+Wi-Fi/1M
working-class/15MS
# New entries may be added below this line
diff --git a/harper-core/proper_noun_rules.json b/harper-core/proper_noun_rules.json
index 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.rs
index 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",
+ )
+ }
}