Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): ignore apostrophes in the `OrthographicConsistency` rule (#2475)
Elijah Potter80be8bf5abe6
diff --git a/harper-core/src/linting/orthographic_consistency.rs b/harper-core/src/linting/orthographic_consistency.rsindex a50c5a9fc..3034b1c0e 100644--- a/harper-core/src/linting/orthographic_consistency.rs+++ b/harper-core/src/linting/orthographic_consistency.rs@@ -99,7 +99,7 @@ impl ExprLinter for OrthographicConsistency {.count()== 1&& let Some(canonical) = self.dict.get_correct_capitalization_of(chars)- && canonical != chars+ && alphabetic_differs(canonical, chars){return Some(Lint {span: word.span,@@ -116,7 +116,7 @@ impl ExprLinter for OrthographicConsistency {if metadata.is_titlecase()&& cur_flags.contains(OrthFlags::LOWERCASE)&& let Some(canonical) = self.dict.get_correct_capitalization_of(chars)- && canonical != chars+ && alphabetic_differs(canonical, chars){return Some(Lint {span: word.span,@@ -134,6 +134,14 @@ impl ExprLinter for OrthographicConsistency {}}+/// Check if the alphabetic characters in the string differ from one another.+/// Ignores non-alphabetic characters.+fn alphabetic_differs(a: &[char], b: &[char]) -> bool {+ a.iter()+ .zip(b.iter())+ .any(|(a, b)| a.is_alphabetic() && b.is_alphabetic() && a != b)+}+#[cfg(test)]mod tests {use crate::linting::tests::{assert_no_lints, assert_suggestion_result};@@ -387,4 +395,12 @@ mod tests {OrthographicConsistency::default(),);}++ #[test]+ fn allows_issue_2465() {+ assert_no_lints(+ "The post’s problem was not in its complexity.",+ OrthographicConsistency::default(),+ );+ }}diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.ymlindex 7c2d8ba44..e9da3d20c 100644--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml@@ -1520,15 +1520,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 964 | “Come, my head’s free at last!” said Alice in a tone of delight, which changed- | ^~~~~~ The canonical dictionary spelling is title case: `head's`.-Suggest:- - Replace with: “head's”---Lint: Readability (127 priority)Message: |964 | “Come, my head’s free at last!” said Alice in a tone of delight, which changed@@ -1694,16 +1685,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 1127 | “Oh, there’s no use in talking to him,” said Alice desperately: “he’s perfectly- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 1128 | idiotic!” And she opened the door and went in.-Suggest:- - Replace with: “he's”---Lint: Readability (127 priority)Message: |1130 | The door led right into a large kitchen, which was full of smoke from one end to@@ -2952,16 +2933,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 2306 | > “Will you walk a little faster?” said a whiting to a snail. “There’s a- 2307 | > porpoise close behind us, and he’s treading on my tail. See how eagerly the- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |2333 | “Yes,” said Alice, “I’ve often seen them at dinn—” she checked herself hastily.diff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.ymlindex 6e8125abe..5152d95c2 100644--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml@@ -178,15 +178,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 57 | reference to the rather hard-boiled painting that hangs in father’s office. I- | ^~~~~~~~ The canonical dictionary spelling is title case: `father's`.-Suggest:- - Replace with: “father's”---Lint: Spelling (63 priority)Message: |61 | restless. Instead of being the warm centre of the world, the Middle West now@@ -540,25 +531,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 402 | “I’ll tell you a family secret,” she whispered enthusiastically. “It’s about the- 403 | butler’s nose. Do you want to hear about the butler’s nose?”- | ^~~~~~~~ The canonical dictionary spelling is title case: `butler's`.-Suggest:- - Replace with: “butler's”----Lint: Capitalization (127 priority)-Message: |- 403 | butler’s nose. Do you want to hear about the butler’s nose?”- | ^~~~~~~~ The canonical dictionary spelling is title case: `butler's`.-Suggest:- - Replace with: “butler's”---Lint: Readability (127 priority)Message: |416 | For a moment the last sunshine fell with romantic affection upon her glowing@@ -967,16 +939,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 764 | “Wilson? He thinks she goes to see her sister in New York. He’s so dumb he- 765 | doesn’t know he’s alive.”- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |768 | together, for Mrs. Wilson sat discreetly in another car. Tom deferred that much@@ -1173,15 +1135,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 964 | “Well, they say he’s a nephew or a cousin of Kaiser Wilhelm’s. That’s where all- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |989 | studies of him.” His lips moved silently for a moment as he invented. “‘George@@ -1218,15 +1171,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 1039 | kept saying to me: ‘Lucille, that man’s ’way below you!’ But if I hadn’t met- | ^~~~~ The canonical dictionary spelling is title case: `man's`.-Suggest:- - Replace with: “man's”---Lint: Miscellaneous (31 priority)Message: |1062 | She pointed suddenly at me, and every one looked at me accusingly. I tried to@@ -1401,16 +1345,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 1174 | juice of two hundred oranges in half an hour if a little button was pressed two- 1175 | hundred times by a butler’s thumb.- | ^~~~~~~~ The canonical dictionary spelling is title case: `butler's`.-Suggest:- - Replace with: “butler's”---Lint: Spelling (63 priority)Message: |1179 | enormous garden. On buffet tables, garnished with glistening hors-d’œuvre,@@ -1892,16 +1826,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 1569 | “She had a fight with a man who says he’s her husband,” explained a girl at my- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 1570 | elbow.-Suggest:- - Replace with: “he's”---Lint: Readability (127 priority)Message: |1574 | rent asunder by dissension. One of the men was talking with curious intensity to@@ -2160,16 +2084,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 1797 | passed so close to some workmen that our fender flicked a button on one man’s- | ^~~~~ The canonical dictionary spelling is title case: `man's`.- 1798 | coat.-Suggest:- - Replace with: “man's”---Lint: Punctuation (31 priority)Message: |1824 | perspiration appeared on her upper lip. Nevertheless there was a vague@@ -3158,16 +3072,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 2056 | “All right, old sport,” called Gatsby. We slowed down. Taking a white card from- 2057 | his wallet, he waved it before the man’s eyes.- | ^~~~~ The canonical dictionary spelling is title case: `man's`.-Suggest:- - Replace with: “man's”---Lint: Readability (127 priority)Message: |2067 | Over the great bridge, with the sunlight through the girders making a constant@@ -3503,15 +3407,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 2215 | about women. He would never so much as look at a friend’s wife.”- | ^~~~~~~~ The canonical dictionary spelling is title case: `friend's`.-Suggest:- - Replace with: “friend's”---Lint: Spelling (63 priority)Message: |2218 | Mr. Wolfshiem drank his coffee with a jerk and got to his feet.@@ -3552,15 +3447,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 2243 | “Meyer Wolfshiem? No, he’s a gambler.” Gatsby hesitated, then added coolly:- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Miscellaneous (31 priority)Message: |2265 | “Come along with me for a minute,” I said; “I’ve got to say hello to some one.”@@ -3821,25 +3707,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 2425 | “He’s afraid, he’s waited so long. He thought you might be offended. You see,- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”----Lint: Capitalization (127 priority)-Message: |- 2425 | “He’s afraid, he’s waited so long. He thought you might be offended. You see,- 2426 | he’s regular tough underneath it all.”- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Formatting (255 priority)Message: |2437 | “I think he half expected her to wander into one of his parties, some night,”@@ -3855,16 +3722,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 2448 | whole idea. He doesn’t know very much about Tom, though he says he’s read a- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 2449 | Chicago paper for years just on the chance of catching a glimpse of Daisy’s-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |2455 | hard, limited person, who dealt in universal scepticism, and who leaned back@@ -4314,16 +4171,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 2926 | said a small town. . . . He must know what a small town is. . . . Well, he’s no- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 2927 | use to us if Detroit is his idea of a small town. . . .” He rang off.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |2940 | “I know what we'll do,” said Gatsby, “we'll have Klipspringer play the piano.”@@ -4696,15 +4543,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3213 | “My God, I believe the man’s coming,” said Tom. “Doesn’t he know she doesn’t- | ^~~~~ The canonical dictionary spelling is title case: `man's`.-Suggest:- - Replace with: “man's”---Lint: Readability (127 priority)Message: |3235 | in my memory from Gatsby’s other parties that summer. There were the same@@ -4851,16 +4689,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3396 | hadn’t been invited. They simply force their way in and he’s too polite to- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 3397 | object.”-Suggest:- - Replace with: “he's”---Lint: Capitalization (31 priority)Message: |3409 | Her glance left me and sought the lighted top of the steps, where “Three o’Clock@@ -4929,16 +4757,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3488 | somewhere a long time ago. For a moment a phrase tried to take shape in my mouth- 3489 | and my lips parted like a dumb man’s, as though there was more struggling upon- | ^~~~~ The canonical dictionary spelling is title case: `man's`.-Suggest:- - Replace with: “man's”---Lint: Spelling (63 priority)Message: |3490 | them than a wisp of startled air. But they made no sound, and what I had almost@@ -5136,15 +4954,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3612 | “No, he’s not,” I assured her. “It’s a bona-fide deal. I happen to know about- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |3612 | “No, he’s not,” I assured her. “It’s a bona-fide deal. I happen to know about@@ -5234,15 +5043,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3686 | “I read somewhere that the sun’s getting hotter every year,” said Tom genially.- | ^~~~~ The canonical dictionary spelling is title case: `sun's`.-Suggest:- - Replace with: “sun's”---Lint: Formatting (255 priority)Message: |3687 | “It seems that pretty soon the earth’s going to fall into the sun—or wait a@@ -5250,16 +5050,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 3687 | “It seems that pretty soon the earth’s going to fall into the sun—or wait a- 3688 | minute—it’s just the opposite—the sun’s getting colder every year.- | ^~~~~ The canonical dictionary spelling is title case: `sun's`.-Suggest:- - Replace with: “sun's”---Lint: Regionalism (63 priority)Message: |3690 | “Come outside,” he suggested to Gatsby, “I’d like you to have a look at the@@ -5309,15 +5099,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3795 | song of it. . . . High in a white palace the king’s daughter, the golden girl. .- | ^~~~~~ The canonical dictionary spelling is title case: `king's`.-Suggest:- - Replace with: “king's”---Lint: Spelling (63 priority)Message: |3809 | “Well, you take my coupé and let me drive your car to town.”@@ -5359,15 +5140,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 3864 | “Nevertheless he’s an Oxford man.”- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |3874 | while in silence. Then as Doctor T. J. Eckleburg’s faded eyes came into sight@@ -6494,16 +6266,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 4622 | house. I sat down for a few minutes with my head in my hands, until I heard the- 4623 | phone taken up inside and the butler’s voice calling a taxi. Then I walked- | ^~~~~~~~ The canonical dictionary spelling is title case: `butler's`.-Suggest:- - Replace with: “butler's”---Lint: Spelling (63 priority)Message: |4635 | the house in a moment; I wouldn’t have been surprised to see sinister faces, the@@ -7309,16 +7071,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 5330 | thought this would be Daisy at last. But the connection came through as a man’s- | ^~~~~ The canonical dictionary spelling is title case: `man's`.- 5331 | voice, very thin and far away.-Suggest:- - Replace with: “man's”---Lint: Spelling (63 priority)Message: |5333 | “This is Slagle speaking . . .”@@ -7601,35 +7353,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 5487 | “But I know he’s there.”- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”----Lint: Capitalization (127 priority)-Message: |- 5493 | “We’re getting sick in tired of it. When I say he’s in Chicago, he’s in- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 5494 | Chicago.”-Suggest:- - Replace with: “he's”----Lint: Capitalization (127 priority)-Message: |- 5493 | “We’re getting sick in tired of it. When I say he’s in Chicago, he’s in- | ^~~~ The canonical dictionary spelling is title case: `he's`.- 5494 | Chicago.”-Suggest:- - Replace with: “he's”---Lint: Formatting (255 priority)Message: |5498 | “Oh-h!” She looked at me over again. ‘‘Will you just— What was your name?”@@ -7705,15 +7428,6 @@ Message: |-Lint: Capitalization (127 priority)-Message: |- 5528 | “Now he’s dead,” I said after a moment. “You were his closest friend, so I know- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Spelling (63 priority)Message: |5552 | For a moment I thought he was going to suggest a “gonnegtion,” but he only@@ -7736,16 +7450,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 5560 | up and down excitedly in the hall. His pride in his son and in his son’s- | ^~~~~ The canonical dictionary spelling is title case: `son's`.- 5561 | possessions was continually increasing and now he had something to show me.-Suggest:- - Replace with: “son's”---Lint: Agreement (30 priority)Message: |5575 | “He come out to see me two years ago and bought me the house I live in now. Of@@ -7801,15 +7505,6 @@ Suggest:-Lint: Capitalization (127 priority)-Message: |- 5612 | something. Do you notice what he’s got about improving his mind? He was always- | ^~~~ The canonical dictionary spelling is title case: `he's`.-Suggest:- - Replace with: “he's”---Lint: Repetition (63 priority)Message: |5613 | great for that. He told me I et like a hog once, and I beat him for it.”