Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix: no longer flag `with plugin` or `, layout` (#1801)

Andrew Dunbarfc9df0b036f7
diff --git a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
index c253fafba..c51d885dd 100644
--- a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
+++ b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
@@ -150,14 +150,18 @@ impl Linter for PhrasalVerbAsCompoundNoun {
continue;
}
- // If the compound is part of a list of nouns, it's probably not a verb.
- if prev_tok.kind.is_conjunction() {
- let maybe_prev_tok_2 = document.get_next_word_from_offset(i, -3);
- if let Some(prev_tok_2) = maybe_prev_tok_2
- && prev_tok_2.kind.is_noun()
- {
- continue;
- }
+ if is_part_of_noun_list(document, i) {
+ continue;
+ }
+
+ // If the previous word is (only) a preposition, this word is surely a noun
+ if prev_tok.kind.is_preposition()
+ && !prev_tok
+ .span
+ .get_content(document.get_source())
+ .eq_ignore_ascii_case_str("to")
+ {
+ continue;
}
// If the previous word is OOV, those are most commonly nouns
@@ -173,6 +177,7 @@ impl Linter for PhrasalVerbAsCompoundNoun {
&["file", "images", "location", "snapshots"][..]
}
['c', 'a', 'l', 'l', 'b', 'a', 'c', 'k'] => &["function"][..],
+ ['l', 'a', 'y', 'o', 'u', 't'] => &["estimation"][..],
['p', 'l', 'a', 'y', 'b', 'a', 'c', 'k'] => &["latency"][..],
['r', 'o', 'l', 'l', 'o', 'u', 't'] => &["status"][..],
['w', 'o', 'r', 'k', 'o', 'u', 't'] => &["constraints", "preference"][..],
@@ -215,6 +220,33 @@ impl Linter for PhrasalVerbAsCompoundNoun {
}
}
+/// Checks if the current token is part of a list of nouns
+fn is_part_of_noun_list(document: &Document, current_index: usize) -> bool {
+ // Check for a conjunction before the current word (-1 is whitespace, -2 is the conjunction)
+ if !matches!(
+ document.get_next_word_from_offset(current_index, -1),
+ Some(tok) if tok.kind.is_conjunction()
+ ) {
+ return false;
+ }
+
+ // Check the token sequence before the conjunction
+ match document.get_token_offset(current_index, -3) {
+ // A comma without the space, assume we're in a list of nouns.
+ Some(tok) if tok.kind.is_comma() => true,
+
+ // Whitespace. If the token before that is a noun or a comma, assume we're in a list of nouns.
+ Some(ws) if ws.kind.is_whitespace() => {
+ document
+ .get_token_offset(current_index, -4)
+ // `noun and` or `, and`
+ .is_some_and(|tok| tok.kind.is_noun() || tok.kind.is_comma())
+ }
+
+ _ => false,
+ }
+}
+
#[cfg(test)]
mod tests {
use super::PhrasalVerbAsCompoundNoun;
@@ -575,4 +607,40 @@ mod tests {
0,
);
}
+
+ #[test]
+ fn font_flag_with_plugin() {
+ assert_lint_count(
+ "**Xcode** (8.0+, otherwise [with plugin](https://github.com/robertvojta/LigatureXcodePlugin))",
+ PhrasalVerbAsCompoundNoun::default(),
+ 0,
+ )
+ }
+
+ #[test]
+ fn dont_flag_and_layout_of_data() {
+ assert_lint_count(
+ "shape, memory space, and layout of data, while performing the complicated indexing for the user",
+ PhrasalVerbAsCompoundNoun::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn dont_flag_in_noun_list_without_space_after_comma() {
+ assert_lint_count(
+ "shape, memory space,and layout of data",
+ PhrasalVerbAsCompoundNoun::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn dont_flag_layout_estimation() {
+ assert_lint_count(
+ "Layout estimation focuses on predicting architectural elements, i.e., walls, doors, and windows, within an indoor scene.",
+ PhrasalVerbAsCompoundNoun::default(),
+ 0,
+ );
+ }
}