Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 83 additions & 2 deletions harper-core/src/linting/closed_compounds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
use crate::linting::LintGroup;
use crate::{
Token,
expr::Expr,
linting::{
ExprLinter, Lint, LintGroup,
expr_linter::{Chunk, preceded_by_word},
},
};

use super::MapPhraseLinter;

struct Overall {
inner: MapPhraseLinter,
}

impl Default for Overall {
fn default() -> Self {
Self {
inner: MapPhraseLinter::new_closed_compound(["over all"], "overall"),
}
}
}

impl ExprLinter for Overall {
type Unit = Chunk;

fn expr(&self) -> &dyn Expr {
self.inner.expr()
}

fn match_to_lint_with_context(
&self,
matched_tokens: &[Token],
source: &[char],
context: Option<(&[Token], &[Token])>,
) -> Option<Lint> {
// "Over all" is normally a preposition followed by a quantifier. Only treat it as the
// adjective "overall" when a preceding determiner establishes that grammatical role.
if !preceded_by_word(context, |word| word.kind.is_determiner()) {
return None;
}

self.inner.match_to_lint(matched_tokens, source)
}

fn description(&self) -> &str {
self.inner.description()
}
}

pub fn lint_group() -> LintGroup {
let mut group = LintGroup::empty();

Expand Down Expand Up @@ -57,7 +103,6 @@ pub fn lint_group() -> LintGroup {
"Nothing" => (&["no thing"][..], "nothing"),
"Notwithstanding" => (&["not with standing"][..], "notwithstanding"),
"Nowhere" => (&["no where"][..], "nowhere"),
"Overall" => (&["over all"][..], "overall"),
"Overclocking" => (&["over clocking"][..], "overclocking"),
"Overload" => (&["over load"][..], "overload"),
"Overnight" => (&["over night"][..], "overnight"),
Expand All @@ -83,6 +128,8 @@ pub fn lint_group() -> LintGroup {
"Worthwhile" => (&["worth while", "worth-while"][..], "worthwhile"),
});

group.add("Overall", Box::new(Overall::default()));

group.set_all_rules_to(Some(true));

group
Expand Down Expand Up @@ -157,6 +204,40 @@ mod tests {
assert_suggestion_result(test_sentence, lint_group(), expected);
}

#[test]
fn allow_over_all_the() {
assert_no_lints("Iterate over all the save data in the slot.", lint_group());
}

#[test]
fn allow_over_all_of_the() {
assert_no_lints(
"Iterate over all of the save data in the slot.",
lint_group(),
);
}

#[test]
fn allow_over_all_plural_noun() {
assert_no_lints(
"Congress may exercise authority over all places purchased by consent.",
lint_group(),
);
}

#[test]
fn allow_over_all_of_pronoun() {
assert_no_lints("A thrill passed over all of us.", lint_group());
}

#[test]
fn allow_over_all_at_sentence_start() {
assert_no_lints(
"Over all these years, the rule stayed the same.",
lint_group(),
);
}

#[test]
fn how_ever() {
let test_sentence = "This is true, how ever, details matter.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,6 @@ Suggest:



Lint: Miscellaneous (31 priority)
Message: |
238 | puzzle!” And she began thinking over all the children she knew that were of the
| ^~~~~~~~ Did you mean the closed compound `overall`?
Suggest:
- Replace with: “overall”



Lint: Capitalization (31 priority)
Message: |
243 | all sorts of things, and she, oh! she knows such a very little! Besides, she’s
Expand Down Expand Up @@ -1703,16 +1694,6 @@ Suggest:



Lint: Miscellaneous (31 priority)
Message: |
1415 | dropped, and the party sat silent for a minute, while Alice thought over all she
| ^~~~~~~~ Did you mean the closed compound `overall`?
1416 | could remember about ravens and writing-desks, which wasn’t much.
Suggest:
- Replace with: “overall”



Lint: Readability (127 priority)
Message: |
1433 | The March Hare took the watch and looked at it gloomily: then he dipped it into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,17 +685,6 @@ Suggest:



Lint: Miscellaneous (31 priority)
Message: |
253 | the Acceptance of Congress, become the Seat of the Government of the United
254 | States, and to exercise like Authority over all Places purchased by the Consent
| ^~~~~~~~ Did you mean the closed compound `overall`?
255 | of the Legislature of the State in which the Same shall be, for the Erection of
Suggest:
- Replace with: “overall”



Lint: Readability (127 priority)
Message: |
265 | The Migration or Importation of such Persons as any of the
Expand Down
9 changes: 0 additions & 9 deletions harper-core/tests/text/linters/The Great Gatsby.snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1549,15 +1549,6 @@ Suggest:



Lint: Miscellaneous (31 priority)
Message: |
1307 | A thrill passed over all of us. The three Mr. Mumbles bent forward and listened
| ^~~~~~~~ Did you mean the closed compound `overall`?
Suggest:
- Replace with: “overall”



Lint: Spelling (63 priority)
Message: |
1310 | “I don’t think it’s so much that,” argued Lucille sceptically; “it’s more that
Expand Down
Loading