Skip to content

Commit

Permalink
Merge pull request #521 from Automattic/an-a-capitalization
Browse files Browse the repository at this point in the history
fix(core): `AnA` linter did not recognize capital articles
  • Loading branch information
elijah-potter authored Jan 28, 2025
2 parents b4e4881 + 2de6e15 commit 8212d58
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions harper-core/src/linting/an_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl Linter for AnA {

let is_a_an = match chars_first {
['a'] => Some(true),
['A'] => Some(true),
['a', 'n'] => Some(false),
['A', 'n'] => Some(false),
_ => None,
};

Expand All @@ -52,7 +54,10 @@ impl Linter for AnA {
lints.push(Lint {
span: first.span,
lint_kind: LintKind::Miscellaneous,
suggestions: vec![Suggestion::ReplaceWith(replacement)],
suggestions: vec![Suggestion::replace_with_match_case(
replacement,
chars_first,
)],
message: "Incorrect indefinite article.".to_string(),
priority: 31,
})
Expand Down Expand Up @@ -113,7 +118,8 @@ fn starts_with_vowel(word: &[char]) -> bool {
| ['u', 'n', 'i', 'n' | 'm', ..]
| ['u', 'n', 'a' | 'u', ..]
| ['h', 'e', 'r', 'b', ..]
| ['u', 'r', 'b', ..])
| ['u', 'r', 'b', ..]
| ['i', 'n', 't', ..])
{
return true;
}
Expand Down Expand Up @@ -250,4 +256,13 @@ mod tests {
fn disallows_uppercase_consonants() {
assert_lint_count("not an Crash", AnA, 1);
}

#[test]
fn disallows_a_interface() {
assert_lint_count(
"A interface for an object that can perform linting actions.",
AnA,
1,
);
}
}

0 comments on commit 8212d58

Please sign in to comment.